Esempio n. 1
0
 void OnEnable()
 {
     if (target != null)
     {
         buttonMethod = new MyBox.Internal.ButtonMethodHandler(target);
     }
 }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (property.objectReferenceValue == null)
            {
                return(base.GetPropertyHeight(property, label));
            }
            if (_buttonMethods == null)
            {
                _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
            }

            float height = ((DisplayInspectorAttribute)attribute).DisplayScript ? EditorGUI.GetPropertyHeight(property) + 4 : 0;

            var propertyObject = new SerializedObject(property.objectReferenceValue).GetIterator();

            propertyObject.Next(true);
            propertyObject.NextVisible(true);

            while (propertyObject.NextVisible(false))
            {
                height += EditorGUI.GetPropertyHeight(propertyObject) + 4;
            }

            if (_buttonMethods.Amount > 0)
            {
                height += 4 + _buttonMethods.Amount * EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
Esempio n. 3
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();
            if (_methods == null)
            {
                return;
            }

            ButtonMethodHandler.OnInspectorGUI(_target, _methods);
        }
Esempio n. 4
0
        private void OnEnable()
        {
            _target = target as ScriptableObject;
            if (_target == null)
            {
                return;
            }

            _methods = ButtonMethodHandler.CollectValidMembers(_target.GetType());
        }
Esempio n. 5
0
        private void OnEnable()
        {
            _target = target as MonoBehaviour;
            if (_target == null)
            {
                return;
            }

            _methods = ButtonMethodHandler.CollectValidMembers(_target.GetType());
        }
Esempio n. 6
0
        private void OnEnable()
        {
            if (target == null)
            {
                return;
            }

            _foldout      = new FoldoutAttributeHandler(target, serializedObject);
            _buttonMethod = new ButtonMethodHandler(target);
        }
Esempio n. 7
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            bool notValidType  = property.propertyType != SerializedPropertyType.ObjectReference;
            bool displayScript = ((DisplayInspectorAttribute)attribute).DisplayScript;

            if (notValidType || property.objectReferenceValue == null || (displayScript && !IsFolded(property)))
            {
                return(base.GetPropertyHeight(property, label));
            }

            if (_buttonMethods == null)
            {
                _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
            }
            float height = displayScript ? EditorGUI.GetPropertyHeight(property) + 4 : 0;

            var target         = GetTargetSO(property.objectReferenceValue);
            var propertyObject = target.GetIterator();

            propertyObject.Next(true);
            propertyObject.NextVisible(true);

            bool expandedReorderable = false;

            while (propertyObject.NextVisible(propertyObject.isExpanded && !expandedReorderable))
            {
#if UNITY_2020_2_OR_NEWER
                expandedReorderable = propertyObject.isExpanded && propertyObject.isArray &&
                                      !propertyObject.IsAttributeDefined <NonReorderableAttribute>();
#endif
                height += EditorGUI.GetPropertyHeight(propertyObject, expandedReorderable) + 4;
            }

            if (_buttonMethods.Amount > 0)
            {
                height += 4 + _buttonMethods.Amount * EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (property.objectReferenceValue == null)
            {
                return(base.GetPropertyHeight(property, label));
            }
            if (_buttonMethods == null)
            {
                _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
            }

            float height = Instance.DisplayScript ? EditorGUI.GetPropertyHeight(property) + 4 : 0;

            var propertyObject = new SerializedObject(property.objectReferenceValue).GetIterator();

            propertyObject.Next(true);
            propertyObject.NextVisible(true);

            while (propertyObject.NextVisible(propertyObject.isExpanded))
            {
                if (propertyObject.isArray && propertyObject.propertyType != SerializedPropertyType.String &&
                    (propertyObject.IsAttributeDefined <SeparatorAttribute>() ||
                     propertyObject.IsAttributeDefined <HeaderAttribute>()))
                {
                    height += propertyObject.isExpanded ? 70 : EditorGUI.GetPropertyHeight(propertyObject) + 4;
                }
                else
                {
                    height += propertyObject.isExpanded ? 20 : EditorGUI.GetPropertyHeight(propertyObject) + 4;
                }
            }

            if (_buttonMethods.Amount > 0)
            {
                height += 4 + _buttonMethods.Amount * EditorGUIUtility.singleLineHeight;
            }
            return(height);
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (Instance.DisplayScript || property.objectReferenceValue == null)
            {
                position.height = EditorGUI.GetPropertyHeight(property);
                EditorGUI.PropertyField(position, property, label);
                position.y += EditorGUI.GetPropertyHeight(property) + 4;
            }

            if (property.objectReferenceValue != null)
            {
                if (_buttonMethods == null)
                {
                    _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
                }

                var   startY = position.y - 2;
                float startX = position.x;

                var propertyObject = new SerializedObject(property.objectReferenceValue).GetIterator();
                propertyObject.Next(true);
                propertyObject.NextVisible(false);

                var xPos  = position.x + 10;
                var width = position.width - 10;

                while (propertyObject.NextVisible(propertyObject.isExpanded))
                {
                    position.x     = xPos + 10 * propertyObject.depth;
                    position.width = width - 10 * propertyObject.depth;

                    if (propertyObject.isArray && propertyObject.propertyType != SerializedPropertyType.String && (propertyObject.IsAttributeDefined <SeparatorAttribute>() || propertyObject.IsAttributeDefined <HeaderAttribute>()))
                    {
                        position.height = propertyObject.isExpanded ? 66 : EditorGUI.GetPropertyHeight(propertyObject);
                        EditorGUI.PropertyField(position, propertyObject);
                        position.y += propertyObject.isExpanded ? 70 : EditorGUI.GetPropertyHeight(propertyObject) + 4;
                    }
                    else
                    {
                        position.height = propertyObject.isExpanded ? 16 : EditorGUI.GetPropertyHeight(propertyObject);
                        EditorGUI.PropertyField(position, propertyObject);
                        position.y += propertyObject.isExpanded ? 20 : EditorGUI.GetPropertyHeight(propertyObject) + 4;
                    }
                }

                if (!_buttonMethods.TargetMethods.IsNullOrEmpty())
                {
                    foreach (var method in _buttonMethods.TargetMethods)
                    {
                        position.height = EditorGUIUtility.singleLineHeight;
                        if (GUI.Button(position, method.Name))
                        {
                            _buttonMethods.Invoke(method.Method);
                        }
                        position.y += position.height;
                    }
                }

                var bgRect = position;
                bgRect.y      = startY - 5;
                bgRect.x      = startX - 10;
                bgRect.width  = 10;
                bgRect.height = position.y - startY;
                if (_buttonMethods.Amount > 0)
                {
                    bgRect.height += 5;
                }

                DrawColouredRect(bgRect, new Color(.6f, .6f, .8f, .5f));

                if (GUI.changed)
                {
                    propertyObject.serializedObject.ApplyModifiedProperties();
                }
            }

            if (GUI.changed)
            {
                property.serializedObject.ApplyModifiedProperties();
            }
        }
Esempio n. 10
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool notValidType = property.propertyType != SerializedPropertyType.ObjectReference;

            if (notValidType)
            {
                EditorGUI.LabelField(position, label.text, "Use [DisplayInspector] with MB or SO");
                return;
            }

            position.height = EditorGUIUtility.singleLineHeight;
            bool displayScript = ((DisplayInspectorAttribute)attribute).DisplayScript;

            if (displayScript || property.objectReferenceValue == null)
            {
                // Draw foldout only if Script line drawn and there is content to hide (ref assigned)
                if (property.objectReferenceValue != null)
                {
                    // Workaround to make label clickable, accurately aligned and property field click is not triggering foldout
                    var foldRect = new Rect(position);
                    foldRect.width = EditorGUIUtility.labelWidth;
                    _foldout.Value = EditorGUI.Foldout(foldRect, _foldout.Value, new GUIContent(""), true, StyleFramework.FoldoutHeader);
                    EditorGUI.PropertyField(position, property, label);
                    if (GUI.changed)
                    {
                        property.serializedObject.ApplyModifiedProperties();
                    }

                    if (!_foldout.Value)
                    {
                        return;
                    }
                }
                else
                {
                    EditorGUI.PropertyField(position, property, label);
                    if (GUI.changed)
                    {
                        property.serializedObject.ApplyModifiedProperties();
                    }
                }
            }
            if (property.objectReferenceValue == null)
            {
                return;
            }

            if (_buttonMethods == null)
            {
                _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
            }

            if (displayScript)
            {
                position.y += position.height + 4;
            }
            var   startY = position.y - 2;
            float startX = position.x;

            var target         = GetTargetSO(property.objectReferenceValue);
            var propertyObject = target.GetIterator();

            propertyObject.Next(true);
            propertyObject.NextVisible(true);

            var xPos  = position.x + 10;
            var width = position.width - 10;

            bool expandedReorderable = false;

            while (propertyObject.NextVisible(propertyObject.isExpanded && !expandedReorderable))
            {
#if UNITY_2020_2_OR_NEWER
                expandedReorderable = propertyObject.isExpanded && propertyObject.isArray &&
                                      !propertyObject.IsAttributeDefined <NonReorderableAttribute>();
#endif
                position.x     = xPos + 10 * propertyObject.depth;
                position.width = width - 10 * propertyObject.depth;

                position.height = EditorGUI.GetPropertyHeight(propertyObject, expandedReorderable);
                EditorGUI.PropertyField(position, propertyObject, expandedReorderable);

                position.y += position.height + 4;
            }

            if (!_buttonMethods.TargetMethods.IsNullOrEmpty())
            {
                foreach (var method in _buttonMethods.TargetMethods)
                {
                    position.height = EditorGUIUtility.singleLineHeight;
                    if (GUI.Button(position, method.Name))
                    {
                        _buttonMethods.Invoke(method.Method);
                    }
                    position.y += position.height;
                }
            }

            var bgRect = position;
            bgRect.y      = startY;
            bgRect.x      = startX - 12;
            bgRect.width  = 11;
            bgRect.height = position.y - startY;
            if (_buttonMethods.Amount > 0)
            {
                bgRect.height += 5;
            }

            DrawColouredRect(bgRect, new Color(.6f, .6f, .8f, .5f));


            target.ApplyModifiedProperties();
            property.serializedObject.ApplyModifiedProperties();
        }
Esempio n. 11
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            bool notValidType = property.propertyType != SerializedPropertyType.ObjectReference;

            if (notValidType)
            {
                EditorGUI.LabelField(position, label.text, "Use [DisplayInspector] with MB or SO");
                return;
            }

            if (((DisplayInspectorAttribute)attribute).DisplayScript || property.objectReferenceValue == null)
            {
                position.height = EditorGUI.GetPropertyHeight(property);
                EditorGUI.PropertyField(position, property, label);
                position.y += EditorGUI.GetPropertyHeight(property) + 4;
                if (GUI.changed)
                {
                    property.serializedObject.ApplyModifiedProperties();
                }
            }
            if (property.objectReferenceValue == null)
            {
                return;
            }


            if (_buttonMethods == null)
            {
                _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);
            }

            var   startY = position.y - 2;
            float startX = position.x;

            var target         = GetTargetSO(property.objectReferenceValue);
            var propertyObject = target.GetIterator();

            propertyObject.Next(true);
            propertyObject.NextVisible(true);

            var xPos  = position.x + 10;
            var width = position.width - 10;

            bool expandedReorderable = false;

            while (propertyObject.NextVisible(propertyObject.isExpanded && !expandedReorderable))
            {
#if UNITY_2020_2_OR_NEWER
                expandedReorderable = propertyObject.isExpanded && propertyObject.isArray &&
                                      !propertyObject.IsAttributeDefined <NonReorderableAttribute>();
#endif
                position.x     = xPos + 10 * propertyObject.depth;
                position.width = width - 10 * propertyObject.depth;

                position.height = EditorGUI.GetPropertyHeight(propertyObject, expandedReorderable);
                EditorGUI.PropertyField(position, propertyObject, expandedReorderable);

                position.y += position.height + 4;
            }

            if (!_buttonMethods.TargetMethods.IsNullOrEmpty())
            {
                foreach (var method in _buttonMethods.TargetMethods)
                {
                    position.height = EditorGUIUtility.singleLineHeight;
                    if (GUI.Button(position, method.Name))
                    {
                        _buttonMethods.Invoke(method.Method);
                    }
                    position.y += position.height;
                }
            }

            var bgRect = position;
            bgRect.y      = startY - 5;
            bgRect.x      = startX - 10;
            bgRect.width  = 10;
            bgRect.height = position.y - startY;
            if (_buttonMethods.Amount > 0)
            {
                bgRect.height += 5;
            }

            DrawColouredRect(bgRect, new Color(.6f, .6f, .8f, .5f));


            target.ApplyModifiedProperties();
            property.serializedObject.ApplyModifiedProperties();
        }