I found another good way today.
12345678910 |
[initializeonloadmethod] static void Start () { Selection. SelectionChanged = delegate { Debug. Log(Selection. Activeobject. Name); }; } |
A few days ago a friend asked me how to listen to the Sceneview and hierarchy view Select an event of a gameobject, today I have time to do research.
Do you know the following two agent events? You can actually do it, but it's not perfect. Because every frame will be called to make a judgment
Editorapplication.hierarchywindowitemongui
Editorapplication.update
I think the best way, or when I choose a gameobject, by unity callback to give me an event. So I found an imperfect solution. Add the following code to the Gameobject script where you need to listen for clicks. Ondrawgizmosselected is the chosen callback. But it may call back multiple times, so make a judgment to make sure it executes only once.
1234567891011 |
#if unity_editor bool selected = false; void ondrawgizmosselected() { if (! Selected) { selected = true; Debug. Log(gameobject. Name); } }#endif |
If you want to deal with it in one place, just get it out of the way. OK This article is a pseudo-proposition, if you have a better way to welcome the following message to me, thank you!
- This article fixed link: http://www.xuanyusong.com/archives/3773
- Reprint Please specify: Rain pine Momo November 29, 2015 Yu Yussong Momo Program Research Institute published
Monitor Gameobject Click events #你好Unity3D #hierarchy View