public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { AbsAutohookAttribute autoHook = attribute as AbsAutohookAttribute; if (Application.isEditor && !Application.isPlaying) { // First, lets attempt to find a valid component we could hook into this property autoHook.currentComponent = FindAutohookTarget(property); if (autoHook.currentComponent != null) { // if we found something, AND the autohook is empty, lets slot it. // the reason were straight up looking for a target component is so we // can skip drawing the field if theres a valid autohook. // this just looks a bit cleaner but isnt particularly safe. YMMV if (property.objectReferenceValue == null) { property.objectReferenceValue = autoHook.currentComponent; } } } if (!autoHook.hideObject || autoHook.currentComponent == null) { EditorGUI.PropertyField(position, property, label); } }
public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { AbsAutohookAttribute autoHook = attribute as AbsAutohookAttribute; if (!autoHook.hideObject || autoHook.currentComponent == null) { return(base.GetPropertyHeight(property, label)); } return(0); }