OnSceneGUI with PropertyDrawer
I have a PropertyDrawer which draws a certain class as a button. When that button is pressed, I need to start capturing scene events (clicks in the scene, etc.) with OnSceneGUI, but it appears to be unsupported by PropertyDrawer. How come? What can I do to remedy?
Answer by Adam-Mechtley · Jan 08, 2017 at 09:48 AM
You probably need to do something like make your PropertyDrawer enable/disable some static flag like MyPropertyType.IsInEditMode = true
which you would then test as necessary in your custom editor's OnSceneGUI callback.
Answer by sotirosn · Sep 08, 2017 at 06:06 PM
As far as I know class properties are not passed to the scene directly. Only entire MonoBehaviour go the scene. You would think that custom property drawers would also have a hook into the scene view, but probably no one has implemented it yet.
So you need to use a UnityEditor.Editor with CustomEditor(typeof(ClassUsingTheProperty)) to activate its OnSceneGUI and then start collecting events. This unfortunately means copy pasting code for every single class type that uses the property.
Your answer
Follow this Question
Related Questions
Property drawer with multiple fields: only first field has prefab override implemented 1 Answer
Property Drawer ArgumentException 1 Answer
Hide properties by enums in array element entries. 0 Answers
Property Drawer SerializedProperty Null inside Array 0 Answers
Draw rect color disappearing when any input is detected 1 Answer