/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of color 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 MaterialParamColorGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); var guiToggle = new GUIToggle(new GUIContent( EditorBuiltin.GetEditorToggleIcon(EditorToggleIcon.AnimateProperty), new LocString("Animate"))); guiColor = new GUIColorField(title); guiColorGradient = new GUIColorGradientField(title); bool isAnimated = material.IsAnimated(shaderParam.name); guiColor.Active = !isAnimated; guiColorGradient.Active = isAnimated; fieldLayout = layout.AddLayoutX(); fieldLayout.AddElement(guiColor); fieldLayout.AddElement(guiColorGradient); fieldLayout.AddSpace(10); fieldLayout.AddElement(guiToggle); guiColor.OnChanged += (x) => { material.SetColor(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiColorGradient.OnChanged += x => { material.SetColorGradient(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiToggle.OnToggled += x => { guiColor.Active = !x; guiColorGradient.Active = x; if (x) { ColorGradient gradient = material.GetColorGradient(shaderParam.name); if (gradient.NumKeys == 0) { material.SetColorGradient(shaderParam.name, new ColorGradient(material.GetColor(shaderParam.name))); } } }; }
/// <summary> /// Creates a new material parameter GUI. /// </summary> /// <param name="shaderParam">Shader parameter to create the GUI for. Must be of floating point 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 MaterialParamFloatGUI(ShaderParameter shaderParam, Material material, GUILayout layout) : base(shaderParam) { LocString title = new LocEdString(shaderParam.name); var guiToggle = new GUIToggle(new GUIContent( EditorBuiltin.GetEditorToggleIcon(EditorToggleIcon.AnimateProperty), new LocString("Animate"))); guiConstant = new GUIFloatField(title); guiCurves = new GUICurvesField(title); bool isAnimated = material.IsAnimated(shaderParam.name); guiConstant.Active = !isAnimated; guiCurves.Active = isAnimated; fieldLayout = layout.AddLayoutX(); fieldLayout.AddElement(guiConstant); fieldLayout.AddElement(guiCurves); fieldLayout.AddSpace(10); fieldLayout.AddElement(guiToggle); guiConstant.OnChanged += (x) => { material.SetFloat(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiCurves.OnChanged += x => { material.SetFloatCurve(shaderParam.name, x); EditorApplication.SetDirty(material); }; guiToggle.OnToggled += x => { guiConstant.Active = !x; guiCurves.Active = x; }; }