- Home /
Unity Editor Event System
So I am trying to look into playing around with the UnityEditor API to see about starting to develop plugins for my team, but have run into the issue where the Event.current is not doing the expected commandNames. Does any one else have this issue? Is there another way of hooking into the Editor Window to capture copy, deletes, moves etc. in the hierarchy. I have already looked at the docs and have called Event.current in OnInspectorGUI with no luck.
Answer by Bunny83 · Sep 18, 2017 at 04:04 AM
No, there's no other way. What exact problem do you have? Keep in mind that certain events could already been processed / used by some built-in mechanics. The "type" of an event will turn into "Ignore" once the even has been used. However the Event class also has the undocumented "rawType" property which should keep it's value even when processed.
Also you just said "EditorWindow". Keep in mind that the Unity editor has several seperate editor windows. The Sceneview, gameview, inspector, console, animationeditor, profiler, ... Those are all editor windows. Events are only set to the active editor window. If you want to get events while the sceneview is active you have to use the scene view gui callback. You have to subscribe a method to this delegate: SceneView.onSceneGUIDelegate
. The method you would subscribe would look like this:
void OnSceneViewGUI(SceneView view)
{
}
//
SceneView.onSceneGUIDelegate += OnSceneViewGUI;
Don't forget to unsubscribe when done. Usually you would use OnEnable to subscribe and OnDisable to unsubscribe.
If you need some general help with the IMGUI you may want to have a look at my IMGUI crash course ^^.
Very informative answer. I am actually looking into doing something similar to what is on the asset store the "Cross Scene Reference Plugin". I have gotten as far as saving over the paths of these references in an internal map that is saved to disk upon saving scenes. So everytime a change is made for an object with the type GameObject or $$anonymous$$onobehavior the reference is stored after the objectpicker window is closed. The problem is when ever a gameobject is moved in the hierarchy the reference is not adjusted to the now new path in the hierarchy. So I am looking to capture that.
I'm not sure if i fully understood your problem, but you may want to have a look at the EditorApplication class. It has several callbacks which might come in handy. Such as:
Also quite useful might be Selection.selectionChanged-