Exemplo n.º 1
0
        /// <summary>
        /// Creates a new material parameter GUI.
        /// </summary>
        /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 4D vector type.</param>
        /// <param name="material">Material the parameter is a part of.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        internal MaterialParamVec4GUI(ShaderParameter shaderParam, Material material, GUILayout layout)
            : base(shaderParam)
        {
            LocString title = new LocEdString(shaderParam.Name);

            guiElem            = new GUIVector4Field(title);
            guiElem.OnChanged += (x) =>
            {
                material.SetVector4(shaderParam.Name, x);
                EditorApplication.SetDirty(material);
            };

            layout.AddElement(guiElem);
        }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            Material material = InspectedObject as Material;

            if (material == null)
            {
                return;
            }

            Shader        activeShader = material.Shader;
            BuiltinShader builtinType  = ShaderToBuiltin(activeShader);

            builtinShaderField       = new GUIEnumField(typeof(BuiltinShader), new LocEdString("Shader"));
            builtinShaderField.Value = (ulong)builtinType;
            builtinShaderField.OnSelectionChanged += x =>
            {
                BuiltinShader newBuiltinType = (BuiltinShader)x;

                material.Shader = Builtin.GetShader(newBuiltinType);
                EditorApplication.SetDirty(material);
                RebuildParamGUI(material);

                bool newIsCustom = newBuiltinType == BuiltinShader.Custom;
                shaderField.Active = newIsCustom;
            };

            shaderField            = new GUIResourceField(typeof(Shader), new LocEdString("Shader file"));
            shaderField.Value      = material.Shader;
            shaderField.OnChanged += (x) =>
            {
                Shader shader = Resources.Load <Shader>(x);

                material.Shader = shader;
                EditorApplication.SetDirty(material);
                RebuildParamGUI(material);
            };

            bool isCustom = builtinType == BuiltinShader.Custom;

            shaderField.Active = isCustom;

            Layout.AddElement(builtinShaderField);
            Layout.AddElement(shaderField);

            RebuildParamGUI(material);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new material parameter GUI.
        /// </summary>
        /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of 4x4 matrix type.</param>
        /// <param name="material">Material the parameter is a part of.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        internal MaterialParamMat4GUI(ShaderParameter shaderParam, Material material, GUILayout layout)
            : base(shaderParam)
        {
            LocString title    = new LocEdString(shaderParam.name);
            GUILabel  guiTitle = new GUILabel(title, GUIOption.FixedWidth(100));

            mainLayout = layout.AddLayoutY();
            GUILayoutX titleLayout = mainLayout.AddLayoutX();

            titleLayout.AddElement(guiTitle);
            titleLayout.AddFlexibleSpace();

            GUILayoutY contentLayout = mainLayout.AddLayoutY();

            GUILayoutX[] rows = new GUILayoutX[MAT_SIZE];
            for (int i = 0; i < rows.Length; i++)
            {
                rows[i] = contentLayout.AddLayoutX();
            }

            for (int row = 0; row < MAT_SIZE; row++)
            {
                for (int col = 0; col < MAT_SIZE; col++)
                {
                    int index = row * MAT_SIZE + col;
                    guiMatFields[index] = new GUIFloatField(row + "," + col, 20, "", GUIOption.FixedWidth(80));

                    GUIFloatField field = guiMatFields[index];
                    rows[row].AddElement(field);
                    rows[row].AddSpace(5);

                    int hoistedRow = row;
                    int hoistedCol = col;
                    field.OnChanged += (x) =>
                    {
                        Matrix4 value = material.GetMatrix4(shaderParam.name);
                        value[hoistedRow, hoistedCol] = x;
                        material.SetMatrix4(shaderParam.name, value);
                        EditorApplication.SetDirty(material);
                    };
                }
            }
        }
        /// <summary>
        /// Creates a new material parameter GUI.
        /// </summary>
        /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of texture type.</param>
        /// <param name="material">Material the parameter is a part of.</param>
        /// <param name="layout">Layout to append the GUI elements to.</param>
        internal MaterialParamTextureGUI(ShaderParameter shaderParam, Material material, GUILayout layout)
            : base(shaderParam)
        {
            LocString title = new LocEdString(shaderParam.Name);

            guiElem = new GUITextureField(title);

            switch (shaderParam.Type)
            {
            case ShaderParameterType.Texture2D:
                guiElem.OnChanged += (x) =>
                {
                    Texture2D texture = Resources.Load <Texture2D>(x);

                    material.SetTexture2D(shaderParam.Name, texture);
                    EditorApplication.SetDirty(material);
                };
                break;

            case ShaderParameterType.Texture3D:
                guiElem.OnChanged += (x) =>
                {
                    Texture3D texture = Resources.Load <Texture3D>(x);

                    material.SetTexture3D(shaderParam.Name, texture);
                    EditorApplication.SetDirty(material);
                };
                break;

            case ShaderParameterType.TextureCube:
                guiElem.OnChanged += (x) =>
                {
                    TextureCube texture = Resources.Load <TextureCube>(x);

                    material.SetTextureCube(shaderParam.Name, texture);
                    EditorApplication.SetDirty(material);
                };
                break;
            }

            layout.AddElement(guiElem);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();

            PhysicsMaterial material = InspectedObject as PhysicsMaterial;

            if (material == null)
            {
                return;
            }

            staticFrictionField  = new GUIFloatField(new LocEdString("Static friction"));
            dynamicFrictionField = new GUIFloatField(new LocEdString("Dynamic friction"));
            restitutionField     = new GUISliderField(0.0f, 1.0f, new LocEdString("Restitution"));

            staticFrictionField.OnChanged += x =>
            {
                material.StaticFriction = x;
                EditorApplication.SetDirty(material);
            };

            dynamicFrictionField.OnChanged += x =>
            {
                material.DynamicFriction = x;
                EditorApplication.SetDirty(material);
            };

            restitutionField.OnChanged += x =>
            {
                material.Restitution = x;
                EditorApplication.SetDirty(material);
            };

            Layout.AddElement(staticFrictionField);
            Layout.AddElement(dynamicFrictionField);
            Layout.AddElement(restitutionField);
        }
        /// <inheritdoc/>
        protected internal override void Initialize()
        {
            Material material = InspectedObject as Material;

            if (material == null)
            {
                return;
            }

            shaderField            = new GUIResourceField(typeof(Shader), new LocEdString("Shader"));
            shaderField.Value      = material.Shader;
            shaderField.OnChanged += (x) =>
            {
                Shader shader = Resources.Load <Shader>(x);

                material.Shader = shader;
                EditorApplication.SetDirty(material);
                RebuildParamGUI(material);
            };

            Layout.AddElement(shaderField);

            RebuildParamGUI(material);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            strings.Clear();

            StringTable stringTable = InspectedObject as StringTable;

            if (stringTable == null)
            {
                return;
            }

            string[] identifiers = stringTable.Identifiers;
            foreach (var identifier in identifiers)
            {
                strings[identifier] = stringTable.GetString(identifier);
            }

            languageField = new GUIEnumField(typeof(Language));
            languageField.OnSelectionChanged += x =>
            {
                StringTables.ActiveLanguage = (Language)x;
                BuildGUI();
                Refresh();
            };

            Layout.AddElement(languageField);

            valuesField = GUIDictionaryField <string, string, StringTableEntry> .Create(
                new LocEdString("Strings"), strings, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (stringTable.Contains(KVP.Key))
                        {
                            string oldValue = stringTable.GetString(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                stringTable.SetString(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            stringTable.SetString(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldIdentifiers = stringTable.Identifiers;
                    foreach (var identifier in oldIdentifiers)
                    {
                        if (!x.ContainsKey(identifier))
                        {
                            stringTable.RemoveString(identifier);
                        }
                    }

                    strings = x;
                }
                else
                {
                    foreach (var KVP in strings)
                    {
                        stringTable.RemoveString(KVP.Key);
                    }

                    strings.Clear();
                }

                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueChanged += x =>
            {
                stringTable.SetString(x, strings[x]);
                EditorApplication.SetDirty(stringTable);
            };

            valuesField.OnValueRemoved += x =>
            {
                stringTable.RemoveString(x);
                EditorApplication.SetDirty(stringTable);
            };

            Layout.AddSpace(10);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Recreates all the GUI elements used by this inspector.
        /// </summary>
        private void BuildGUI()
        {
            Layout.Clear();
            styles.Clear();

            GUISkin guiSkin = InspectedObject as GUISkin;

            if (guiSkin == null)
            {
                return;
            }

            string[] styleNames = guiSkin.StyleNames;
            foreach (var styleName in styleNames)
            {
                styles[styleName] = guiSkin.GetStyle(styleName);
            }

            valuesField = GUIDictionaryField <string, GUIElementStyle, GUIElementStyleEntry> .Create
                              (new LocEdString("Styles"), styles, Layout);

            valuesField.IsExpanded = Persistent.GetBool("valuesField_Expanded");
            valuesField.OnExpand  += x => Persistent.SetBool("valuesField_Expanded", x);

            valuesField.OnChanged += x =>
            {
                if (x != null)
                {
                    foreach (var KVP in x)
                    {
                        if (guiSkin.HasStyle(KVP.Key))
                        {
                            GUIElementStyle oldValue = guiSkin.GetStyle(KVP.Key);
                            if (oldValue != KVP.Value)
                            {
                                guiSkin.SetStyle(KVP.Key, KVP.Value);
                            }
                        }
                        else
                        {
                            guiSkin.SetStyle(KVP.Key, KVP.Value);
                        }
                    }

                    string[] oldStyleNames = guiSkin.StyleNames;
                    foreach (var styleName in oldStyleNames)
                    {
                        if (!x.ContainsKey(styleName))
                        {
                            guiSkin.RemoveStyle(styleName);
                        }
                    }

                    styles = x;
                }
                else
                {
                    foreach (var KVP in styles)
                    {
                        guiSkin.RemoveStyle(KVP.Key);
                    }

                    styles.Clear();
                }

                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueChanged += x =>
            {
                guiSkin.SetStyle(x, styles[x]);
                EditorApplication.SetDirty(guiSkin);
            };

            valuesField.OnValueRemoved += x =>
            {
                guiSkin.RemoveStyle(x);
                EditorApplication.SetDirty(guiSkin);
            };

            Layout.AddSpace(10);
        }