Search Unity

  1. Calling all beginners! Join the FPS Beginners Mods Challenge until December 13.
    Dismiss Notice
  2. It's Cyber Week at the Asset Store!
    Dismiss Notice

Correct use of EditorApplication.HierarchyWindowItemCallback

Discussion in 'Scripting' started by Wahooney, Feb 22, 2013.

  1. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    275
    Where can I initialize EditorApplication.hierarchyWindowItem without the user having to explicitly run a script? Like something that runs as Unity starts up, or an attribute that automatically runs a function as unity starts.

    I know this is very vague, but I hope someone out there can lend a hand.

    Thanks!
     
  2. Rs

    Rs

    Joined:
    Aug 14, 2012
    Posts:
    39
    EditorApplication.hierarchyWindowItem is the type of hierarchyWindowItemOnGUI. It exists to define the signature of the delegates you subscribe to hierarchyWindowItemOnGUI which is define as

    Code (CSharp):
    1. public static EditorApplication.HierarchyWindowItemCallback hierarchyWindowItemOnGUI;
    So there is no correct use in a strict sense, though you are using it correctly when you use hierarchyWindowItemOnGUI.
    Here's a minimal example:

    Code (CSharp):
    1. [InitializeOnLoad]
    2. public class HierarchyStyler {
    3.  
    4.     static HierarchyStyler()
    5.     {
    6.         Debug.Log("Initialized");
    7.         EditorApplication.hierarchyWindowItemOnGUI += hwCallbackDelegate;
    8.     }
    9.  
    10.  
    11.     static void hwCallbackDelegate(int _instanceID, Rect _selectionRect)
    12.     {
    13.         Debug.Log("CALLBACK");
    14.     }
    15. }
    You should see some heavy printout in the console.
     
    Wahooney likes this.
  3. Wahooney

    Wahooney

    Joined:
    Mar 8, 2010
    Posts:
    275
    Thanks :) Probably should have posted that I found the solution some time ago ;) At least this question is answered now for future generations ;)