Exemplo n.º 1
0
        public bool OnGUI(Rect position, SerializedProperty property, GUIContent label, bool includeChildren)
        {
            if (label == null)
            {
                label = EditorHelper.TempContent(property.displayName);
            }

            if (!includeChildren || !property.hasVisibleChildren)
            {
                return(ScriptAttributeUtility.SharedNullInternalPropertyHandler.OnGUI(position, property, label, includeChildren));
                //return EditorGUI.PropertyField(position, property, label, includeChildren);
            }

            float h;
            Rect  r;

            EditorGUI.BeginChangeCheck();

            //draw header
            h                   = EditorGUIUtility.singleLineHeight;
            r                   = new Rect(position.xMin, position.yMin, position.width, h);
            position            = new Rect(r.xMin, r.yMax, r.width, position.height - h);
            property.isExpanded = EditorGUI.Foldout(r, property.isExpanded, label);

            //draw children
            if (property.isExpanded)
            {
                var iterator = property.Copy();
                var end      = property.GetEndProperty();
                for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false)
                {
                    if (SerializedProperty.EqualContents(iterator, end))
                    {
                        break;
                    }

                    h        = SPEditorGUI.GetPropertyHeight(iterator);
                    r        = new Rect(position.xMin, position.yMin, position.width, h);
                    position = new Rect(r.xMin, r.yMax, r.width, position.height - h);

                    SPEditorGUI.PropertyField(r, iterator, EditorHelper.TempContent(iterator.displayName), iterator.hasVisibleChildren);
                }
            }

            return(EditorGUI.EndChangeCheck());
        }
        protected virtual void DrawElement(Rect area, SerializedProperty element, GUIContent label, int elementIndex)
        {
            if (_drawElementAtBottom)
            {
                SerializedProperty prop = string.IsNullOrEmpty(_childPropertyAsEntry) ? null : element.FindPropertyRelative(_childPropertyAsEntry);

                if (prop != null)
                {
                    SPEditorGUI.PropertyField(area, prop, label);
                }
                else
                {
                    EditorGUI.LabelField(area, label);
                }
            }
            else
            {
                if (_internalDrawer != null)
                {
                    _internalDrawer.OnGUI(area, element, label);
                }
                else if (ElementIsFlatChildField(element))
                {
                    //we don't draw this way if it's a built-in type from Unity

                    if (_hideElementLabel)
                    {
                        //no label
                        SPEditorGUI.FlatChildPropertyField(area, element);
                    }
                    else
                    {
                        //showing label
                        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
                {
                    area = EditorGUI.PrefixLabel(area, label);
                    SPEditorGUI.DefaultPropertyField(area, element, label, false);
                }
            }
        }
Exemplo n.º 3
0
        public static System.Reflection.MemberInfo DrawMemberProxy(Rect position, SerializedProperty property, GUIContent label, DynamicMemberAccess memberAccessLevel = DynamicMemberAccess.Read)
        {
            var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
            var r1 = new Rect(position.xMin, r0.yMax, position.width, EditorGUIUtility.singleLineHeight);

            var targProp   = property.FindPropertyRelative("_target");
            var memberProp = property.FindPropertyRelative("_memberName");

            SPEditorGUI.PropertyField(r0, targProp, label);
            System.Reflection.MemberInfo selectedMember;
            memberProp.stringValue = SPEditorGUI.ReflectedPropertyField(r1,
                                                                        EditorHelper.TempContent(" - Property", "The property on the target to set."),
                                                                        targProp.objectReferenceValue,
                                                                        memberProp.stringValue,
                                                                        memberAccessLevel,
                                                                        out selectedMember);
            return(selectedMember);
        }
        private void DrawForPlayRandomAnimation(Rect position, SerializedProperty property, GUIContent label)
        {
            var controller = property.serializedObject.FindProperty(i_PlayRandomAnimationInspector.PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue;

            if (controller is Animation || controller is SPLegacyAnimController)
            {
                this.DrawFlat = true;
                this.DrawGenerically(position, property, label);
            }
            else if (controller is ISPAnimator)
            {
                var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);
                var r1 = new Rect(r0.xMin, r0.yMax, r0.width, EditorGUIUtility.singleLineHeight);

                SPEditorGUI.PropertyField(r0, property.FindPropertyRelative(PROP_WEIGHT));
                var propId = property.FindPropertyRelative(PROP_ID);
                propId.stringValue = i_PlayAnimationInspector.DrawSPAnimatorFunctionPopup(r1, controller as ISPAnimator, propId.stringValue);
            }
            else if (controller is ISPAnimationSource)
            {
                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 r3 = new Rect(r1.xMin, r1.yMax, r1.width, position.yMax - r1.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));
                property.FindPropertyRelative(PROP_CLIP).objectReferenceValue = null;
                SPEditorGUI.PropertyField(r1, property.FindPropertyRelative(PROP_ID));

                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));
            }
            else
            {
                EditorGUI.LabelField(position, "Attach a target animator before configuring animations.");
            }
        }
            protected override void DrawElementValue(Rect area, SerializedProperty element, GUIContent label, int elementIndex)
            {
                var controller = element.serializedObject.FindProperty(PROP_TARGETANIMATOR).FindPropertyRelative(TriggerableTargetObjectPropertyDrawer.PROP_TARGET).objectReferenceValue;

                if (controller is Animation || controller is SPLegacyAnimController)
                {
                    var modeProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_MODE);
                    switch (modeProp.GetEnumValue <i_PlayAnimation.PlayByMode>())
                    {
                    case i_PlayAnimation.PlayByMode.PlayAnim:
                    {
                        var clipProp = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_CLIP);
                        var obj      = EditorGUI.ObjectField(area, GUIContent.none, 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;

                    default:
                    {
                        SPEditorGUI.PropertyField(area, element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID), GUIContent.none);
                    }
                    break;
                    }
                }
                else if (controller is ISPAnimator)
                {
                    var propId = element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID);
                    propId.stringValue = i_PlayAnimationInspector.DrawSPAnimatorFunctionPopup(area, GUIContent.none, controller as ISPAnimator, propId.stringValue);
                }
                else if (controller is ISPAnimationSource)
                {
                    SPEditorGUI.PropertyField(area, element.FindPropertyRelative(PlayAnimInfoPropertyDrawer.PROP_ID), GUIContent.none);
                }
            }
Exemplo n.º 6
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var signalSourceProp = property.FindPropertyRelative("_signalSource");

            SPEditorGUI.PropertyField(position, signalSourceProp, label);

            if (signalSourceProp.objectReferenceValue == null)
            {
                var go = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
                if (go != null && (go.HasComponent <Rigidbody>() || go.HasComponent <Collider>()))
                {
                    signalSourceProp.objectReferenceValue = go;
                }
                else
                {
                    var root = go.FindTrueRoot();
                    if (root != null && (root.HasComponent <Rigidbody>() || root.HasComponent <Collider>()))
                    {
                        signalSourceProp.objectReferenceValue = root;
                    }
                }
            }
        }
Exemplo n.º 7
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (property.serializedObject.isEditingMultipleObjects)
            {
                return;
            }

            var lifeCycleProp = property.FindPropertyRelative("_lifeCycle");

            if (_message != null)
            {
                var r = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight * 2f);
                EditorGUI.HelpBox(r, _message, _messageType);

                r = new Rect(r.xMin, r.yMax, r.width, EditorGUIUtility.singleLineHeight);
                var b = lifeCycleProp.GetEnumValue <SingletonLifeCycleRule>().HasFlag(SingletonLifeCycleRule.AlwaysReplace);
                b = EditorGUI.Toggle(r, "Always Replace", b);
                lifeCycleProp.SetEnumValue((b) ? SingletonLifeCycleRule.AlwaysReplace : SingletonLifeCycleRule.LivesForDurationOfScene);
            }
            else
            {
                SPEditorGUI.PropertyField(position, lifeCycleProp);
            }
        }
        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;
                }
            }
        }
Exemplo n.º 9
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.º 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;
                }
            }
        }