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();
            }
        }
        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.º 3
0
        private void _animList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _animList.serializedProperty.GetArrayElementAtIndex(index);

            GUIContent label;

            if (Application.isPlaying && !this.serializedObject.isEditingMultipleObjects)
            {
                var targ = this.target as Animation;
                var clip = element.objectReferenceValue as AnimationClip;
                if (targ.IsPlaying(clip.name))
                {
                    label = EditorHelper.TempContent("Anim " + index.ToString("00") + " : (Playing)");
                }
                else
                {
                    label = EditorHelper.TempContent("Anim " + index.ToString("00"));
                }
            }
            else
            {
                label = EditorHelper.TempContent("Anim " + index.ToString("00"));
            }

            area.height = EditorGUIUtility.singleLineHeight;
            EditorGUI.PropertyField(area, element, label);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_animList, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 4
0
        private void _nodeList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            if (area.width < ARG_BTN_WIDTH)
            {
                return;
            }

            var elementProp = _nodesProp.GetArrayElementAtIndex(index);
            var transformProp = elementProp.FindPropertyRelative(PROP_NODE_TRANSFORM);
            var btnRect = new Rect(area.xMax - ARG_BTN_WIDTH, area.yMin, ARG_BTN_WIDTH, area.height);
            var propRect = new Rect(area.xMin, area.yMin, area.width - ARG_BTN_WIDTH, area.height);

            if(transformProp.objectReferenceValue == null || elementProp.isExpanded)
            {
                EditorGUI.PropertyField(propRect, transformProp, GUIContent.none);
            }
            else
            {
                var t = transformProp.objectReferenceValue as Transform;
                EditorGUI.LabelField(propRect, EditorHelper.TempContent(t.name), EditorHelper.TempContent("{ strength: " + t.localScale.z.ToString("0.00") + " }"));

                if(ReorderableListHelper.IsClickingArea(area))
                {
                    EditorGUIUtility.PingObject(t);
                }
            }

            if(GUI.Button(btnRect, _argBtnLabel))
            {
                elementProp.isExpanded = !elementProp.isExpanded;
            }

            if (GUI.enabled) ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_nodeList, area, index, isActive, isFocused);
        }
        private void DoHeaderContextMenu(Rect area)
        {
            if (ReorderableListHelper.IsClickingArea(area, MouseUtil.BTN_RIGHT))
            {
                Event.current.Use();

                if (this.serializedProperty != null)
                {
                    var menu = new GenericMenu();
                    var prop = this.serializedProperty;
                    menu.AddItem(new GUIContent("Clear"), false, () =>
                    {
                        prop.serializedObject.Update();
                        prop.arraySize = 0;
                        prop.serializedObject.ApplyModifiedProperties();
                    });
                    menu.ShowAsContext();
                }
                else if (this.list != null)
                {
                    var menu = new GenericMenu();
                    var lst  = this.list;
                    menu.AddItem(new GUIContent("Clear"), false, () =>
                    {
                        lst.Clear();
                    });
                    menu.ShowAsContext();
                }
            }
        }
        private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _maskList.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            const float RECURS_WIDTH       = 80f;
            const float RECURS_LABEL_WIDTH = 60f;

            //DRAW TRANSFORM
            var transProp = element.FindPropertyRelative("Transform");
            var transRect = new Rect(area.xMin, area.yMin, area.width - RECURS_WIDTH, EditorGUIUtility.singleLineHeight);

            EditorGUI.PropertyField(transRect, transProp, GUIContent.none);

            //DRAW RECURSIVE TOGGLE
            var recursProp       = element.FindPropertyRelative("Recursive");
            var recursTotalRect  = new Rect(transRect.xMax + 2f, area.yMin, RECURS_WIDTH - 2f, EditorGUIUtility.singleLineHeight);
            var recursLabelRect  = new Rect(recursTotalRect.xMin, recursTotalRect.yMin, RECURS_LABEL_WIDTH, recursTotalRect.height);
            var recursToggleRect = new Rect(recursLabelRect.xMax, recursTotalRect.yMin, recursTotalRect.xMax - recursLabelRect.xMax, recursTotalRect.height);
            var recursLabel      = new GUIContent("Recurses");

            EditorGUI.BeginProperty(recursTotalRect, recursLabel, recursProp);
            EditorGUI.LabelField(recursLabelRect, recursLabel);
            recursProp.boolValue = EditorGUI.Toggle(recursToggleRect, GUIContent.none, recursProp.boolValue);
            EditorGUI.EndProperty();

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_maskList, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 7
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);
            }
        }
Exemplo n.º 8
0
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var targProp = element.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);

            const float MARGIN             = 1.0f;
            const float WEIGHT_FIELD_WIDTH = 60f;
            const float PERC_FIELD_WIDTH   = 45f;
            const float FULLWEIGHT_WIDTH   = WEIGHT_FIELD_WIDTH + PERC_FIELD_WIDTH;

            EditorGUI.BeginProperty(area, GUIContent.none, targProp);

            Rect       trigRect;
            var        actInfo      = EventTriggerTargetPropertyDrawer.GetTriggerActivationInfo(element);
            GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + actInfo.ActivationTypeDisplayName);

            if (this.CustomizeEntryLabel != null)
            {
                this.CustomizeEntryLabel(labelContent, index);
            }
            if (_drawWeight && area.width > FULLWEIGHT_WIDTH)
            {
                var top        = area.yMin + MARGIN;
                var labelRect  = new Rect(area.xMin, top, EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, EditorGUIUtility.singleLineHeight);
                var weightRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, top, WEIGHT_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                var percRect   = new Rect(area.xMin + EditorGUIUtility.labelWidth - PERC_FIELD_WIDTH, top, PERC_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

                var   weightProp = element.FindPropertyRelative(PROP_WEIGHT);
                float weight     = weightProp.floatValue;

                EditorGUI.LabelField(labelRect, labelContent);
                weightProp.floatValue = EditorGUI.FloatField(weightRect, weight);
                float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f);
                EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p));
            }
            else
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var top       = area.yMin + MARGIN;
                var labelRect = new Rect(area.xMin, top, area.width, EditorGUIUtility.singleLineHeight);

                trigRect = EditorGUI.PrefixLabel(labelRect, labelContent);
            }

            //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
            EditorGUI.BeginChangeCheck();
            var targObj = EventTriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue);

            if (EditorGUI.EndChangeCheck())
            {
                targProp.objectReferenceValue = EventTriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, actInfo.ActivationType) ? targObj : null;
            }
            EditorGUI.EndProperty();

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
        private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            //EditorGUI.PropertyField(area, element, GUIContent.none, false);
            var        attrib = this.attribute as ReorderableArrayAttribute;
            GUIContent label  = GUIContent.none;

            if (attrib != null)
            {
                if (attrib.ElementLabelFormatString != null)
                {
                    label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index));
                }
                if (attrib.ElementPadding > 0f)
                {
                    area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height);
                }
            }

            if (_drawElementAtBottom)
            {
                var lbl = TempElementLabel(element, index);
                SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry);

                if (prop != null)
                {
                    SPEditorGUI.PropertyField(area, prop, lbl);
                }
                else
                {
                    EditorGUI.LabelField(area, lbl);
                }
            }
            else
            {
                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(area, element, label);
                }
                else
                {
                    SPEditorGUI.DefaultPropertyField(area, element, label, false);
                }
            }

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
        private void _animList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _animList.serializedProperty.GetArrayElementAtIndex(index);

            _clipDrawer.DrawClip(area, element, EditorHelper.TempContent(index.ToString()), Mathf.Min(area.width * 0.08f, 30f), _nameLabelGUIStyle, _isStaticColl);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_animList, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 11
0
        private void _prefabList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            //EditorGUI.PropertyField(area, element, false);
            element.objectReferenceValue = EditorGUI.ObjectField(area, element.objectReferenceValue, typeof(GameObject), false);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 12
0
        private void _timeLayers_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            string layerName = _timeLayersHelper.Layers[index] as string;

            EditorGUI.BeginChangeCheck();
            layerName = EditorGUI.TextField(area, layerName);
            if (EditorGUI.EndChangeCheck())
            {
                _timeLayersHelper.Layers[index] = layerName;
            }

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_timeLayersListDrawer, area, index, isActive, isFocused);
            }
        }
        protected virtual void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            //EditorGUI.PropertyField(area, element, GUIContent.none, false);
            GUIContent label = null;

            if (_hideElementLabel)
            {
                label = GUIContent.none;
            }
            else
            {
                if (this.FormatElementLabel != null)
                {
                    string slbl = this.FormatElementLabel(element, index, isActive, isFocused);
                    if (slbl != null)
                    {
                        label = EditorHelper.TempContent(slbl);
                    }
                }
                else if (!string.IsNullOrEmpty(_elementLabelFormatString))
                {
                    label = EditorHelper.TempContent(string.Format(_elementLabelFormatString, index));
                }
                else
                {
                    label = TempElementLabel(element, index);
                }
                if (_elementPadding > 0f)
                {
                    area = new Rect(area.xMin + _elementPadding, area.yMin, Mathf.Max(0f, area.width - _elementPadding), area.height);
                }
            }

            this.DrawElement(area, element, label, index);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 14
0
        protected virtual void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            var label = this.GetFormattedElementLabel(area, index, isActive, isFocused);

            this.DrawElement(area, element, label, index);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
        private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            //EditorGUI.PropertyField(area, element, GUIContent.none, false);
            var        attrib = this.attribute as ReorderableArrayAttribute;
            GUIContent label  = null;

            if (this.FormatElementLabel != null)
            {
                string slbl = this.FormatElementLabel(element, index, isActive, isFocused);
                if (slbl != null)
                {
                    label = EditorHelper.TempContent(slbl);
                }
            }
            else if (attrib != null)
            {
                if (attrib.ElementLabelFormatString != null)
                {
                    label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index));
                }
                if (attrib.ElementPadding > 0f)
                {
                    area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height);
                }
            }
            if (label == null)
            {
                label = (_hideElementLabel) ? GUIContent.none : TempElementLabel(element, index);
            }

            this.DrawElement(area, element, label, index);

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
Exemplo n.º 16
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.º 17
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);
            }
        }
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var trigProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);
            var actProp  = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_ACTIVATIONTYPE);
            //var act = (TriggerActivationType)actProp.enumValueIndex;
            var act = actProp.GetEnumValue <TriggerActivationType>();

            const float MARGIN = 1.0f;

            if (act == TriggerActivationType.TriggerAllOnTarget)
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var trigRect  = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight);
                var trigLabel = new GUIContent("Target");
                EditorGUI.BeginProperty(trigRect, trigLabel, trigProp);
                trigProp.objectReferenceValue = SPEditorGUI.ComponentField(trigRect,
                                                                           trigLabel,
                                                                           ValidateTriggerableTargAsMechanism(trigProp.objectReferenceValue) as Component,
                                                                           typeof(ITriggerableMechanism),
                                                                           true);
                EditorGUI.EndProperty();
            }
            else
            {
                //Draw Triggerable - this forces the user to use the advanced settings, not for newbs
                var trigRect  = new Rect(area.xMin, area.yMin + MARGIN, area.width, EditorGUIUtility.singleLineHeight);
                var trigLabel = new GUIContent("Advanced Target", "A target is not set, see advanced settings section to set a target.");

                if (trigProp.objectReferenceValue != null)
                {
                    var        obj      = trigProp.objectReferenceValue;
                    var        trigType = trigProp.objectReferenceValue.GetType();
                    GUIContent extraLabel;
                    switch (act)
                    {
                    case TriggerActivationType.SendMessage:
                        extraLabel = new GUIContent("(SendMessage) " + obj.name);
                        break;

                    case TriggerActivationType.TriggerSelectedTarget:
                        extraLabel = new GUIContent("(TriggerSelectedTarget) " + obj.name + " -> " + trigType.Name);
                        break;

                    case TriggerActivationType.CallMethodOnSelectedTarget:
                        extraLabel = new GUIContent("(CallMethodOnSelectedTarget) " + obj.name + " -> " + trigType.Name + "." + element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_METHODNAME).stringValue);
                        break;

                    default:
                        extraLabel = GUIContent.none;
                        break;
                    }
                    EditorGUI.LabelField(trigRect, trigLabel, extraLabel);
                }
                else
                {
                    EditorGUI.LabelField(trigRect, trigLabel, new GUIContent("No Target"), new GUIStyle("Label")
                    {
                        alignment = TextAnchor.MiddleCenter
                    });
                }
            }

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var trigProp = element.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG);
            var actProp  = element.FindPropertyRelative(TriggerTargetProps.PROP_ACTIVATIONTYPE);
            //var act = (TriggerActivationType)actProp.enumValueIndex;
            var act = actProp.GetEnumValue <TriggerActivationType>();

            const float MARGIN             = 1.0f;
            const float SMALL_LABEL_WIDTH  = 120f;
            const float WEIGHT_FIELD_WIDTH = 60f;
            const float PERC_FIELD_WIDTH   = 45f;

            Rect       trigRect;
            GUIContent labelContent = (act == TriggerActivationType.TriggerAllOnTarget) ? EditorHelper.TempContent("Target") : EditorHelper.TempContent("Advanced Target", "A target is not set, see advanced settings section to set a target.");

            if (_drawWeight && area.width > SMALL_LABEL_WIDTH)
            {
                var totalwidth = area.width - SMALL_LABEL_WIDTH;
                var top        = area.yMin + MARGIN;
                var labelRect  = new Rect(area.xMin, top, SMALL_LABEL_WIDTH, EditorGUIUtility.singleLineHeight);
                var weightRect = new Rect(labelRect.xMax, top, Mathf.Min(totalwidth, WEIGHT_FIELD_WIDTH), EditorGUIUtility.singleLineHeight);
                var percRect   = new Rect(weightRect.xMax, top, Mathf.Min(totalwidth - weightRect.width, PERC_FIELD_WIDTH), EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(percRect.xMax, top, Mathf.Max(0f, totalwidth - weightRect.width - percRect.width), EditorGUIUtility.singleLineHeight);

                var   weightProp = element.FindPropertyRelative(PROP_WEIGHT);
                float weight     = weightProp.floatValue;

                EditorGUI.LabelField(labelRect, labelContent);
                weightProp.floatValue = EditorGUI.FloatField(weightRect, weight);
                float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f);
                EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p));
            }
            else
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var top       = area.yMin + MARGIN;
                var labelRect = new Rect(area.xMin, top, Mathf.Min(area.width, EditorGUIUtility.labelWidth), EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(labelRect.xMax, top, Mathf.Max(0f, area.width - labelRect.width), EditorGUIUtility.singleLineHeight);

                EditorGUI.LabelField(labelRect, labelContent);
            }

            if (act == TriggerActivationType.TriggerAllOnTarget)
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                EditorGUI.BeginProperty(trigRect, GUIContent.none, trigProp);
                var targGo    = GameObjectUtil.GetGameObjectFromSource(trigProp.objectReferenceValue);
                var newTargGo = EditorGUI.ObjectField(trigRect, GUIContent.none, targGo, typeof(GameObject), true) as GameObject;
                if (newTargGo != targGo)
                {
                    targGo = newTargGo;
                    trigProp.objectReferenceValue = (targGo != null) ? targGo.transform : null;
                }
                EditorGUI.EndProperty();
            }
            else
            {
                //Draw Triggerable - this forces the user to use the advanced settings, not for newbs
                if (trigProp.objectReferenceValue != null)
                {
                    var        go       = GameObjectUtil.GetGameObjectFromSource(trigProp.objectReferenceValue);
                    var        trigType = trigProp.objectReferenceValue.GetType();
                    GUIContent extraLabel;
                    switch (act)
                    {
                    case TriggerActivationType.SendMessage:
                        extraLabel = new GUIContent("(SendMessage) " + go.name);
                        break;

                    case TriggerActivationType.TriggerSelectedTarget:
                        extraLabel = new GUIContent("(TriggerSelectedTarget) " + go.name + " -> " + trigType.Name);
                        break;

                    case TriggerActivationType.CallMethodOnSelectedTarget:
                        extraLabel = new GUIContent("(CallMethodOnSelectedTarget) " + go.name + " -> " + trigType.Name + "." + element.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME).stringValue);
                        break;

                    default:
                        extraLabel = GUIContent.none;
                        break;
                    }
                    EditorGUI.LabelField(trigRect, extraLabel);
                }
                else
                {
                    EditorGUI.LabelField(trigRect, EditorHelper.TempContent("No Target"), new GUIStyle("Label")
                    {
                        alignment = TextAnchor.MiddleCenter
                    });
                }
            }

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
Exemplo n.º 20
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);
            }
        }
        private void _targetList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _targetList.serializedProperty.GetArrayElementAtIndex(index);

            var targProp = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);
            var actProp  = element.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_ACTIVATIONTYPE);
            //var act = (TriggerActivationType)actProp.enumValueIndex;
            var act = actProp.GetEnumValue <TriggerActivationType>();

            const float MARGIN             = 1.0f;
            const float WEIGHT_FIELD_WIDTH = 60f;
            const float PERC_FIELD_WIDTH   = 45f;
            const float FULLWEIGHT_WIDTH   = WEIGHT_FIELD_WIDTH + PERC_FIELD_WIDTH;

            EditorGUI.BeginProperty(area, GUIContent.none, targProp);

            Rect       trigRect;
            GUIContent labelContent = EditorHelper.TempContent(index.ToString("00: ") + act.ToString()); //(act == TriggerActivationType.TriggerAllOnTarget) ? EditorHelper.TempContent("Target") : EditorHelper.TempContent(string.Format("Target ({0})", act));

            if (_drawWeight && area.width > FULLWEIGHT_WIDTH)
            {
                var top        = area.yMin + MARGIN;
                var labelRect  = new Rect(area.xMin, top, EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, EditorGUIUtility.singleLineHeight);
                var weightRect = new Rect(area.xMin + EditorGUIUtility.labelWidth - FULLWEIGHT_WIDTH, top, WEIGHT_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                var percRect   = new Rect(area.xMin + EditorGUIUtility.labelWidth - PERC_FIELD_WIDTH, top, PERC_FIELD_WIDTH, EditorGUIUtility.singleLineHeight);
                trigRect = new Rect(area.xMin + EditorGUIUtility.labelWidth, top, area.width - EditorGUIUtility.labelWidth, EditorGUIUtility.singleLineHeight);

                var   weightProp = element.FindPropertyRelative(PROP_WEIGHT);
                float weight     = weightProp.floatValue;

                EditorGUI.LabelField(labelRect, labelContent);
                weightProp.floatValue = EditorGUI.FloatField(weightRect, weight);
                float p = (_totalWeight > 0f) ? (100f * weight / _totalWeight) : ((index == 0) ? 100f : 0f);
                EditorGUI.LabelField(percRect, string.Format("{0:0.#}%", p));
            }
            else
            {
                //Draw Triggerable - this is the simple case to make a clean designer set up for newbs
                var top       = area.yMin + MARGIN;
                var labelRect = new Rect(area.xMin, top, area.width, EditorGUIUtility.singleLineHeight);

                trigRect = EditorGUI.PrefixLabel(labelRect, labelContent);
            }

            //Draw Triggerable - this is the simple case to make a clean designer set up for newbs

            /*
             * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue);
             * var newTargGo = EditorGUI.ObjectField(trigRect, GUIContent.none, targGo, typeof(GameObject), true) as GameObject;
             * if (newTargGo != targGo)
             * {
             *  targGo = newTargGo;
             *  targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null;
             * }
             */
            EditorGUI.BeginChangeCheck();
            var targObj = TriggerTargetPropertyDrawer.TargetObjectField(trigRect, GUIContent.none, targProp.objectReferenceValue);

            if (EditorGUI.EndChangeCheck())
            {
                targProp.objectReferenceValue = TriggerTargetPropertyDrawer.IsValidTriggerTarget(targObj, act) ? targObj : null;
            }
            EditorGUI.EndProperty();

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
Exemplo n.º 22
0
        private void _maskList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            var element = _lst.serializedProperty.GetArrayElementAtIndex(index);

            if (element == null)
            {
                return;
            }

            //EditorGUI.PropertyField(area, element, GUIContent.none, false);
            var        attrib = this.attribute as ReorderableArrayAttribute;
            GUIContent label  = GUIContent.none;

            if (attrib != null)
            {
                if (attrib.ElementLabelFormatString != null)
                {
                    label = EditorHelper.TempContent(string.Format(attrib.ElementLabelFormatString, index));
                }
                if (attrib.ElementPadding > 0f)
                {
                    area = new Rect(area.xMin + attrib.ElementPadding, area.yMin, Mathf.Max(0f, area.width - attrib.ElementPadding), area.height);
                }
            }

            if (_drawElementAtBottom)
            {
                var lbl = TempElementLabel(element, index);
                SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry);

                if (prop != null)
                {
                    SPEditorGUI.PropertyField(area, prop, lbl);
                }
                else
                {
                    EditorGUI.LabelField(area, lbl);
                }
            }
            else
            {
                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(area, element, label);
                }
                else if (element.hasChildren && element.objectReferenceValue is MonoBehaviour)
                {
                    //we don't draw this way if it's a built-in type from Unity
                    var labelArea = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
                    EditorGUI.LabelField(labelArea, label);
                    var childArea = new Rect(area.xMin, area.yMin + EditorGUIUtility.singleLineHeight + 1f, area.width, area.height - EditorGUIUtility.singleLineHeight);
                    SPEditorGUI.FlatChildPropertyField(childArea, element);
                }
                else
                {
                    SPEditorGUI.DefaultPropertyField(area, element, label, false);
                }
            }

            if (GUI.enabled)
            {
                ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_lst, area, index, isActive, isFocused);
            }
        }
        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();
            }
        }