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 + TOP_PAD;
                    }
                    else
                    {
                        h = SPEditorGUI.GetDefaultPropertyHeight(pchild, label2, true) + BOTTOM_PAD + TOP_PAD;
                    }
                    var area     = new Rect(position.x, position.yMax - h, position.width, h);
                    var drawArea = new Rect(area.x, area.y + TOP_PAD, area.width, area.height - TOP_PAD);

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

                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(drawArea, pchild, label2);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(drawArea, pchild, GUIContent.none, true);
                    }
                }
            }
            else
            {
                EditorGUI.PropertyField(position, property, label, false);
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var prop_min = property.FindPropertyRelative(PROP_MIN);
            var prop_max = property.FindPropertyRelative(PROP_MAX);

            var   attrib             = this.fieldInfo.GetCustomAttributes(typeof(Interval.ConfigAttribute), false).Cast <Interval.ConfigAttribute>().FirstOrDefault();
            bool  reverse            = (attrib != null) ? attrib.Reverse : false;
            float minValue           = (attrib != null) ? attrib.MinValue : float.NegativeInfinity;
            float maxValue           = (attrib != null) ? attrib.MaxValue : float.PositiveInfinity;
            bool  discreteValuesOnly = (attrib != null) ? attrib.DiscreteValuesOnly : false;


            GUIContent[] subLabels;
            float        labelWidth;

            if (reverse)
            {
                subLabels  = (attrib != null) ? new GUIContent[] { EditorHelper.TempContent(attrib.MaxLabel), EditorHelper.TempContent(attrib.MinLabel) } : _defaultLabels;
                labelWidth = (attrib != null) ? attrib.LabelWidth : 30f;
                _values[1] = prop_min.floatValue;
                _values[0] = prop_max.floatValue;
            }
            else
            {
                subLabels  = (attrib != null) ? new GUIContent[] { EditorHelper.TempContent(attrib.MinLabel), EditorHelper.TempContent(attrib.MaxLabel) } : _defaultLabels;
                labelWidth = (attrib != null) ? attrib.LabelWidth : 30f;
                _values[0] = prop_min.floatValue;
                _values[1] = prop_max.floatValue;
            }

            EditorGUI.BeginProperty(position, label, property);
            EditorGUI.BeginChangeCheck();
            SPEditorGUI.DelayedMultiFloatField(position, label, subLabels, _values, labelWidth);
            if (EditorGUI.EndChangeCheck())
            {
                _values[0] = Mathf.Clamp(_values[0], minValue, maxValue);
                _values[1] = Mathf.Clamp(_values[1], minValue, maxValue);
                if (discreteValuesOnly)
                {
                    _values[0] = Mathf.Round(_values[0]);
                }
                if (discreteValuesOnly)
                {
                    _values[1] = Mathf.Round(_values[1]);
                }

                float min = reverse ? _values[1] : _values[0];
                float max = reverse ? _values[0] : _values[1];

                if (!MathUtil.FuzzyEqual(min, prop_min.floatValue))
                {
                    //changed min
                    if (max < min)
                    {
                        max = min;
                    }
                }
                else
                {
                    //changed max
                    if (min > max)
                    {
                        min = max;
                    }
                }

                prop_min.floatValue = min;
                prop_max.floatValue = max;
            }
            EditorGUI.EndProperty();
        }
Exemplo n.º 3
0
        private CachedReorderableList GetList(SerializedProperty property, GUIContent label)
        {
            var lst = CachedReorderableList.GetListDrawer(property, _maskList_DrawHeader, _maskList_DrawElement);

            lst.draggable = _draggable;

            if (property.arraySize > 0)
            {
                var pchild = property.GetArrayElementAtIndex(0);
                lst.elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(pchild, label) : SPEditorGUI.GetDefaultPropertyHeight(pchild, label) + 1;
            }
            else
            {
                lst.elementHeight = EditorGUIUtility.singleLineHeight;
            }

            return(lst);
        }
Exemplo n.º 4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            this.Init(property);

            EditorGUI.BeginProperty(position, label, property);

            //################################
            //FIRST LINE
            var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

            var configProp = property.FindPropertyRelative(PROP_CONFIGURED);
            var targetProp = property.FindPropertyRelative(PROP_TARGET);
            var findProp   = property.FindPropertyRelative(PROP_FIND);

            //var r0 = new Rect(rect.xMin, rect.yMin, EditorGUIUtility.labelWidth, rect.height);
            //rect = new Rect(r0.xMax, rect.yMin, rect.width - r0.width, rect.height);
            //property.isExpanded = EditorGUI.Foldout(r0, property.isExpanded, label);
            if (!this.AlwaysExpanded)
            {
                property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(ref rect, property.isExpanded, label);
            }
            else
            {
                rect = EditorGUI.PrefixLabel(rect, label);
            }

            var r0 = new Rect(rect.xMin, rect.yMin, Mathf.Min(rect.width * 0.25f, 50f), rect.height);
            var e  = (configProp.boolValue) ? TargetSource.Config : TargetSource.Arg;

            EditorGUI.BeginChangeCheck();
            e = (TargetSource)EditorGUI.EnumPopup(r0, e);
            if (EditorGUI.EndChangeCheck())
            {
                UpdateTargetFromSource(targetProp, e);
                configProp.boolValue = (e != TargetSource.Arg);
                if (e != TargetSource.Arg)
                {
                    findProp.SetEnumValue(TriggerableTargetObject.FindCommand.Direct);
                }
            }
            else if (e == TargetSource.Config && !_defaultSet && targetProp.objectReferenceValue == null)
            {
                UpdateTargetFromSource(targetProp, e);
                _defaultSet = true;
            }
            else
            {
                _defaultSet = true;
            }

            var r1 = new Rect(rect.xMin + r0.width, rect.yMin, rect.width - r0.width, rect.height);

            if (!configProp.boolValue)
            {
                var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>();
                switch (e0)
                {
                case TriggerableTargetObject.FindCommand.Direct:
                    EditorGUI.LabelField(r1, "Target determined by activating trigger.");
                    break;

                case TriggerableTargetObject.FindCommand.FindParent:
                case TriggerableTargetObject.FindCommand.FindInChildren:
                case TriggerableTargetObject.FindCommand.FindInEntity:
                    EditorGUI.LabelField(r1, e0.ToString() + " of activating trigger arg.");
                    break;

                case TriggerableTargetObject.FindCommand.FindInScene:
                case TriggerableTargetObject.FindCommand.FindEntityInScene:
                default:
                    configProp.boolValue            = false;
                    targetProp.objectReferenceValue = null;
                    EditorGUI.LabelField(r1, e0.ToString());
                    break;
                }

                targetProp.objectReferenceValue = null;
            }
            else
            {
                _objectDrawer.OnGUI(r1, targetProp, GUIContent.none);
            }


            //################################
            //SECOND LINE
            if (this.AlwaysExpanded || property.isExpanded)
            {
                var indent = EditorGUIUtility.labelWidth * 0.5f;
                rect = new Rect(position.xMin + indent, position.yMin + EditorGUIUtility.singleLineHeight, Mathf.Max(0f, position.width - indent), EditorGUIUtility.singleLineHeight);

                var w0 = Mathf.Min(rect.width * 0.3f, 120f);
                var w1 = Mathf.Min(rect.width * 0.3f, 80f);
                var w2 = rect.width - w0 - w1;
                r0 = new Rect(rect.xMin, rect.yMin, w0, rect.height);
                r1 = new Rect(r0.xMax, rect.yMin, w1, rect.height);
                var r2 = new Rect(r1.xMax, rect.yMin, w2, rect.height);

                var resolveProp = property.FindPropertyRelative(PROP_RESOLVEBY);
                var queryProp   = property.FindPropertyRelative(PROP_QUERY);

                var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>();
                EditorGUI.BeginChangeCheck();
                e0 = (TriggerableTargetObject.FindCommand)EditorGUI.EnumPopup(r0, e0);
                if (EditorGUI.EndChangeCheck())
                {
                    findProp.SetEnumValue(e0);
                }
                switch (e0)
                {
                case TriggerableTargetObject.FindCommand.FindInScene:
                case TriggerableTargetObject.FindCommand.FindEntityInScene:
                    configProp.boolValue            = false;
                    targetProp.objectReferenceValue = null;
                    break;
                }

                var e1 = resolveProp.GetEnumValue <TriggerableTargetObject.ResolveByCommand>();
                EditorGUI.BeginChangeCheck();
                e1 = (TriggerableTargetObject.ResolveByCommand)EditorGUI.EnumPopup(r1, e1);
                if (EditorGUI.EndChangeCheck())
                {
                    resolveProp.SetEnumValue(e1);
                }

                switch (e1)
                {
                case TriggerableTargetObject.ResolveByCommand.Nothing:
                {
                    var cache = SPGUI.Disable();
                    EditorGUI.TextField(r2, string.Empty);
                    queryProp.stringValue = string.Empty;
                    cache.Reset();
                }
                break;

                case TriggerableTargetObject.ResolveByCommand.WithTag:
                {
                    queryProp.stringValue = EditorGUI.TagField(r2, queryProp.stringValue);
                }
                break;

                case TriggerableTargetObject.ResolveByCommand.WithName:
                {
                    queryProp.stringValue = EditorGUI.TextField(r2, queryProp.stringValue);
                }
                break;

                case TriggerableTargetObject.ResolveByCommand.WithType:
                {
                    var tp = TypeUtil.FindType(queryProp.stringValue);
                    if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object)))
                    {
                        tp = null;
                    }
                    tp = SPEditorGUI.TypeDropDown(r2, GUIContent.none, typeof(UnityEngine.Object), tp);
                    queryProp.stringValue = (tp != null) ? tp.FullName : null;
                }
                break;
                }
            }

            EditorGUI.EndProperty();
        }
        private void _dataList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            Rect position;
            var  el = _dataList.serializedProperty.GetArrayElementAtIndex(index);

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_MODE));

            //TODO - member
            position = CalcNextRect(ref area);
            var memberProp = el.FindPropertyRelative(PROP_DATA_MEMBER);

            System.Type propType;
            memberProp.stringValue = i_TweenValueInspector.ReflectedPropertyAndCustomTweenAccessorField(position,
                                                                                                        EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                                                        _targetProp.objectReferenceValue,
                                                                                                        memberProp.stringValue,
                                                                                                        com.spacepuppy.Dynamic.DynamicMemberAccess.ReadWrite,
                                                                                                        out propType);

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_EASE));

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_DUR));

            if (propType != null)
            {
                switch (el.FindPropertyRelative(PROP_DATA_MODE).GetEnumValue <TweenHash.AnimMode>())
                {
                case TweenHash.AnimMode.To:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("To Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                }
                break;

                case TweenHash.AnimMode.From:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("From Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));
                }
                break;

                case TweenHash.AnimMode.By:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("By Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));
                }
                break;

                case TweenHash.AnimMode.FromTo:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("Start Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("End Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUEE));
                }
                break;

                case TweenHash.AnimMode.RedirectTo:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("Start Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("End Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUEE));
                }
                break;
                }
            }
        }
        private void DrawValueFieldInValueMode(Rect position, SerializedProperty property, VariantReference.EditorHelper helper)
        {
            if (helper.Target == null)
            {
                return;
            }
            var variant = helper.Target;

            if (this.RestrictVariantType && helper._type != this.VariantTypeRestrictedTo)
            {
                helper.PrepareForValueTypeChange(this.VariantTypeRestrictedTo);
                GUI.changed = true; //force change
            }

            var r0 = new Rect(position.xMin, position.yMin, 90.0f, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, position.yMin, position.xMax - r0.xMax, EditorGUIUtility.singleLineHeight);

            var cache = SPGUI.DisableIf(this.RestrictVariantType);

            EditorGUI.BeginChangeCheck();
            var valueType = (VariantType)EditorGUI.EnumPopup(r0, GUIContent.none, variant.ValueType);

            if (EditorGUI.EndChangeCheck())
            {
                helper.PrepareForValueTypeChange(valueType);
            }
            cache.Reset();

            if (_typeRestrictedTo.IsEnum)
            {
                variant.IntValue = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(_typeRestrictedTo, variant.IntValue)));
            }
            else
            {
                switch (valueType)
                {
                case VariantType.Null:
                    cache = SPGUI.Disable();
                    EditorGUI.TextField(r1, "Null");
                    cache.Reset();
                    break;

                case VariantType.String:
                    variant.StringValue = EditorGUI.TextField(r1, variant.StringValue);
                    break;

                case VariantType.Boolean:
                    variant.BoolValue = EditorGUI.Toggle(r1, variant.BoolValue);
                    break;

                case VariantType.Integer:
                    variant.IntValue = EditorGUI.IntField(r1, variant.IntValue);
                    break;

                case VariantType.Float:
                    variant.FloatValue = EditorGUI.FloatField(r1, variant.FloatValue);
                    break;

                case VariantType.Double:
                    variant.DoubleValue = ConvertUtil.ToDouble(EditorGUI.TextField(r1, variant.DoubleValue.ToString()));
                    break;

                case VariantType.Vector2:
                    variant.Vector2Value = EditorGUI.Vector2Field(r1, GUIContent.none, variant.Vector2Value);
                    break;

                case VariantType.Vector3:
                    variant.Vector3Value = EditorGUI.Vector3Field(r1, GUIContent.none, variant.Vector3Value);
                    break;

                case VariantType.Vector4:
                    variant.Vector4Value = EditorGUI.Vector4Field(r1, (string)null, variant.Vector4Value);
                    break;

                case VariantType.Quaternion:
                    variant.QuaternionValue = SPEditorGUI.QuaternionField(r1, GUIContent.none, variant.QuaternionValue);
                    break;

                case VariantType.Color:
                    variant.ColorValue = EditorGUI.ColorField(r1, variant.ColorValue);
                    break;

                case VariantType.DateTime:
                    variant.DateValue = ConvertUtil.ToDate(EditorGUI.TextField(r1, variant.DateValue.ToString()));
                    break;

                case VariantType.GameObject:
                    variant.GameObjectValue = EditorGUI.ObjectField(r1, variant.GameObjectValue, typeof(GameObject), true) as GameObject;
                    break;

                case VariantType.Component:
                {
                    _selectComponentDrawer.AllowNonComponents = false;
                    _selectComponentDrawer.RestrictionType    = _forcedObjectType;
                    _selectComponentDrawer.ShowXButton        = true;
                    var targProp = property.FindPropertyRelative("_unityObjectReference");
                    EditorGUI.BeginChangeCheck();
                    _selectComponentDrawer.OnGUI(r1, targProp);
                    if (EditorGUI.EndChangeCheck())
                    {
                        variant.ComponentValue = targProp.objectReferenceValue as Component;
                    }
                }
                break;

                case VariantType.Object:
                {
                    var obj = variant.ObjectValue;
                    if (ComponentUtil.IsAcceptableComponentType(_forcedObjectType))
                    {
                        if (obj is GameObject || obj is Component)
                        {
                            _selectComponentDrawer.AllowNonComponents = false;
                            _selectComponentDrawer.RestrictionType    = _forcedObjectType;
                            _selectComponentDrawer.ShowXButton        = true;
                            var targProp = property.FindPropertyRelative("_unityObjectReference");
                            EditorGUI.BeginChangeCheck();
                            _selectComponentDrawer.OnGUI(r1, targProp);
                            if (EditorGUI.EndChangeCheck())
                            {
                                variant.ObjectValue = targProp.objectReferenceValue as Component;
                            }
                        }
                        else
                        {
                            EditorGUI.BeginChangeCheck();
                            obj = EditorGUI.ObjectField(r1, obj, typeof(UnityEngine.Object), true);
                            if (EditorGUI.EndChangeCheck())
                            {
                                if (obj == null)
                                {
                                    variant.ObjectValue = null;
                                }
                                else if (TypeUtil.IsType(obj.GetType(), _forcedObjectType))
                                {
                                    variant.ObjectValue = obj;
                                }
                                else
                                {
                                    var go = GameObjectUtil.GetGameObjectFromSource(obj);
                                    if (go != null)
                                    {
                                        variant.ObjectValue = go.GetComponent(_forcedObjectType);
                                    }
                                    else
                                    {
                                        variant.ObjectValue = null;
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        variant.ObjectValue = EditorGUI.ObjectField(r1, obj, _forcedObjectType, true);
                    }
                }
                break;

                case VariantType.LayerMask:
                {
                    variant.LayerMaskValue = SPEditorGUI.LayerMaskField(r1, GUIContent.none, (int)variant.LayerMaskValue);
                }
                break;

                case VariantType.Rect:
                {
                    variant.RectValue = EditorGUI.RectField(r1, variant.RectValue);
                }
                break;
                }
            }
        }
Exemplo n.º 7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!property.isArray)
            {
                EditorGUI.PropertyField(position, property, label, false);
                return;
            }

            if (property.arraySize == 0)
            {
                property.arraySize = 1;
            }

            if (property.arraySize == 1)
            {
                var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(0), label) : EditorGUIUtility.singleLineHeight;
                var propArea      = new Rect(position.xMin, position.yMin, Mathf.Max(0f, position.width - BTN_WIDTH), elementHeight);
                var btnArea       = new Rect(propArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);

                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(propArea, property.GetArrayElementAtIndex(0), label);
                }
                else
                {
                    SPEditorGUI.DefaultPropertyField(propArea, property.GetArrayElementAtIndex(0), label);
                }
                if (GUI.Button(btnArea, _moreBtnLabel))
                {
                    property.arraySize = 2;
                }
            }
            else
            {
                var elementArea = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

                //draw header
                var leftOverArea = EditorGUI.PrefixLabel(elementArea, label ?? GUIContent.none);
                var sizeArea     = new Rect(Mathf.Max(leftOverArea.xMin, leftOverArea.xMax - BTN_WIDTH - SIZE_WIDTH),
                                            leftOverArea.yMin,
                                            Mathf.Min(SIZE_WIDTH, Mathf.Max(0f, leftOverArea.width - BTN_WIDTH)), EditorGUIUtility.singleLineHeight);
                var btnArea = new Rect(sizeArea.xMax, position.yMin, Mathf.Min(BTN_WIDTH, position.width), EditorGUIUtility.singleLineHeight);
                property.arraySize = Mathf.Max(EditorGUI.IntField(sizeArea, property.arraySize), 1);
                if (GUI.Button(btnArea, _oneBtnLabel))
                {
                    property.arraySize = 1;
                }

                EditorGUI.indentLevel++;
                for (int i = 0; i < property.arraySize; i++)
                {
                    var lbl           = EditorHelper.TempContent("Element " + i.ToString());
                    var elementHeight = (_internalDrawer != null) ? _internalDrawer.GetPropertyHeight(property.GetArrayElementAtIndex(i), lbl) : EditorGUIUtility.singleLineHeight;
                    elementArea = new Rect(position.xMin, elementArea.yMax, position.width, elementHeight);

                    if (_internalDrawer != null)
                    {
                        _internalDrawer.OnGUI(elementArea, property.GetArrayElementAtIndex(i), lbl);
                    }
                    else
                    {
                        SPEditorGUI.DefaultPropertyField(elementArea, property.GetArrayElementAtIndex(i), lbl);
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
Exemplo n.º 8
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var r0 = new Rect(position.xMin, position.yMin, position.width / 2f, position.height);
            var r1 = new Rect(r0.xMax, position.yMin, position.width - r0.width, position.height);

            var propName  = property.FindPropertyRelative(PROP_NAME);
            var propValue = property.FindPropertyRelative(PROP_VALUE);
            var propRef   = property.FindPropertyRelative(PROP_REF);

            int index = System.Array.IndexOf(_knownPlayerSettingPropNames, propName.stringValue);

            EditorGUI.BeginChangeCheck();
            index = EditorGUI.Popup(r0, GUIContent.none, index, _knownPlayerSettingPropNamesPretty);
            if (EditorGUI.EndChangeCheck())
            {
                if (index >= 0 && index < _knownPlayerSettingPropNames.Length)
                {
                    propName.stringValue = _knownPlayerSettingPropNames[index];
                }
                else
                {
                    propName.stringValue = string.Empty;
                }

                propValue.stringValue        = string.Empty;
                propRef.objectReferenceValue = null;
            }

            if (index < 0 || index >= _knownPlayerSettings.Length)
            {
                return;
            }

            var info = _knownPlayerSettings[index];

            if (info.PropertyType.IsEnum)
            {
                int ei = ConvertUtil.ToInt(propValue.stringValue);
                propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.EnumPopup(r1, ConvertUtil.ToEnumOfType(info.PropertyType, ei))).ToString();
                propRef.objectReferenceValue = null;
            }
            else
            {
                var etp = VariantReference.GetVariantType(info.PropertyType);
                switch (etp)
                {
                case VariantType.Null:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.String:
                    propValue.stringValue        = EditorGUI.TextField(r1, propValue.stringValue);
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Boolean:
                    propValue.stringValue        = EditorGUI.Toggle(r1, GUIContent.none, ConvertUtil.ToBool(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Integer:
                    propValue.stringValue        = EditorGUI.IntField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Float:
                    propValue.stringValue        = EditorGUI.FloatField(r1, GUIContent.none, ConvertUtil.ToSingle(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Double:
                    propValue.stringValue        = EditorGUI.DoubleField(r1, GUIContent.none, ConvertUtil.ToDouble(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector2:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector2Field(r1, GUIContent.none, ConvertUtil.ToVector2(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector3:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector3Field(r1, GUIContent.none, ConvertUtil.ToVector3(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Vector4:
                    propValue.stringValue        = VectorUtil.Stringify(EditorGUI.Vector4Field(r1, (string)null, ConvertUtil.ToVector4(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Quaternion:
                    propValue.stringValue        = QuaternionUtil.Stringify(SPEditorGUI.QuaternionField(r1, GUIContent.none, ConvertUtil.ToQuaternion(propValue.stringValue)));
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Color:
                    propValue.stringValue        = ConvertUtil.ToInt(EditorGUI.ColorField(r1, ConvertUtil.ToColor(propValue.stringValue))).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.DateTime:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.GameObject:
                case VariantType.Component:
                case VariantType.Object:
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = EditorGUI.ObjectField(r1, GUIContent.none, propValue.objectReferenceValue, info.PropertyType, false);
                    break;

                case VariantType.LayerMask:
                    propValue.stringValue        = SPEditorGUI.LayerMaskField(r1, GUIContent.none, ConvertUtil.ToInt(propValue.stringValue)).ToString();
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Rect:
                    //TODO - should never actually occur
                    propValue.stringValue        = string.Empty;
                    propRef.objectReferenceValue = null;
                    break;

                case VariantType.Numeric:

                    break;
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            EditorGUI.BeginProperty(position, label, property);


            var  baseType           = typeof(object);
            bool allowAbstractTypes = false;
            bool allowInterfaces    = false;

            System.Type              defaultType   = null;
            System.Type[]            excludedTypes = null;
            TypeDropDownListingStyle style         = TypeDropDownListingStyle.Namespace;

            System.Predicate <System.Type> searchPredicate = null;

            if (_isManuallyConfigured)
            {
                baseType           = _inheritsFromType ?? typeof(object);
                allowAbstractTypes = _allowAbstractTypes;
                allowInterfaces    = _allowInterfaces;
                defaultType        = _defaultType;
                excludedTypes      = _excludedTypes;
                style           = _dropDownStyle;
                searchPredicate = _searchPredicate;
            }
            else if (this.fieldInfo != null)
            {
                var attrib = this.fieldInfo.GetCustomAttributes(typeof(TypeReference.ConfigAttribute), true).FirstOrDefault() as TypeReference.ConfigAttribute;
                if (attrib != null)
                {
                    baseType           = attrib.inheritsFromType;
                    allowAbstractTypes = attrib.allowAbstractClasses;
                    allowInterfaces    = attrib.allowInterfaces;
                    defaultType        = attrib.defaultType;
                    excludedTypes      = attrib.excludedTypes;
                    style           = attrib.dropDownStyle;
                    searchPredicate = null;
                }
            }



            //var tpref = EditorHelper.GetTargetObjectOfProperty(property) as TypeReference;
            //if(tpref == null)
            //{
            //    tpref = new TypeReference();
            //    EditorHelper.SetTargetObjectOfProperty(property, tpref);
            //    property.serializedObject.ApplyModifiedProperties();
            //}

            //EditorGUI.BeginChangeCheck();
            //tpref.Type = SPEditorGUI.TypeDropDown(position, label, baseType, tpref.Type, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, style);
            //if (EditorGUI.EndChangeCheck())
            //    property.serializedObject.Update();



            var tp = GetTypeFromTypeReference(property);

            EditorGUI.BeginChangeCheck();
            tp = SPEditorGUI.TypeDropDown(position, label, baseType, tp, allowAbstractTypes, allowInterfaces, defaultType, excludedTypes, style, searchPredicate);
            if (EditorGUI.EndChangeCheck())
            {
                SetTypeToTypeReference(property, tp);
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 10
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            //EditorGUI.BeginProperty(position, label, property);
            //if(property.isExpanded)
            //{
            //    var r1 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            //    var r2 = new Rect(position.xMin, r1.yMax, position.width, EditorGUIUtility.singleLineHeight);
            //    var r3 = new Rect(position.xMin, r2.yMax, position.width, EditorGUIUtility.singleLineHeight);

            //    property.isExpanded = EditorGUI.Foldout(r1, property.isExpanded, GUIContent.none);
            //    SPEditorGUI.DefaultPropertyField(r1, property.FindPropertyRelative(PROP_WEIGHT), label);
            //    EditorGUI.indentLevel++;
            //    SPEditorGUI.DefaultPropertyField(r2, property.FindPropertyRelative(PROP_DIMINISHRATE), EditorHelper.TempContent("Diminish Rate"));
            //    SPEditorGUI.DefaultPropertyField(r3, property.FindPropertyRelative(PROP_DIMINISHPERIOD), EditorHelper.TempContent("Diminish Period Duration"));
            //    EditorGUI.indentLevel--;
            //}
            //else
            //{
            //    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
            //    SPEditorGUI.DefaultPropertyField(position, property.FindPropertyRelative(PROP_WEIGHT), label);
            //}
            //EditorGUI.EndProperty();


            if (!this.DrawFoldout || property.isExpanded)
            {
                const float LINE2_MARGIN = 20f;
                var         r1           = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                var         r2           = new Rect(position.xMin + LINE2_MARGIN, r1.yMax, Mathf.Max(position.width - LINE2_MARGIN, 0f), EditorGUIUtility.singleLineHeight);

                if (this.DrawFoldout)
                {
                    property.isExpanded = EditorGUI.Foldout(r1, property.isExpanded, GUIContent.none);
                }

                var weightProp = property.FindPropertyRelative(PROP_WEIGHT);

                _line1[0] = weightProp.floatValue;

                EditorGUI.BeginChangeCheck();
                SPEditorGUI.MultiFloatField(r1, label, _line1Labels, _line1, 50f);
                if (EditorGUI.EndChangeCheck())
                {
                    weightProp.floatValue = _line1[0];
                }

                var maxCountProp = property.FindPropertyRelative(PROP_MAXCOUNT);
                var rateProp     = property.FindPropertyRelative(PROP_DIMINISHRATE);
                var periodProp   = property.FindPropertyRelative(PROP_DIMINISHPERIOD);

                _line2[0] = maxCountProp.floatValue;
                _line2[1] = rateProp.floatValue;
                _line2[2] = periodProp.floatValue;

                EditorGUI.BeginChangeCheck();
                SPEditorGUI.MultiFloatField(r2, _line2Labels, _line2, 80f);
                if (EditorGUI.EndChangeCheck())
                {
                    maxCountProp.floatValue = DiscreteFloatPropertyDrawer.NormalizeValue(maxCountProp.floatValue, _line2[0]);
                    rateProp.floatValue     = _line2[1];
                    periodProp.floatValue   = _line2[2];
                }
            }
            else
            {
                if (this.DrawFoldout)
                {
                    property.isExpanded = EditorGUI.Foldout(position, property.isExpanded, GUIContent.none);
                }

                var weightProp = property.FindPropertyRelative(PROP_WEIGHT);
                _line1[0] = weightProp.floatValue;
                SPEditorGUI.MultiFloatField(position, label, _line1Labels, _line1, 50f);
            }
        }
Exemplo n.º 11
0
        private void _dataList_DrawElement(Rect area, int index, bool isActive, bool isFocused)
        {
            Rect position;
            var  el = _dataList.serializedProperty.GetArrayElementAtIndex(index);

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_MODE));

            //TODO - member
            position = CalcNextRect(ref area);
            var memberProp = el.FindPropertyRelative(PROP_DATA_MEMBER);

            System.Reflection.MemberInfo selectedMember;
            memberProp.stringValue = SPEditorGUI.ReflectedPropertyField(position,
                                                                        EditorHelper.TempContent("Property", "The property on the target to set."),
                                                                        _targetProp.objectReferenceValue,
                                                                        memberProp.stringValue,
                                                                        out selectedMember);

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_EASE));

            position = CalcNextRect(ref area);
            SPEditorGUI.PropertyField(position, el.FindPropertyRelative(PROP_DATA_DUR));

            if (selectedMember != null)
            {
                var propType = com.spacepuppy.Dynamic.DynamicUtil.GetParameters(selectedMember).FirstOrDefault();

                switch (el.FindPropertyRelative(PROP_DATA_MODE).GetEnumValue <TweenHash.AnimMode>())
                {
                case TweenHash.AnimMode.To:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("To Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                }
                break;

                case TweenHash.AnimMode.From:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("From Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));
                }
                break;

                case TweenHash.AnimMode.By:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("By Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));
                }
                break;

                case TweenHash.AnimMode.FromTo:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("Start Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("End Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUEE));
                }
                break;

                case TweenHash.AnimMode.RedirectTo:
                {
                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("Start Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUES));

                    position = CalcNextRect(ref area);
                    this.DrawVariant(position, EditorHelper.TempContent("End Value"), propType, el.FindPropertyRelative(PROP_DATA_VALUEE));
                }
                break;
                }
            }
        }
Exemplo n.º 12
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            this.Init(property);

            EditorGUI.BeginProperty(position, label, property);

            //################################
            //FIRST LINE
            var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

            var configProp = property.FindPropertyRelative(PROP_CONFIGURED);
            var targetProp = property.FindPropertyRelative(PROP_TARGET);

            //var r0 = new Rect(rect.xMin, rect.yMin, EditorGUIUtility.labelWidth, rect.height);
            //rect = new Rect(r0.xMax, rect.yMin, rect.width - r0.width, rect.height);
            //property.isExpanded = EditorGUI.Foldout(r0, property.isExpanded, label);
            property.isExpanded = SPEditorGUI.PrefixFoldoutLabel(ref rect, property.isExpanded, label);

            var r0 = new Rect(rect.xMin, rect.yMin, Mathf.Min(rect.width * 0.25f, 50f), rect.height);
            var e  = (configProp.boolValue) ? TargetSource.Config : TargetSource.Arg;

            EditorGUI.BeginChangeCheck();
            e = (TargetSource)EditorGUI.EnumPopup(r0, e);
            if (EditorGUI.EndChangeCheck())
            {
                UpdateTargetFromSource(targetProp, e, (_configAttrib != null) ? _configAttrib.TargetType : null);
                configProp.boolValue = (e != TargetSource.Arg);
            }
            else if (e == TargetSource.Config && !_defaultSet && targetProp.objectReferenceValue == null)
            {
                UpdateTargetFromSource(targetProp, e, (_configAttrib != null) ? _configAttrib.TargetType : null);
                _defaultSet = true;
            }
            else
            {
                _defaultSet = true;
            }

            var r1 = new Rect(rect.xMin + r0.width, rect.yMin, rect.width - r0.width, rect.height);

            if (!configProp.boolValue)
            {
                EditorGUI.LabelField(r1, "Target determined by activating trigger.");
                targetProp.objectReferenceValue = null;
            }
            else
            {
                _objectDrawer.RestrictionType = (_configAttrib != null) ? _configAttrib.TargetType : null;
                _objectDrawer.OnGUI(r1, targetProp, GUIContent.none);
            }


            //################################
            //SECOND LINE
            if (property.isExpanded)
            {
                var indent = EditorGUIUtility.labelWidth * 0.5f;
                rect = new Rect(position.xMin + indent, position.yMin + EditorGUIUtility.singleLineHeight, Mathf.Max(0f, position.width - indent), EditorGUIUtility.singleLineHeight);

                var w0 = Mathf.Min(rect.width * 0.3f, 120f);
                var w1 = Mathf.Min(rect.width * 0.3f, 80f);
                var w2 = rect.width - w0 - w1;
                r0 = new Rect(rect.xMin, rect.yMin, w0, rect.height);
                r1 = new Rect(r0.xMax, rect.yMin, w1, rect.height);
                var r2 = new Rect(r1.xMax, rect.yMin, w2, rect.height);

                var findProp    = property.FindPropertyRelative(PROP_FIND);
                var resolveProp = property.FindPropertyRelative(PROP_RESOLVEBY);
                var queryProp   = property.FindPropertyRelative(PROP_QUERY);

                var e0 = findProp.GetEnumValue <TriggerableTargetObject.FindCommand>();
                EditorGUI.BeginChangeCheck();
                e0 = (TriggerableTargetObject.FindCommand)EditorGUI.EnumPopup(r0, e0);
                if (EditorGUI.EndChangeCheck())
                {
                    findProp.SetEnumValue(e0);
                }

                var e1 = resolveProp.GetEnumValue <TriggerableTargetObject.ResolveByCommand>();
                EditorGUI.BeginChangeCheck();
                e1 = (TriggerableTargetObject.ResolveByCommand)EditorGUI.EnumPopup(r1, e1);
                if (EditorGUI.EndChangeCheck())
                {
                    resolveProp.SetEnumValue(e1);
                }

                switch (e1)
                {
                case TriggerableTargetObject.ResolveByCommand.Nothing:
                {
                    GUI.enabled = false;
                    EditorGUI.TextField(r2, string.Empty);
                    queryProp.stringValue = string.Empty;
                    GUI.enabled           = true;
                }
                break;

                case TriggerableTargetObject.ResolveByCommand.WithTag:
                {
                    queryProp.stringValue = EditorGUI.TagField(r2, queryProp.stringValue);
                }
                break;

                case TriggerableTargetObject.ResolveByCommand.WithName:
                {
                    queryProp.stringValue = EditorGUI.TextField(r2, queryProp.stringValue);
                }
                break;
                }
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 13
0
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            var signalSourceProp = property.FindPropertyRelative("_signalSource");

            return(SPEditorGUI.GetPropertyHeight(signalSourceProp, 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 = SPEditorGUI.PrefixFoldoutLabel(position, 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();
            }
        }
Exemplo n.º 15
0
        private void DrawAdvanced_TriggerSelected(Rect area, SerializedProperty property)
        {
            /*
             * //Draw Target
             * var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
             * var targProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);
             * var targLabel = EditorHelper.TempContent("Triggerable Target");
             * var targGo = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue);
             * var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject;
             * if (newTargGo != targGo)
             * {
             *  targGo = newTargGo;
             *  targProp.objectReferenceValue = (targGo != null) ? targGo.GetComponent<ITriggerableMechanism>() as Component : null;
             * }
             *
             * var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight);
             * if (targProp.objectReferenceValue != null)
             * {
             *  var selectedType = targProp.objectReferenceValue.GetType();
             *  var availableMechanismTypes = (from c in targGo.GetComponents<ITriggerableMechanism>() select c.GetType()).ToArray();
             *  var availableMechanismTypeNames = availableMechanismTypes.Select((tp) => tp.Name).ToArray();
             *
             *  var index = System.Array.IndexOf(availableMechanismTypes, selectedType);
             *  EditorGUI.BeginChangeCheck();
             *  index = EditorGUI.Popup(targCompPopupRect, "Target Component", index, availableMechanismTypeNames);
             *  if (EditorGUI.EndChangeCheck())
             *  {
             *      targProp.objectReferenceValue = (index >= 0) ? targGo.GetComponent(availableMechanismTypes[index]) : null;
             *  }
             * }
             * else
             * {
             *  EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)");
             * }
             *
             * //Draw Triggerable Arg
             * var argRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight);
             * var btnRect = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight);
             * var argArrayProp = property.FindPropertyRelative(TriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS);
             * if (argArrayProp.arraySize == 0)
             * {
             *  EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel);
             *  if (GUI.Button(btnRect, _argBtnLabel))
             *  {
             *      argArrayProp.arraySize = 1;
             *      argArrayProp.serializedObject.ApplyModifiedProperties();
             *  }
             * }
             * else
             * {
             *  if (argArrayProp.arraySize > 1) argArrayProp.arraySize = 1;
             *  var argProp = argArrayProp.GetArrayElementAtIndex(0);
             *  //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel);
             *  _variantDrawer.RestrictVariantType = false;
             *  _variantDrawer.ForcedObjectType = null;
             *  _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel);
             *
             *  if (GUI.Button(btnRect, _argBtnLabel))
             *  {
             *      argArrayProp.arraySize = 0;
             *      argArrayProp.serializedObject.ApplyModifiedProperties();
             *  }
             * }
             */


            var targRect = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
            var targProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLETARG);

            targRect = EditorGUI.PrefixLabel(targRect, EditorHelper.TempContent("Triggerable Target"));

            //validate
            if (!GameObjectUtil.IsGameObjectSource(targProp.objectReferenceValue) && !(targProp.objectReferenceValue is ITriggerable))
            {
                targProp.objectReferenceValue = null;
            }

            //draw obj field
            if (targProp.objectReferenceValue != null)
            {
                if (SPEditorGUI.XButton(ref targRect, "Clear Selected Object", true))
                {
                    targProp.objectReferenceValue = null;
                    goto DrawTriggerableArg;
                }

                var targObj = targProp.objectReferenceValue;

                var availableMechanisms         = ObjUtil.GetAllFromSource <ITriggerable>(targObj);
                var availableMechanismTypeNames = availableMechanisms.Select((o) => EditorHelper.TempContent(o.GetType().Name)).ToArray();

                var index = System.Array.IndexOf(availableMechanisms, targObj);
                EditorGUI.BeginChangeCheck();
                index = EditorGUI.Popup(targRect, GUIContent.none, index, availableMechanismTypeNames);
                if (EditorGUI.EndChangeCheck())
                {
                    targObj = (index >= 0) ? availableMechanisms[index] as UnityEngine.Object : null;
                    targProp.objectReferenceValue = targObj;
                }
            }
            else
            {
                EditorGUI.BeginChangeCheck();
                var targObj = TargetObjectField(targRect, GUIContent.none, targProp.objectReferenceValue);
                if (EditorGUI.EndChangeCheck())
                {
                    targObj = ObjUtil.GetAsFromSource <ITriggerable>(targObj) as UnityEngine.Object;
                    targProp.objectReferenceValue = targObj;
                }
            }


            //Draw Triggerable Arg
DrawTriggerableArg:
            var argRect = new Rect(area.xMin, targRect.yMax, area.width - ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight);
            var btnRect      = new Rect(argRect.xMax, argRect.yMin, ARG_BTN_WIDTH, EditorGUIUtility.singleLineHeight);
            var argArrayProp = property.FindPropertyRelative(EventTriggerTargetPropertyDrawer.PROP_TRIGGERABLEARGS);

            if (argArrayProp.arraySize == 0)
            {
                EditorGUI.LabelField(argRect, _defaultArgLabel, _undefinedArgLabel);
                if (GUI.Button(btnRect, _argBtnLabel))
                {
                    argArrayProp.arraySize = 1;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }
            }
            else
            {
                if (argArrayProp.arraySize > 1)
                {
                    argArrayProp.arraySize = 1;
                }
                var argProp = argArrayProp.GetArrayElementAtIndex(0);
                //EditorGUI.PropertyField(argRect, argProp, _defaultArgLabel);
                _variantDrawer.RestrictVariantType = false;
                _variantDrawer.ForcedObjectType    = null;
                _variantDrawer.OnGUI(argRect, argProp, _defaultArgLabel);

                if (GUI.Button(btnRect, _argBtnLabel))
                {
                    argArrayProp.arraySize = 0;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }
            }
        }
Exemplo n.º 16
0
        private void DrawVector3(Rect position, SerializedProperty property, GUIContent label)
        {
            position = EditorGUI.PrefixLabel(position, label);

            float btnw = Mathf.Min(position.width, BTN_WIDTH);
            var   rbtn = new Rect(position.xMax - btnw, position.yMin, btnw, EditorGUIUtility.singleLineHeight);

            var v = property.vector3Value;

            if (v == Vector3.zero)
            {
                v = Vector3.forward;
                property.vector3Value = Vector3.forward;
            }

            Vector3Directions i = Vector3Directions.Configure;

            if (v == Vector3.up)
            {
                i = Vector3Directions.Up;
            }
            else if (v == Vector3.down)
            {
                i = Vector3Directions.Down;
            }
            else if (v == Vector3.right)
            {
                i = Vector3Directions.Right;
            }
            else if (v == Vector3.left)
            {
                i = Vector3Directions.Left;
            }
            else if (v == Vector3.forward)
            {
                i = Vector3Directions.Forward;
            }
            else if (v == Vector3.back)
            {
                i = Vector3Directions.Backward;
            }
            else
            {
                i = Vector3Directions.Configure;
            }

            EditorGUI.BeginChangeCheck();
            i = (Vector3Directions)EditorGUI.EnumPopup(rbtn, i);
            if (EditorGUI.EndChangeCheck())
            {
                switch (i)
                {
                case Vector3Directions.Up:
                    property.vector3Value = Vector3.up;
                    break;

                case Vector3Directions.Down:
                    property.vector3Value = Vector3.down;
                    break;

                case Vector3Directions.Right:
                    property.vector3Value = Vector3.right;
                    break;

                case Vector3Directions.Left:
                    property.vector3Value = Vector3.left;
                    break;

                case Vector3Directions.Forward:
                    property.vector3Value = Vector3.forward;
                    break;

                case Vector3Directions.Backward:
                    property.vector3Value = Vector3.back;
                    break;
                }
            }

            if (i < Vector3Directions.Configure)
            {
                float w  = (position.width - btnw) / 3f;
                var   r1 = new Rect(position.xMin, position.yMin, w, EditorGUIUtility.singleLineHeight);
                var   r2 = new Rect(r1.xMax, position.yMin, w, EditorGUIUtility.singleLineHeight);
                var   r3 = new Rect(r2.xMax, position.yMin, w, EditorGUIUtility.singleLineHeight);

                EditorGUI.LabelField(r1, "X: " + v.x.ToString("0.#######"));
                EditorGUI.LabelField(r2, "Y: " + v.y.ToString("0.#######"));
                EditorGUI.LabelField(r3, "Z: " + v.z.ToString("0.#######"));
            }
            else
            {
                //TODO - need way to make this work effectively
                var r = new Rect(position.xMin, position.yMin, position.width - btnw, EditorGUIUtility.singleLineHeight);
                EditorGUI.BeginChangeCheck();
                v = SPEditorGUI.DelayedVector3Field(r, GUIContent.none, v);
                if (EditorGUI.EndChangeCheck())
                {
                    property.vector3Value = v.normalized;
                }
            }
        }
        public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
        {
            if (property.serializedObject.targetObject is i_PlayRandomAnimation)
            {
                this.DrawFlat = true;

                var controller = property.serializedObject.FindProperty(i_PlayRandomAnimationInspector.PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue;
                if (controller is Animation || controller is SPLegacyAnimController)
                {
                    float h = EditorGUIUtility.singleLineHeight * 6f;
                    var   propApplySetting = property.FindPropertyRelative(PROP_APPPLYSETTINGS);
                    if (propApplySetting.boolValue)
                    {
                        var propSettings = property.FindPropertyRelative(PROP_SETTINGS);
                        propSettings.isExpanded = true;
                        h += SPEditorGUI.GetPropertyHeight(propSettings, EditorHelper.TempContent(propSettings.displayName), true);
                    }
                    else
                    {
                        h += EditorGUIUtility.singleLineHeight;
                    }

                    return(h);
                }
                else if (controller is ISPAnimator)
                {
                    return(EditorGUIUtility.singleLineHeight * 2f);
                }
                else if (controller is ISPAnimationSource)
                {
                    float h = EditorGUIUtility.singleLineHeight * 5f;
                    if (!this.DrawFlat)
                    {
                        h += EditorGUIUtility.singleLineHeight;
                    }

                    var propApplySetting = property.FindPropertyRelative(PROP_APPPLYSETTINGS);
                    if (propApplySetting.boolValue)
                    {
                        var propSettings = property.FindPropertyRelative(PROP_SETTINGS);
                        propSettings.isExpanded = true;
                        h += SPEditorGUI.GetPropertyHeight(propSettings, EditorHelper.TempContent(propSettings.displayName), true);
                    }
                    else
                    {
                        h += EditorGUIUtility.singleLineHeight;
                    }

                    return(h);
                }
                else
                {
                    return(EditorGUIUtility.singleLineHeight);
                }
            }
            else
            {
                if (!this.DrawFlat && !property.isExpanded)
                {
                    return(EditorGUIUtility.singleLineHeight);
                }

                float h = EditorGUIUtility.singleLineHeight * 6f;
                if (!this.DrawFlat)
                {
                    h += EditorGUIUtility.singleLineHeight;
                }

                var propApplySetting = property.FindPropertyRelative(PROP_APPPLYSETTINGS);
                if (propApplySetting.boolValue)
                {
                    var propSettings = property.FindPropertyRelative(PROP_SETTINGS);
                    propSettings.isExpanded = true;
                    h += SPEditorGUI.GetPropertyHeight(propSettings, EditorHelper.TempContent(propSettings.displayName), true);
                }
                else
                {
                    h += EditorGUIUtility.singleLineHeight;
                }

                return(h);
            }
        }
Exemplo n.º 18
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);
            }
        }
        private void DrawGenerically(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!this.DrawFlat)
            {
                var rh = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                position = new Rect(position.xMin, rh.yMax, position.width, position.height - rh.height);

                property.isExpanded = EditorGUI.Foldout(rh, property.isExpanded, label);

                if (!property.isExpanded)
                {
                    return;
                }
            }

            var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMin, r0.yMax, r0.width, EditorGUIUtility.singleLineHeight);
            var r2 = new Rect(r1.xMin, r1.yMax, r1.width, EditorGUIUtility.singleLineHeight);
            var r3 = new Rect(r2.xMin, r2.yMax, r2.width, position.yMax - r2.yMax - EditorGUIUtility.singleLineHeight * 3f);
            var r4 = new Rect(r3.xMin, r3.yMax, r3.width, EditorGUIUtility.singleLineHeight);
            var r5 = new Rect(r4.xMin, r4.yMax, r4.width, EditorGUIUtility.singleLineHeight);
            var r6 = new Rect(r5.xMin, r5.yMax, r5.width, EditorGUIUtility.singleLineHeight);

            SPEditorGUI.PropertyField(r0, property.FindPropertyRelative(PROP_WEIGHT));

            var propMode = property.FindPropertyRelative(PROP_MODE);

            SPEditorGUI.PropertyField(r1, propMode);

            switch (propMode.GetEnumValue <i_PlayAnimation.PlayByMode>())
            {
            case i_PlayAnimation.PlayByMode.PlayAnim:
            {
                property.FindPropertyRelative(PROP_ID).stringValue = string.Empty;

                var clipProp = property.FindPropertyRelative(PROP_CLIP);
                var obj      = EditorGUI.ObjectField(r2, EditorHelper.TempContent(clipProp.displayName), clipProp.objectReferenceValue, typeof(UnityEngine.Object), true);
                if (obj == null || obj is AnimationClip || obj is IScriptableAnimationClip)
                {
                    clipProp.objectReferenceValue = obj;
                }
                else if (GameObjectUtil.IsGameObjectSource(obj))
                {
                    clipProp.objectReferenceValue = ObjUtil.GetAsFromSource <IScriptableAnimationClip>(obj) as UnityEngine.Object;
                }
            }
            break;

            case i_PlayAnimation.PlayByMode.PlayAnimByID:
            {
                property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null;

                SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID));
            }
            break;

            case i_PlayAnimation.PlayByMode.PlayAnimFromResource:
            {
                property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null;

                SPEditorGUI.PropertyField(r2, property.FindPropertyRelative(PROP_ID));
            }
            break;
            }

            this.DrawSettings(r3, property);
            SPEditorGUI.PropertyField(r4, property.FindPropertyRelative(PROP_QUEUEMODE));
            SPEditorGUI.PropertyField(r5, property.FindPropertyRelative(PROP_PLAYMODE));
            SPEditorGUI.PropertyField(r6, property.FindPropertyRelative(PROP_CROSSFADEDUR));
        }
Exemplo n.º 20
0
        public void OnGUI(Rect position, SerializedProperty property)
        {
            //if (property.propertyType != SerializedPropertyType.ObjectReference || !TypeUtil.IsType(_restrictionType, typeof(Component), typeof(IComponent)))
            if (property.propertyType != SerializedPropertyType.ObjectReference || (!this.AllowNonComponents && !(TypeUtil.IsType(_restrictionType, typeof(Component)) || _restrictionType.IsInterface)))
            {
                this.DrawAsMismatchedAttribute(position, property);
                return;
            }

            this.Init();

            GameObject targGo;

            if (this.ForceOnlySelf)
            {
                targGo = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (targGo == null)
                {
                    this.DrawAsMismatchedAttribute(position, property);
                    return;
                }

                if (property.objectReferenceValue == null)
                {
                    property.objectReferenceValue = targGo.GetComponent(_restrictionType);
                }
            }

            targGo = GameObjectUtil.GetGameObjectFromSource(property.objectReferenceValue);
            if (property.objectReferenceValue == null)
            {
                //SPEditorGUI.DefaultPropertyField(position, property, label);
                if (!this.ForceOnlySelf)
                {
                    this.DrawObjectRefField(position, property);
                }
                else
                {
                    EditorGUI.LabelField(position, "Malformed serializable field.");
                }
            }
            else if (this.AllowNonComponents)
            {
                if (targGo == null)
                {
                    this.DrawObjectRefField(position, property);
                }
                else
                {
                    this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType);
                    var components = this.ChoiceSelector.GetComponents();

                    var fullsize = position;
                    if (components.Length == 0 ||
                        (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide)))
                    {
                        property.objectReferenceValue = null;
                        fullsize = this.DrawDotDotButton(fullsize, property);
                        this.DrawObjectRefField(fullsize, property);

                        this.ChoiceSelector.GUIComplete(property, -1);
                    }
                    else
                    {
                        position = this.DrawDotDotButton(position, property);
                        var names = this.ChoiceSelector.GetPopupEntries();
                        System.Array.Resize(ref names, names.Length + 1);
                        names[names.Length - 1] = EditorHelper.TempContent(targGo.name + " (...GameObject)");

                        int oi = (property.objectReferenceValue is GameObject) ? names.Length - 1 : this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component);
                        int ni = EditorGUI.Popup(position, oi, names);

                        if (oi != ni)
                        {
                            if (ni == names.Length - 1)
                            {
                                property.objectReferenceValue = targGo;
                            }
                            else
                            {
                                property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                            }

                            //if (ni < components.Length)
                            //    property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                            //else
                            //    property.objectReferenceValue = targGo;
                        }

                        this.ChoiceSelector.GUIComplete(property, ni);
                    }
                }
            }
            else
            {
                this.ChoiceSelector.BeforeGUI(this, property, this.ComponentRestrictionType);
                var components = this.ChoiceSelector.GetComponents();

                var fullsize = position;
                if (components.Length == 0 ||
                    (this.ShowXButton && SPEditorGUI.XButton(ref position, "Clear Selected Object", this.XButtonOnRightSide)))
                {
                    property.objectReferenceValue = null;
                    fullsize = this.DrawDotDotButton(fullsize, property);
                    this.DrawObjectRefField(fullsize, property);

                    this.ChoiceSelector.GUIComplete(property, -1);
                }
                else
                {
                    position = this.DrawDotDotButton(position, property);
                    var names = this.ChoiceSelector.GetPopupEntries();
                    int oi    = this.ChoiceSelector.GetPopupIndexOfComponent(property.objectReferenceValue as Component);
                    int ni    = EditorGUI.Popup(position, oi, names);
                    if (oi != ni)
                    {
                        property.objectReferenceValue = this.ChoiceSelector.GetComponentAtPopupIndex(ni);
                    }

                    this.ChoiceSelector.GUIComplete(property, ni);
                }
            }
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (!this.ValidateFieldType())
            {
                EditorGUI.PropertyField(position, property, label);
                return;
            }

            EditorGUI.BeginProperty(position, label, property);

            //get base type
            var attrib = this.attribute as TypeRestrictionAttribute;

            bool isArray              = this.fieldInfo.FieldType.IsListType();
            var  fieldType            = (isArray) ? this.fieldInfo.FieldType.GetElementTypeOfListType() : this.fieldInfo.FieldType;
            bool fieldIsComponentType = TypeUtil.IsType(fieldType, typeof(Component));
            bool objIsComponentType   = property.objectReferenceValue is Component;
            var  inheritsFromType     = attrib.InheritsFromType ?? ((fieldIsComponentType) ? typeof(Component) : fieldType);

            if (attrib.HideTypeDropDown || !objIsComponentType)
            {
                //draw object field
                if (fieldIsComponentType)
                {
                    var fieldCompType = (TypeUtil.IsType(fieldType, typeof(Component))) ? fieldType : typeof(Component);
                    var comp          = SPEditorGUI.ComponentField(position, label, property.objectReferenceValue as Component, inheritsFromType, true, fieldCompType);
                    if (comp == null)
                    {
                        property.objectReferenceValue = null;
                    }
                    else
                    {
                        property.objectReferenceValue = ObjUtil.GetAsFromSource(inheritsFromType, comp) as UnityEngine.Object;
                    }
                    //else if (TypeUtil.IsType(comp.GetType(), inheritsFromType))
                    //    property.objectReferenceValue = comp;
                    //else
                    //    property.objectReferenceValue = comp.GetComponent(inheritsFromType);
                }
                else
                {
                    var obj = EditorGUI.ObjectField(position, label, property.objectReferenceValue, fieldType, true);
                    if (obj == null)
                    {
                        property.objectReferenceValue = null;
                    }
                    else
                    {
                        property.objectReferenceValue = ObjUtil.GetAsFromSource(inheritsFromType, obj) as UnityEngine.Object;
                    }
                }
            }
            else
            {
                //draw complex field
                if (_selectComponentDrawer == null)
                {
                    _selectComponentDrawer = new SelectableComponentPropertyDrawer();
                }

                _selectComponentDrawer.RestrictionType = inheritsFromType ?? typeof(Component);
                _selectComponentDrawer.ShowXButton     = true;

                _selectComponentDrawer.OnGUI(position, property, label);
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 22
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            this.Init(property);

            EditorGUI.BeginProperty(position, label, property);

            //################################
            //FIRST LINE
            var rect = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

            rect = EditorGUI.PrefixLabel(rect, label);

            var targetProp = property.FindPropertyRelative(PROP_TARGET);

            var w0 = Mathf.Min(rect.width * 0.3f, 80f);
            var w1 = rect.width - w0;
            var r0 = new Rect(rect.xMin, rect.yMin, w0, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(r0.xMax, rect.yMin, w1, EditorGUIUtility.singleLineHeight);

            var searchProp = property.FindPropertyRelative(PROP_SEARCHBY);
            var queryProp  = property.FindPropertyRelative(PROP_QUERY);

            var eSearchBy = (SearchByAlt)searchProp.GetEnumValue <SearchBy>();

            EditorGUI.BeginChangeCheck();
            eSearchBy = (SearchByAlt)EditorGUI.EnumPopup(r0, eSearchBy);
            if (EditorGUI.EndChangeCheck())
            {
                searchProp.SetEnumValue((SearchBy)eSearchBy);
            }

            switch (eSearchBy)
            {
            case SearchByAlt.Direct:
            {
                //SPEditorGUI.PropertyField(r1, targetProp, GUIContent.none);
                if (_selectableDrawer == null)
                {
                    _selectableDrawer = new SelectableComponentPropertyDrawer();
                }
                _selectableDrawer.AllowSceneObjects = true;
                _selectableDrawer.RestrictionType   = _inheritsFromType;
                _selectableDrawer.AllowProxy        = _allowProxy;
                _selectableDrawer.OnGUI(r1, targetProp, GUIContent.none);
            }
            break;

            case SearchByAlt.Tag:
            {
                queryProp.stringValue           = EditorGUI.TagField(r1, queryProp.stringValue);
                targetProp.objectReferenceValue = null;
            }
            break;

            case SearchByAlt.Name:
            {
                queryProp.stringValue           = EditorGUI.TextField(r1, queryProp.stringValue);
                targetProp.objectReferenceValue = null;
            }
            break;

            case SearchByAlt.Type:
            {
                var tp = TypeUtil.FindType(queryProp.stringValue);
                if (!TypeUtil.IsType(tp, typeof(UnityEngine.Object)))
                {
                    tp = null;
                }
                tp = SPEditorGUI.TypeDropDown(r1, GUIContent.none, typeof(UnityEngine.Object), tp);
                queryProp.stringValue           = (tp != null) ? tp.FullName : null;
                targetProp.objectReferenceValue = null;
            }
            break;
            }

            EditorGUI.EndProperty();
        }
Exemplo n.º 23
0
        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;

            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,
                                                                           TriggerTargetPropertyDrawer.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        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, trigLabel, extraLabel);
                }
                else
                {
                    EditorGUI.LabelField(trigRect, trigLabel, new GUIContent("No Target"), new GUIStyle("Label")
                    {
                        alignment = TextAnchor.MiddleCenter
                    });
                }
            }

            ReorderableListHelper.DrawDraggableElementDeleteContextMenu(_targetList, area, index, isActive, isFocused);
        }
Exemplo n.º 24
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 DrawAdvanced_CallMethodOnSelected(Rect area, SerializedProperty property)
        {
            //Draw Target
            var targRect  = new Rect(area.xMin, area.yMin, area.width, EditorGUIUtility.singleLineHeight);
            var targProp  = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLETARG);
            var targLabel = new GUIContent("Triggerable Target");
            var targGo    = GameObjectUtil.GetGameObjectFromSource(targProp.objectReferenceValue);
            var newTargGo = EditorGUI.ObjectField(targRect, targLabel, targGo, typeof(GameObject), true) as GameObject;

            if (newTargGo != targGo)
            {
                targGo = newTargGo;
                targProp.objectReferenceValue = (targGo != null) ? targGo.transform : null;
            }

            var targCompPopupRect = new Rect(area.xMin, targRect.yMax, area.width, EditorGUIUtility.singleLineHeight);

            if (targGo != null)
            {
                EditorGUI.BeginChangeCheck();
                var selectedComp = SPEditorGUI.SelectComponentFromSourceField(targCompPopupRect, "Target Component", targGo, targProp.objectReferenceValue as Component);
                if (EditorGUI.EndChangeCheck())
                {
                    targProp.objectReferenceValue = selectedComp;
                }
            }
            else
            {
                EditorGUI.LabelField(targCompPopupRect, "Target Component", "(First Select a Target)");
            }

            //Draw Method Name
            var methNameRect = new Rect(area.xMin, targCompPopupRect.yMax, area.width, EditorGUIUtility.singleLineHeight);

            System.Reflection.MemberInfo selectedMember = null;
            if (targProp.objectReferenceValue != null)
            {
                var methProp = property.FindPropertyRelative(TriggerTargetProps.PROP_METHODNAME);

                //var tp = targProp.objectReferenceValue.GetType();
                //var members = GetAvailableMethods(tp).ToArray();

                //var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.Method).ToArray();
                var members = com.spacepuppy.Dynamic.DynamicUtil.GetEasilySerializedMembers(targProp.objectReferenceValue, System.Reflection.MemberTypes.All, spacepuppy.Dynamic.DynamicMemberAccess.Write).ToArray();
                System.Array.Sort(members, (a, b) => string.Compare(a.Name, b.Name, true));
                var memberNames = members.Select((m) => m.Name).ToArray();

                int index = System.Array.IndexOf(memberNames, methProp.stringValue);
                index = EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), index, (from n in memberNames select new GUIContent(n)).ToArray());
                methProp.stringValue = (index >= 0) ? memberNames[index] : null;
                selectedMember       = (index >= 0) ? members[index] : null;
            }
            else
            {
                EditorGUI.Popup(methNameRect, new GUIContent("Method", "The method/prop on the target to call."), -1, new GUIContent[0]);
            }

            property.serializedObject.ApplyModifiedProperties();

            //Draw Triggerable Arg
            var parr = (selectedMember != null) ? com.spacepuppy.Dynamic.DynamicUtil.GetDynamicParameterInfo(selectedMember) : null;

            if (parr == null || parr.Length == 0)
            {
                //NO PARAMETERS
                _callMethodModeExtraLines = 1;

                var argRect      = new Rect(area.xMin, methNameRect.yMax, area.width, EditorGUIUtility.singleLineHeight);
                var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS);
                if (argArrayProp.arraySize > 0)
                {
                    argArrayProp.arraySize = 0;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }

                var cache = SPGUI.Disable();
                EditorGUI.LabelField(argRect, GUIContent.none, new GUIContent("*Zero Parameter Count*"));
                cache.Reset();
            }
            else
            {
                //MULTIPLE PARAMETERS - special case, does not support trigger event arg
                _callMethodModeExtraLines = parr.Length;

                var argArrayProp = property.FindPropertyRelative(TriggerTargetProps.PROP_TRIGGERABLEARGS);

                if (argArrayProp.arraySize != parr.Length)
                {
                    argArrayProp.arraySize = parr.Length;
                    argArrayProp.serializedObject.ApplyModifiedProperties();
                }

                EditorGUI.indentLevel++;
                for (int i = 0; i < parr.Length; i++)
                {
                    var paramType = parr[i].ParameterType;
                    var argRect   = new Rect(area.xMin, methNameRect.yMax + i * EditorGUIUtility.singleLineHeight, area.width, EditorGUIUtility.singleLineHeight);
                    var argProp   = argArrayProp.GetArrayElementAtIndex(i);

                    if (paramType == typeof(object))
                    {
                        //draw the default variant as the method accepts anything
                        _variantDrawer.RestrictVariantType = false;
                        _variantDrawer.ForcedObjectType    = null;
                        _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed."));
                    }
                    else
                    {
                        var argType = VariantReference.GetVariantType(paramType);
                        _variantDrawer.RestrictVariantType     = true;
                        _variantDrawer.VariantTypeRestrictedTo = argType;
                        _variantDrawer.ForcedObjectType        = (paramType.IsInterface || TypeUtil.IsType(paramType, typeof(Component))) ? paramType : null;
                        _variantDrawer.OnGUI(argRect, argProp, EditorHelper.TempContent("Arg " + i.ToString() + ": " + parr[i].ParameterName, "A parameter to be passed to the method if needed."));
                    }
                }
                EditorGUI.indentLevel--;
            }
        }
Exemplo n.º 26
0
        public void DrawDetails(Rect position, SerializedProperty property)
        {
            var cache = SPGUI.DisableIfPlaying();

            //draw basic details
            var yMin = position.yMin;

            for (int i = 0; i < _detailProps.Length; i++)
            {
                //var r = new Rect(position.xMin, yMin + i * EditorGUIUtility.singleLineHeight, position.width, EditorGUIUtility.singleLineHeight);
                switch (_detailProps[i])
                {
                case SPAnimClip.PROP_WRAPMODE:
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    var wrapModeProp = property.FindPropertyRelative(SPAnimClip.PROP_WRAPMODE);
                    wrapModeProp.SetEnumValue(SPEditorGUI.WrapModeField(r, wrapModeProp.displayName, wrapModeProp.GetEnumValue <WrapMode>(), true));
                }
                break;

                case "ScaledDuration":
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    var label = EditorHelper.TempContent("Scaled Duration", "The duration of the clip with the speed applied. Modifying this alters the 'speed' property.");
                    var clip  = property.FindPropertyRelative(PROP_CLIP).objectReferenceValue as AnimationClip;
                    if (clip == null)
                    {
                        EditorGUI.FloatField(r, label, 0f);
                        continue;
                    }

                    var   speedProp = property.FindPropertyRelative(SPAnimClip.PROP_SPEED);
                    float dur       = (speedProp.floatValue == 0f) ? float.PositiveInfinity : Mathf.Abs(clip.length / speedProp.floatValue);
                    EditorGUI.BeginChangeCheck();

                    dur = EditorGUI.FloatField(r, label, dur);

                    if (EditorGUI.EndChangeCheck())
                    {
                        speedProp.floatValue = (dur <= 0f) ? 0f : clip.length / dur;
                    }
                }
                break;

                default:
                {
                    var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                    position = new Rect(position.xMin, r.yMax, position.width, Mathf.Max(position.height - r.height, 0f));

                    EditorGUI.PropertyField(r, property.FindPropertyRelative(_detailProps[i]));
                }
                break;
                }
            }

            cache.Reset();
        }
Exemplo n.º 27
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.propertyType != SerializedPropertyType.String)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            var tr = GameObjectUtil.GetTransformFromSource(property.serializedObject.targetObject);

            if (tr == null)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            IAIController controller = tr.GetComponent <IAIController>();

            while (controller == null && tr.parent != null)
            {
                tr         = tr.parent;
                controller = tr.GetComponent <IAIController>();
            }
            if (controller == null)
            {
                SPEditorGUI.DefaultPropertyField(position, property, label);
                return;
            }

            var names    = (controller.Variables == null) ? new string[] {} : controller.Variables.Names.ToArray();
            var guiNames = (from n in names select EditorHelper.TempContent(n)).Append(EditorHelper.TempContent("Custom...")).ToArray();
            int index    = names.IndexOf(property.stringValue);

            if (index < 0)
            {
                index = names.Length;
            }
            if (index == names.Length)
            {
                var fw = position.width - EditorGUIUtility.labelWidth;
                var wl = EditorGUIUtility.labelWidth + (fw / 4f);
                var wr = position.width - wl - 1f;

                var rl = new Rect(position.xMin, position.yMin, wl, EditorGUIUtility.singleLineHeight);
                var rr = new Rect(rl.xMax + 1f, rl.yMin, wr, EditorGUIUtility.singleLineHeight);

                index = EditorGUI.Popup(rl, label, index, guiNames);
                if (index >= 0 && index < names.Length)
                {
                    property.stringValue = names[index];
                }
                else
                {
                    property.stringValue = EditorGUI.TextField(rr, property.stringValue);
                }
            }
            else
            {
                index = EditorGUI.Popup(position, label, index, guiNames);
                property.stringValue = (index >= 0 && index < names.Length) ? names[index] : null;
            }
        }