Search Unity

  1. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  2. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  3. Participate with students all over the world and build projects to teach people. Join now!
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

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

Discussion in 'Extensions & OnGUI' started by FuguFirecracker, Dec 6, 2018 at 10:59 PM.

  1. FuguFirecracker

    FuguFirecracker

    Joined:
    Sep 20, 2011
    Posts:
    237
    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:
    237
    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:
    237
    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.