Exemplo n.º 1
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            this.Init(property, label);

            //const float WIDTH_FOLDOUT = 5f;
            //if(!_alwaysExpanded) property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
            if (!_alwaysExpanded)
            {
                property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none, true);
            }

            if (_alwaysExpanded || property.isExpanded)
            {
                if (_drawWeight)
                {
                    this.CalculateTotalWeight();
                }

                if (!_alwaysExpanded)
                {
                    GUI.Box(position, GUIContent.none);
                }

                position = new Rect(position.xMin + MARGIN, position.yMin + MARGIN, position.width - MARGIN * 2f, position.height - MARGIN * 2f);
                EditorGUI.BeginProperty(position, label, property);

                position = this.DrawList(position, property);
                position = this.DrawAdvancedTargetSettings(position, property);

                EditorGUI.EndProperty();

                if (Application.isPlaying && !property.serializedObject.isEditingMultipleObjects)
                {
                    var w    = position.width * 0.6f;
                    var pad  = (position.width - w) / 2f;
                    var rect = new Rect(position.xMin + pad, position.yMax + -BTN_ACTIVATE_HEIGHT + 2f, w, 20f);
                    if (GUI.Button(rect, "Activate Trigger"))
                    {
                        var targ = EditorHelper.GetTargetObjectOfProperty(property) as SPEvent;
                        if (targ != null)
                        {
                            targ.ActivateTrigger(property.serializedObject.targetObject, null);
                        }
                    }
                }
            }
            else
            {
                EditorGUI.BeginProperty(position, label, property);

                ReorderableListHelper.DrawRetractedHeader(position, label, EditorHelper.TempContent("Trigger Targets"));

                EditorGUI.EndProperty();
            }
        }
Exemplo n.º 2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);

            if (property.isExpanded)
            {
                _keys = GetKeys(property);
                if (_keys == null)
                {
                    EditorGUI.LabelField(position, "Failed to determine enum key type.");
                    return;
                }

                var valuesProp = property.FindPropertyRelative(PROP_VALUES);
                if (valuesProp.arraySize != _keys.Length)
                {
                    valuesProp.arraySize = _keys.Length;
                }

                this.BeginProperty(property, label);
                _lst.DoList(position);
                this.EndProperty();
            }
            else
            {
                ReorderableListHelper.DrawRetractedHeader(position, label);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            this.ConfigureSettings();

            if (_disallowFoldout)
            {
                this.OnGUIStart(property, label);
                _lst.DoList(position);
                this.OnGUIEnd();
            }
            else
            {
                if (property.isExpanded)
                {
                    this.OnGUIStart(property, label);
                    var foldoutRect = new Rect(position.xMin, position.yMin, 20f, EditorGUIUtility.singleLineHeight);
                    property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none);
                    _lst.DoList(position);
                    this.OnGUIEnd();
                }
                else
                {
                    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
                    ReorderableListHelper.DrawRetractedHeader(position, label);
                }
            }
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            if (property.isArray)
            {
                if (_disallowFoldout)
                {
                    this.StartOnGUI(property, label);
                    _lst.DoList(EditorGUI.IndentedRect(position));
                    this.EndOnGUI(property, label);
                }
                else
                {
                    const float WIDTH_FOLDOUT = 5f;
                    if (property.isExpanded)
                    {
                        this.StartOnGUI(property, label);
                        property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                        _lst.DoList(EditorGUI.IndentedRect(position));
                        this.EndOnGUI(property, label);
                    }
                    else
                    {
                        if (_removeBackgroundWhenCollapsed)
                        {
                            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
                        }
                        else
                        {
                            property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                            ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                        }
                    }
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, false);
            }
        }
Exemplo n.º 5
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            if (property.isArray)
            {
                if (_disallowFoldout)
                {
                    this.StartOnGUI(property, label);
                    //_lst.DoList(EditorGUI.IndentedRect(position));
                    _lst.DoList(position);
                    this.EndOnGUI(property, label);
                }
                else
                {
                    const float WIDTH_FOLDOUT = 5f;
                    if (property.isExpanded)
                    {
                        this.StartOnGUI(property, label);
                        property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                        //_lst.DoList(EditorGUI.IndentedRect(position));
                        _lst.DoList(position);
                        this.EndOnGUI(property, label);
                    }
                    else
                    {
                        if (_removeBackgroundWhenCollapsed)
                        {
                            property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, label);
                        }
                        else
                        {
                            property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, WIDTH_FOLDOUT, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);
                            //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                            ReorderableListHelper.DrawRetractedHeader(position, label);
                        }
                    }
                }

                if (_drawElementAtBottom && _lst.index >= 0 && _lst.index < property.arraySize)
                {
                    var pchild = property.GetArrayElementAtIndex(_lst.index);
                    var label2 = TempElementLabel(pchild, _lst.index); //(string.IsNullOrEmpty(_childPropertyAsLabel)) ? TempElementLabel(_lst.index) : GUIContent.none;

                    pchild.isExpanded = true;
                    float h;
                    if (_internalDrawer != null)
                    {
                        h = _internalDrawer.GetPropertyHeight(pchild, label2) + BOTTOM_PAD;
                    }
                    else
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD;
                    }
                    var area = new Rect(position.x, position.yMax - h, position.width, h);

                    GUI.BeginGroup(area, label2, GUI.skin.box);
                    GUI.EndGroup();

                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(area, pchild, label2);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(area, pchild, GUIContent.none, true);
                    }
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, false);
            }
        }
Exemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            if (property.isArray)
            {
                if (this.CustomLabel != null)
                {
                    label = this.CustomLabel;
                }
                else if (label != null)
                {
                    label = EditorHelper.CloneContent(label);
                    if (_showTooltipInHeader)
                    {
                        label.text = string.Format("{0} [{1:0}] - {2}", label.text, property.arraySize, (string.IsNullOrEmpty(label.tooltip) ? property.tooltip : label.tooltip));
                    }
                    else
                    {
                        label.text = string.Format("{0} [{1:0}]", label.text, property.arraySize);
                    }

                    if (string.IsNullOrEmpty(label.tooltip))
                    {
                        label.tooltip = property.tooltip;
                    }
                }
                else
                {
                    label = EditorHelper.TempContent(property.displayName, property.tooltip);
                }

                //const float WIDTH_FOLDOUT = 5f;
                var foldoutRect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                position = EditorGUI.IndentedRect(position);
                Rect listArea = position;

                if (_disallowFoldout)
                {
                    listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight());
                    this.StartOnGUI(property, label);
                    //_lst.DoList(EditorGUI.IndentedRect(position));
                    _lst.DoList(listArea);
                    this.EndOnGUI(property, label);
                }
                else
                {
                    if (property.isExpanded)
                    {
                        listArea = new Rect(position.xMin, position.yMin, position.width, _lst.GetHeight());
                        this.StartOnGUI(property, label);
                        property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none);
                        //_lst.DoList(EditorGUI.IndentedRect(position));
                        _lst.DoList(listArea);
                        this.EndOnGUI(property, label);
                    }
                    else
                    {
                        if (_removeBackgroundWhenCollapsed)
                        {
                            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label);
                        }
                        else
                        {
                            property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, GUIContent.none);
                            //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                            ReorderableListHelper.DrawRetractedHeader(position, label);
                        }
                    }
                }

                this.DoDragAndDrop(property, listArea);

                if (property.isExpanded && _drawElementAtBottom && _lst.index >= 0 && _lst.index < property.arraySize)
                {
                    var pchild = property.GetArrayElementAtIndex(_lst.index);
                    var label2 = TempElementLabel(pchild, _lst.index); //(string.IsNullOrEmpty(_childPropertyAsLabel)) ? TempElementLabel(_lst.index) : GUIContent.none;

                    pchild.isExpanded = true;
                    float h;
                    if (_internalDrawer != null)
                    {
                        h = _internalDrawer.GetPropertyHeight(pchild, label2) + BOTTOM_PAD + TOP_PAD;
                    }
                    else if (pchild.hasChildren)
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label, true) + BOTTOM_PAD + TOP_PAD - EditorGUIUtility.singleLineHeight;
                    }
                    else
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD + TOP_PAD;
                    }
                    var area     = new Rect(position.xMin, position.yMax - h, position.width, h);
                    var drawArea = new Rect(area.xMin, area.yMin + TOP_PAD, area.width - MARGIN, area.height - TOP_PAD);

                    GUI.BeginGroup(area, label2, GUI.skin.box);
                    GUI.EndGroup();

                    EditorGUI.indentLevel++;
                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(drawArea, pchild, label2);
                    }
                    else if (pchild.hasChildren)
                    {
                        SPEditorGUI.FlatChildPropertyField(drawArea, pchild);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(drawArea, pchild, GUIContent.none, false);
                    }
                    EditorGUI.indentLevel--;
                }
            }
            else
            {
                SPEditorGUI.DefaultPropertyField(position, property, label, false);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            this.Init(property, label, true);
            _currentLabel = label;
            if (this.fieldInfo.DeclaringType == typeof(SPAnimationController))
            {
                _currentLabel.text = "Animation States";
            }

            property.isExpanded = EditorGUI.Foldout(new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight), property.isExpanded, GUIContent.none);

            if (!property.isExpanded)
            {
                //here we emulate the ReorderableList header
                //ReorderableListHelper.DrawRetractedHeader(EditorGUI.IndentedRect(position), label);
                ReorderableListHelper.DrawRetractedHeader(position, label);
            }
            else
            {
                //var cache = SPGUI.DisableIfPlaying();
                _animList.displayAdd    = !Application.isPlaying;
                _animList.displayRemove = !Application.isPlaying;
                _animList.draggable     = !Application.isPlaying;

                EditorGUI.BeginChangeCheck();
                //_animList.DoList(EditorGUI.IndentedRect(position));
                _animList.DoList(position);
                if (EditorGUI.EndChangeCheck())
                {
                    property.serializedObject.ApplyModifiedProperties();
                }

                if (!_hideDetailRegion && _animList.index >= 0)
                {
                    try
                    {
                        var detailRect = new Rect(position.xMin, position.yMin + _animList.GetHeight(), position.width, this.GetDetailHeight());
                        var stateProp  = _animList.serializedProperty.GetArrayElementAtIndex(_animList.index);
                        var nameProp   = stateProp.FindPropertyRelative("_name");

                        GUI.BeginGroup(detailRect, nameProp.stringValue, GUI.skin.box);
                        GUI.EndGroup();

                        //draw basic details
                        var buffer = EditorGUIUtility.singleLineHeight + 2f;
                        detailRect = new Rect(detailRect.xMin, detailRect.yMin + buffer, detailRect.width, detailRect.height - buffer);
                        _clipDrawer.DrawDetails(detailRect, stateProp);
                    }
                    catch
                    {
                        //failed to draw details because poorly selected nonsense
                    }
                }

                //cache.Reset();
            }
        }