Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            var dat = (InputAction)this.target;

            bool isDirty = false;

            //Axis Settings
            GUILayout.BeginVertical();

            GUILayout.Label("Axis Settings");

            var newDeadZone = EditorGUILayout.FloatField("Deadzone", dat.deadZone);

            if (newDeadZone != dat.deadZone)
            {
                Undo.RecordObject(dat, "Input Action Change Deadzone");
                dat.deadZone = newDeadZone;
                isDirty      = true;
            }

            var newForceRaw = EditorGUILayout.Toggle("Force Raw", dat.forceRaw);

            if (newForceRaw != dat.forceRaw)
            {
                Undo.RecordObject(dat, "Input Action Change Force Raw");
                dat.forceRaw = newForceRaw;
                isDirty      = true;
            }

            GUILayout.EndVertical();
            //

            EditorExt.Utility.DrawSeparator();

            //Binds

            GUILayout.BeginVertical();

            GUILayout.Label("Binds");

            int deleteIndex = -1, dupIndex = -1;

            for (int i = 0; i < dat.defaultBinds.Length; i++)
            {
                var bind = dat.defaultBinds[i];
                if (bind == null)
                {
                    continue;
                }

                GUILayout.BeginVertical(GUI.skin.box);

                //header
                GUILayout.BeginHorizontal();
                GUILayout.Label("Bind " + i);
                GUILayout.FlexibleSpace();
                if (EditorExt.Utility.DrawRemoveButton())
                {
                    deleteIndex = i;
                }
                if (EditorExt.Utility.DrawSimpleButton("D", "Duplicate"))
                {
                    dupIndex = i;
                }
                GUILayout.EndHorizontal();
                //

                //settings
                EditorGUI.BeginChangeCheck();

                //code
                GUILayout.BeginHorizontal();

                KeyType curKeyType;
                if (!string.IsNullOrEmpty(bind.input))
                {
                    curKeyType = KeyType.Input;
                }
                else
                {
                    curKeyType = KeyType.KeyCode;
                }

                var newKeyType = (KeyType)EditorGUILayout.EnumPopup(curKeyType, GUILayout.Width(80f));
                if (curKeyType != newKeyType)
                {
                    //changed, reset based on type
                    curKeyType = newKeyType;
                    switch (curKeyType)
                    {
                    case KeyType.Input:
                        bind.SetAsInput(mInputAxesDisplay.FirstAxisName());
                        break;

                    case KeyType.KeyCode:
                        bind.SetAsKey(0);
                        break;
                    }
                }

                switch (curKeyType)
                {
                case KeyType.Input:
                    bind.input = mInputAxesDisplay.AxisNamePopupLayout(bind.input);
                    break;

                case KeyType.KeyCode:
                    bind.code = (int)(KeyCode)EditorGUILayout.EnumPopup((KeyCode)bind.code);
                    break;
                }

                GUILayout.EndHorizontal();

                //axis settings
                GUILayout.Label("Axis Settings");

                bind.invert = EditorGUILayout.Toggle("Invert", bind.invert);

                if (curKeyType == KeyType.KeyCode)
                {
                    bind.axis = (InputAction.ButtonAxis)EditorGUILayout.EnumPopup("Axis", bind.axis);
                }

                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(dat, "Input Action Change Bind " + i);
                    dat.defaultBinds[i] = bind;
                    dat.ResetBind(i);
                    isDirty = true;
                }

                GUILayout.EndVertical();
            }

            if (GUILayout.Button("Add New Bind"))
            {
                Undo.RecordObject(dat, "Input Action Add New Bind");
                System.Array.Resize(ref dat.defaultBinds, dat.defaultBinds.Length + 1);
                dat.ResetBinds();
                isDirty = true;
            }

            if (deleteIndex != -1)
            {
                Undo.RecordObject(dat, "Input Action Delete Bind");
                dat.defaultBinds = ArrayUtil.RemoveAt(dat.defaultBinds, deleteIndex);
                dat.ResetBinds();
                isDirty = true;
            }

            if (dupIndex != -1)
            {
                Undo.RecordObject(dat, "Input Action Duplicate Bind");
                var newBind = dat.defaultBinds[dupIndex];
                ArrayUtil.InsertAfter(ref dat.defaultBinds, dupIndex, newBind);
                dat.ResetBinds();
                isDirty = true;
            }

            if (isDirty)
            {
                EditorUtility.SetDirty(dat);
            }

            GUILayout.EndVertical();
        }
        public override void OnInspectorGUI()
        {
            ShaderGlobalVariables dat = target as ShaderGlobalVariables;

            //Values
            mValuesFoldout = EditorGUILayout.Foldout(mValuesFoldout, "Values");
            if (mValuesFoldout)
            {
                if (dat.values != null)
                {
                    for (int i = 0; i < dat.values.Length; i++)
                    {
                        var val = dat.values[i];

                        EditorGUI.BeginChangeCheck();

                        GUILayout.BeginVertical(GUI.skin.box);

                        //name
                        GUILayout.BeginHorizontal();

                        val.name = EditorGUILayout.TextField(val.name);

                        GUILayout.FlexibleSpace();

                        if (EditorExt.Utility.DrawAddButton())
                        {
                            Undo.RecordObject(target, "Shader Global Variables Add");
                            ArrayUtil.InsertAfter(ref dat.values, i, val.Clone());
                            break;
                        }

                        GUILayout.Space(4f);

                        if (EditorExt.Utility.DrawRemoveButton())
                        {
                            Undo.RecordObject(target, "Shader Global Variables Remove");
                            ArrayUtil.RemoveAt(ref dat.values, i);
                            break;
                        }

                        GUILayout.EndHorizontal();

                        //type
                        val.type = (ShaderGlobalVariables.Type)EditorGUILayout.EnumPopup(val.type);

                        //value
                        switch (val.type)
                        {
                        case ShaderGlobalVariables.Type.Float:
                            val.val     = EditorGUILayout.FloatField("Value", val.val);
                            val.texture = null;
                            break;

                        case ShaderGlobalVariables.Type.Vector:
                            val.val4    = EditorGUILayout.Vector4Field("Value", val.val4);
                            val.texture = null;
                            break;

                        case ShaderGlobalVariables.Type.Color:
                            val.color   = EditorGUILayout.ColorField(val.color);
                            val.texture = null;
                            break;

                        case ShaderGlobalVariables.Type.Texture:
                            val.texture = EditorGUILayout.ObjectField(val.texture, typeof(Texture), false) as Texture;
                            break;
                        }

                        GUILayout.EndVertical();

                        if (EditorGUI.EndChangeCheck())
                        {
                            Undo.RecordObject(target, "Shader Global Variables Edit - " + dat.values[i].name);
                            dat.values[i] = val;
                        }
                    }
                }

                //add new
                if (GUILayout.Button("Add New Value"))
                {
                    Undo.RecordObject(target, "Shader Global Variables Add");

                    if (dat.values == null || dat.values.Length == 0)
                    {
                        dat.values = new ShaderGlobalVariables.Data[1] {
                            new ShaderGlobalVariables.Data()
                        };
                    }
                    else
                    {
                        var newDat = dat.values[dat.values.Length - 1].Clone();
                        System.Array.Resize(ref dat.values, dat.values.Length + 1);
                        dat.values[dat.values.Length - 1] = newDat;
                    }
                }
            }

            EditorExt.Utility.DrawSeparator();

            //Component settings
            EditorGUI.BeginChangeCheck();

            var applyOnAwake = GUILayout.Toggle(dat.applyOnAwake, "Apply On Awake");

            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Change Shader Global Variables Component Setting");

                dat.applyOnAwake = applyOnAwake;
            }


            //Controls
            if (GUILayout.Button("Refresh"))
            {
                dat.Apply();
            }
        }