Inheritance: PropertyAttribute
Ejemplo n.º 1
0
        private Component FindComponent(SerializedProperty property)
        {
            SerializedObject root = property.serializedObject;

            if (!(root.targetObject is Component))
            {
                return(null);
            }

            Type              type              = fieldInfo.FieldType;
            Component         parent            = (Component)root.targetObject;
            AutoHookAttribute autoHookAttribute = (AutoHookAttribute)attribute;

            switch (autoHookAttribute.SearchArea)
            {
            case AutoHookSearchArea.Parent:
                return(parent.GetComponentInParent(type));

            case AutoHookSearchArea.Children:
                return(parent.GetComponentInChildren(type));

            case AutoHookSearchArea.DirectChildrenOnly:
                return(FindComponentInDirectChildren(parent.transform, type));

            case AutoHookSearchArea.AllChildrenOnly:
                return(FindComponentInChildrenRecursive(parent.transform, type));

            default:
                return(parent.GetComponent(type));
            }
        }
Ejemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            AutoHookAttribute autoHookAttribute = (AutoHookAttribute)attribute;

            if (autoHookAttribute.StopSearchWhenFound)
            {
                if (property.objectReferenceValue == null)
                {
                    Component component = FindComponent(property);
                    property.objectReferenceValue = component;
                }
            }
            else
            {
                Component component = FindComponent(property);

                if (property.objectReferenceValue == null && component != null)
                {
                    property.objectReferenceValue = component;
                }
            }

            EditorGUI.BeginDisabledGroup(autoHookAttribute.ReadOnlyWhenFound);
            EditorGUI.PropertyField(position, property, label);
            EditorGUI.EndDisabledGroup();
        }
Ejemplo n.º 3
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            AutoHookAttribute autoHookAttribute = (AutoHookAttribute)attribute;

            if (autoHookAttribute.HideWhenFound && property.objectReferenceValue != null)
            {
                return(0);
            }

            return(EditorGUI.GetPropertyHeight(property, label));
        }