コード例 #1
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);



            var cache = SPGUI.DisableIfPlaying();

            this.DrawPropertyField(PROP_NOTIFTYPE);

            var useGlobalProp = this.serializedObject.FindProperty(PROP_USEGLOBAL);
            var targetProp    = this.serializedObject.FindProperty(PROP_TARGET);

            SPEditorGUILayout.PropertyField(useGlobalProp);
            if (useGlobalProp.boolValue)
            {
                targetProp.objectReferenceValue = null;
            }
            else
            {
                SPEditorGUILayout.PropertyField(targetProp);
            }

            cache.Reset();



            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_NOTIFTYPE, PROP_USEGLOBAL, PROP_TARGET);

            this.serializedObject.ApplyModifiedProperties();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            var cache = SPGUI.DisableIfPlaying();

            /*
             * Component[] states = null;
             * var src = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);
             * if (src != null) states = ParentComponentStateSupplier<IAIState>.GetComponentsOnTarg(src, false).Cast<Component>().ToArray();
             * else states = new Component[] { };
             *
             * var componentLabels = (from c in states select EditorHelper.TempContent(string.Format("{0} ({1})", c.name, c.GetType().Name))).ToArray();
             * property.objectReferenceValue = SPEditorGUI.SelectComponentField(position, label, states, componentLabels, property.objectReferenceValue as Component);
             *
             * cache.Reset();
             */

            Component[] states = null;
            var         src    = GameObjectUtil.GetGameObjectFromSource(property.serializedObject.targetObject);

            if (src != null)
            {
                states = ParentComponentStateSupplier <IAIState> .GetComponentsOnTarg(src, false).Cast <Component>().Prepend(null).ToArray();
            }
            else
            {
                states = new Component[] { }
            };

            var componentLabels = (from c in states select(c != null) ? EditorHelper.TempContent(string.Format("{0} ({1})", c.name, c.GetType().Name)) : EditorHelper.TempContent("...Nothing")).ToArray();

            property.objectReferenceValue = SPEditorGUI.SelectComponentField(position, label, states, componentLabels, property.objectReferenceValue as Component);

            cache.Reset();
        }
    }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            this.Init(property, label);

            var cache = SPGUI.DisableIfPlaying();

            _maskList.DoList(position);

            cache.Reset();
        }
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (EditorHelper.AssertMultiObjectEditingNotSupported(position, property, label))
            {
                return;
            }

            var cache = SPGUI.DisableIfPlaying();

            _property = property;

            GUI.Box(position, GUIContent.none);

            var r0 = new Rect(position.xMin, position.yMin, position.width, EditorGUIUtility.singleLineHeight);

            _matPropRefDrawer.OnGUI(r0, property, label); //because we mirror the properties of MaterialPropertyReference, this works
            position = new Rect(position.xMin, r0.yMax, position.width, position.height - r0.height);

            EditorGUI.indentLevel++;

            _valuesProp = property.FindPropertyRelative(PROP_VALUES);
            var lst = CachedReorderableList.GetListDrawer(_valuesProp, _valuesList_DrawHeader, _valuesList_DrawElement);

            lst.headerHeight  = 0f;
            lst.elementHeight = EditorGUIUtility.singleLineHeight;

            var r2 = new Rect(position.xMin, position.yMin, position.width, lst.GetHeight());
            var r3 = new Rect(position.xMin, position.yMax - EditorGUIUtility.singleLineHeight * 1.25f, position.width, EditorGUIUtility.singleLineHeight);

            //lst.DoList(EditorGUI.IndentedRect(r2));
            lst.DoList(r2);
            EditorGUI.PropertyField(r3, property.FindPropertyRelative(PROP_POSITION));

            EditorGUI.indentLevel--;

            _property   = null;
            _valuesProp = null;

            cache.Reset();
        }
コード例 #5
0
        protected override void OnSPInspectorGUI()
        {
            this.serializedObject.Update();

            var targ = this.target as AIController;

            if (targ == null)
            {
                return;
            }

            this.DrawPropertyField(EditorHelper.PROP_SCRIPT);

            var sourceProp = this.serializedObject.FindProperty(PROP_STATESOURCE);

            SPEditorGUILayout.PropertyField(sourceProp);

            var cache     = SPGUI.DisableIfPlaying();
            var stateProp = this.serializedObject.FindProperty(PROP_DEFAULTSTATE);

            switch (sourceProp.GetEnumValue <AIStateMachineSourceMode>())
            {
            case AIStateMachineSourceMode.SelfSourced:
            {
                var states = ComponentStateSupplier <IAIState> .GetComponentsOnTarg(targ.gameObject).Cast <Component>().ToArray();

                stateProp.objectReferenceValue = SPEditorGUILayout.SelectComponentField(stateProp.displayName, states, stateProp.objectReferenceValue as Component);
            }
            break;

            case AIStateMachineSourceMode.ChildSourced:
            {
                var states = ParentComponentStateSupplier <IAIState> .GetComponentsOnTarg(targ.gameObject, false);

                var names = (from s in states select EditorHelper.TempContent(GameObjectUtil.GetGameObjectFromSource(s).name + " (" + s.GetType().Name + ")")).ToArray();
                int i     = states.IndexOf(stateProp.objectReferenceValue);
                i = EditorGUILayout.Popup(EditorHelper.TempContent(stateProp.displayName), i, names);
                stateProp.objectReferenceValue = (i >= 0) ? states[i] as UnityEngine.Object : null;
            }
            break;

            default:
            {
                var states = ArrayUtil.Empty <Component>();
                stateProp.objectReferenceValue = SPEditorGUILayout.SelectComponentField(stateProp.displayName, states, stateProp.objectReferenceValue as Component);
            }
            break;
            }

            cache.Reset();


            this.DrawDefaultInspectorExcept(EditorHelper.PROP_SCRIPT, PROP_STATESOURCE, PROP_DEFAULTSTATE);

            this.serializedObject.ApplyModifiedProperties();


            if (Application.isPlaying)
            {
                if (targ.States != null && targ.States.Current != null)
                {
                    var c   = targ.States.Current;
                    var msg = string.Format("Currently active state is {0} ({1}).", c.DisplayName, c.GetType().Name);
                    EditorGUILayout.HelpBox(msg, MessageType.Info);
                }
                else
                {
                    EditorGUILayout.HelpBox("Currently active state is null.", MessageType.Info);
                }
            }
        }
コード例 #6
0
        public static Rect DrawTimeSupplier(Rect position, SerializedProperty property, float desiredWidth, string[] availableNames)
        {
            if (position.width <= 0f)
            {
                return(position);
            }

            var r = new Rect(position.xMin, position.yMin, Mathf.Min(position.width, desiredWidth), position.height);

            var tsTypeProp = property.FindPropertyRelative(PROP_TIMESUPPLIERTYPE);
            var tsNameProp = property.FindPropertyRelative(PROP_TIMESUPPLIERNAME);

            int index = -1;

            using (var lst = TempCollection.GetList <string>())
            {
                lst.Add("Normal");
                lst.Add("Real");
                lst.Add("Smooth");

                foreach (var nm in CustomTimeLayersData.Layers)
                {
                    if (!lst.Contains(nm))
                    {
                        lst.Add(nm);
                    }
                }

                if (availableNames != null)
                {
                    foreach (var nm in availableNames)
                    {
                        if (!lst.Contains(nm))
                        {
                            lst.Add(nm);
                        }
                    }
                }

                var e = tsTypeProp.GetEnumValue <DeltaTimeType>();
                if (e == DeltaTimeType.Custom)
                {
                    index = lst.IndexOf(tsNameProp.stringValue);
                    if (index < 0)
                    {
                        tsTypeProp.SetEnumValue(DeltaTimeType.Normal);
                        tsNameProp.stringValue = null;
                        index = 0;
                    }
                }
                else
                {
                    index = (int)e;
                }

                var cache = SPGUI.DisableIfPlaying();
                EditorGUI.BeginChangeCheck();
                index = Mathf.Max(EditorGUI.Popup(position, index, lst.ToArray()), 0);
                if (EditorGUI.EndChangeCheck())
                {
                    if (index < 3)
                    {
                        tsTypeProp.SetEnumValue((DeltaTimeType)index);
                        tsNameProp.stringValue = null;
                    }
                    else
                    {
                        tsTypeProp.SetEnumValue(DeltaTimeType.Custom);
                        tsNameProp.stringValue = lst[index];
                    }
                }
                cache.Reset();
            }

            return(new Rect(r.xMax, position.yMin, Mathf.Max(position.width - r.width, 0f), position.height));
        }
コード例 #7
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();
        }
コード例 #8
0
        public void DrawClip(Rect area, SerializedProperty property, GUIContent label, float labelWidth, GUIStyle labelStyle, bool nameIsReadonly)
        {
            //Draw Name
            var nameProp = property.FindPropertyRelative(PROP_NAME);

            var labelRect = new Rect(area.xMin, area.yMin, labelWidth, EditorGUIUtility.singleLineHeight);
            var textRect  = new Rect(labelRect.xMax, area.yMin, (area.width - labelWidth) * 0.4f, EditorGUIUtility.singleLineHeight);

            EditorGUI.BeginProperty(area, label, nameProp);
            //EditorGUI.LabelField(labelRect, label, labelStyle);
            GUI.Label(labelRect, label, labelStyle);
            if (nameIsReadonly || _nameIsReadOnly || Application.isPlaying)
            {
                //EditorGUI.LabelField(textRect, nameProp.stringValue, GUI.skin.textField);
                GUI.Label(textRect, nameProp.stringValue, GUI.skin.textField);
            }
            else
            {
                //nameProp.stringValue = EditorGUI.TextField(textRect, nameProp.stringValue);
                nameProp.stringValue = GUI.TextField(textRect, nameProp.stringValue);
            }
            //EditorGUI.EndProperty();

            var cache = SPGUI.DisableIfPlaying();

            //Draw Animation Clip Reference
            var clipProp  = property.FindPropertyRelative(PROP_CLIP);
            var xmin      = textRect.xMax + 2f;
            var clipRect  = new Rect(xmin, area.yMin, area.xMax - xmin, EditorGUIUtility.singleLineHeight);
            var clipLabel = GUIContent.none;
            //EditorGUI.BeginProperty(clipRect, clipLabel, clipProp);
            //clipProp.objectReferenceValue = EditorGUI.ObjectField(clipRect, clipProp.objectReferenceValue, typeof(AnimationClip), false);
            var obj = clipProp.objectReferenceValue;

            if (GameObjectUtil.IsGameObjectSource(obj))
            {
                if (_selectComponentDrawer == null)
                {
                    _selectComponentDrawer = new SelectableComponentPropertyDrawer();
                    _selectComponentDrawer.RestrictionType = typeof(IScriptableAnimationClip);
                    _selectComponentDrawer.ShowXButton     = true;
                }
                _selectComponentDrawer.OnGUI(clipRect, clipProp, GUIContent.none);
            }
            else
            {
                obj = EditorGUI.ObjectField(clipRect, obj, 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;
                }
            }
            EditorGUI.EndProperty();

            cache.Reset();



            if (Application.isPlaying && !property.hasMultipleDifferentValues && property.serializedObject.targetObject is SPLegacyAnimController)
            {
                if (GUI.Button(new Rect(area.xMin, area.yMin, 20f, EditorGUIUtility.singleLineHeight), ">"))
                {
                    var targ = property.serializedObject.targetObject as SPLegacyAnimController;
                    targ.Play(nameProp.stringValue);
                }
            }
        }