Beispiel #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);
        }
Beispiel #2
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);
                    };
                }
            }
        }
Beispiel #3
0
        /// <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);
        }
Beispiel #4
0
 /// <summary>
 /// Creates a new material parameter GUI.
 /// </summary>
 /// <param name="shaderParam">Shader parameter to create the GUI for.</param>
 protected MaterialParamGUI(ShaderParameter shaderParam)
 {
     this.shaderParam = shaderParam;
 }