Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

[SOLVED] Reflection Help Required || Beta 2018.3 Breaks my Asset

Discussion in 'Immediate Mode GUI (IMGUI)' started by FuguFirecracker, Dec 6, 2018.

  1. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Hey Hey.

    Testing out the compatibility of my asset with the soon to be released 2018.3.
    Sadly, it is broken.

    Here's where it falls down:
    Code (CSharp):
    1.  var hierarchyWindowType = Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.SceneHierarchyWindow")
    2. var createContextMenuMethod = hierarchyWindowType.GetMethod("CreateGameObjectContextClick", BindingFlags.NonPublic | BindingFlags.Instance);            
    3. Debug.Log(createContextMenuMethod!=null);
    The debug line is just in there to pinpoint the problem.
    in 2018.2 ... the Debug return 'True', meaning the method has been found.
    in 2018.3 ... the Debug returns 'False' the method IS null :(

    I downloaded the UnityCsReference and it appears that that IS the still the name of the Method... What's the issue?

    Change BindingFlags, perhaps?
    Thanks for any insight.
     
  2. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Okay ... So a bunch of methods have been moved out of UnityEditor.SceneHierarchyWindow
    Code (CSharp):
    1.  MethodInfo[] methodInfos = hierarchyWindowType.GetMethods(BindingFlags.NonPublic |BindingFlags.Instance );
    2.                 foreach (var methodInfo in methodInfos)
    3.                 {
    4.                     Debug.Log(methodInfo.Name);
    5.                 }
    120 Methods in 2018.2 ( including CreateGameObjectContextClick )
    Only 68 Methods in 2018.3
     
  3. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    419
    Well thanks for the blank stares ;)
    I got it working.

    UnityEditor.SceneHierarchyWindow has been rewritten separating out many of the methods.
    Here's the code:

    Code (CSharp):
    1.   var hierarchyWindowType =
    2.                     Assembly.GetAssembly(typeof(Editor)).GetType("UnityEditor.SceneHierarchyWindow");
    3.                
    4.                 var hierarchyWindow = Resources.FindObjectsOfTypeAll(hierarchyWindowType).FirstOrDefault();
    5.                
    6.                 var sceneHierarchy =
    7.                     hierarchyWindowType.GetProperty("sceneHierarchy", BindingFlags.Public | BindingFlags.Instance);
    8.                
    9.                 var createContextMenuMethod = sceneHierarchy.PropertyType.GetMethod("CreateGameObjectContextClick",
    10.                     BindingFlags.NonPublic | BindingFlags.Instance);
    That's probably only useful to myself ... Ah ... maybe someone may need it.