jeudi 2 août 2018

How to access to Animation Window private properties?

I want to access to private property m_AnimEditor of Animation Window (to be honest, I want to go even deeper, but it's not so important for now).

I'm getting the window:

EditorWindow[] allWindows = Resources.FindObjectsOfTypeAll<EditorWindow>();
EditorWindow animationWindow = null;
foreach (var editorWindow in allWindows) {
    if (editorWindow.titleContent.text.Equals("Animation")) {
        animationWindow = editorWindow;
        break;
    }
}

Now, I want to get m_AnimEditor property:

PropertyInfo animWindowPropInfo = animationWindow.GetType().GetProperty("m_AnimEditor", BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);

But I'm getting null. See debug panel below:

enter image description here

I thought it was because animationWindow type maybe was EditorWindow, despite debugger was showing me "(UnityEditor.AnimationWindow)" and I tryed to convert the object:

Assembly assem = typeof(EditorWindow).Assembly;
Type type = assem.GetType("UnityEditor.AnimationWindow");
object castedObject = Convert.ChangeType(animationWindow, type);
PropertyInfo castedObjectPropInfo = castedObject.GetType().GetProperty("m_AnimEditor", BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance);
PropertyInfo[] castedObjectPropInfos = castedObject.GetType().GetProperties(BindingFlags.Public|BindingFlags.NonPublic|BindingFlags.Instance|BindingFlags.GetField);

But the result was the same as earlier. BUT, public property (wantsMouseMove for instance) I get easily. Problem only with private properties.


Maybe I do something wrong. What should I do to get the private property and then property of that property (object) too?





Aucun commentaire:

Enregistrer un commentaire