/// <inheritoc/> protected internal override void Initialize(int layoutIndex) { if (property != null) { guiField = new GUIColorField(new GUIContent(title)); guiField.OnChanged += OnFieldValueChanged; layout.AddElement(layoutIndex, guiField); } }
/// <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); guiElem = new GUIColorField(title); guiElem.OnChanged += (x) => { material.SetColor(shaderParam.name, x); EditorApplication.SetDirty(material); }; layout.AddElement(guiElem); }
/// <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> /// Builds the GUI for the specified state style. /// </summary> /// <param name="title">Text to display on the title bar.</param> /// <param name="layout">Layout to append the GUI elements to.</param> public void BuildGUI(LocString title, GUILayout layout) { foldout = new GUIToggle(title, EditorStyles.Foldout); textureField = new GUIResourceField(typeof(SpriteTexture), new LocEdString("Texture")); textColorField = new GUIColorField(new LocEdString("Text color")); foldout.AcceptsKeyFocus = false; foldout.OnToggled += x => { textureField.Active = x; textColorField.Active = x; isExpanded = x; }; textureField.OnChanged += x => { SpriteTexture texture = Resources.Load <SpriteTexture>(x.UUID); state.texture = texture; if (OnChanged != null) { OnChanged(state); } }; textColorField.OnChanged += x => { state.textColor = x; if (OnChanged != null) { OnChanged(state); } }; layout.AddElement(foldout); layout.AddElement(textureField); layout.AddElement(textColorField); foldout.Value = isExpanded; textureField.Active = isExpanded; textColorField.Active = isExpanded; }
private static extern void Internal_create3(GUIColorField managedInstance, string style);
private static extern void Internal_create2(GUIColorField managedInstance, LocString labelText, string style);
private static extern void Internal_create0(GUIColorField managedInstance, ref GUIContent labelContent, string style);
private static extern void Internal_CreateInstance(GUIColorField instance, ref GUIContent title, int titleWidth, string style, GUIOption[] options, bool withTitle);
private void OnInitialize() { guiColor = new GUIColorField(); guiColor.SetWidth(100); guiSlider2DTex = new GUITexture(null, GUIOption.FixedHeight(ColorBoxHeight), GUIOption.FixedWidth(ColorBoxWidth)); guiSliderVertTex = new GUITexture(null, GUIOption.FixedHeight(SliderSideHeight), GUIOption.FixedWidth(SliderSideWidth)); guiSliderRHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderGHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderBHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiSliderAHorzTex = new GUITexture(null, GUIOption.FixedHeight(SliderIndividualHeight)); guiColorBoxBtn = new GUIButton(colorBoxMode.ToString()); guiColorModeBtn = new GUIButton(sliderMode.ToString()); guiSliderVert = new GUISliderV(EditorStylesInternal.ColorSliderVert); guiSliderRHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz); guiSliderGHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz); guiSliderBHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz); guiSliderAHorz = new GUISliderH(EditorStylesInternal.ColorSliderHorz); guiSlider2DHandle = new GUITexture(null, EditorStylesInternal.ColorSlider2DHandle); guiLabelR = new GUILabel(new LocEdString("R")); guiLabelG = new GUILabel(new LocEdString("G")); guiLabelB = new GUILabel(new LocEdString("B")); guiLabelA = new GUILabel(new LocEdString("A")); guiInputR = new GUIIntField(); guiInputG = new GUIIntField(); guiInputB = new GUIIntField(); guiInputA = new GUIIntField(); guiOK = new GUIButton(new LocEdString("OK")); guiCancel = new GUIButton(new LocEdString("Cancel")); guiColorBoxBtn.OnClick += OnColorBoxModeChanged; guiColorModeBtn.OnClick += OnSliderModeChanged; guiSliderVert.OnChanged += OnSliderVertChanged; guiSliderRHorz.OnChanged += OnSliderRHorzChanged; guiSliderGHorz.OnChanged += OnSliderGHorzChanged; guiSliderBHorz.OnChanged += OnSliderBHorzChanged; guiSliderAHorz.OnChanged += OnSliderAHorzChanged; guiInputR.OnChanged += OnInputRChanged; guiInputG.OnChanged += OnInputGChanged; guiInputB.OnChanged += OnInputBChanged; guiInputA.OnChanged += OnInputAChanged; guiOK.OnClick += OnOK; guiCancel.OnClick += OnCancel; if (hdr) { guiSliderExposure = new GUISliderH("", GUIOption.FixedWidth(100)); guiSliderExposure.SetRange(-MaxExposureRange, MaxExposureRange); guiSliderExposure.OnChanged += OnSliderExposureChanged; guiLabelExposure = new GUILabel(new LocEdString("Exposure")); guiInputExposure = new GUIFloatField(); guiInputExposure.SetRange(-MaxExposureRange, MaxExposureRange); guiInputExposure.OnChanged += OnInputExposureChanged; } GUIPanel mainPanel = GUI.AddPanel(0); mainPanel.SetWidth(ContentWidth); mainPanel.SetHeight(ContentHeight); GUILayout v0 = mainPanel.AddLayoutY(); v0.AddSpace(5); GUILayout h0 = v0.AddLayoutX(); h0.AddSpace(10); h0.AddElement(guiColor); h0.AddFlexibleSpace(); h0.AddElement(guiColorBoxBtn); h0.AddElement(guiColorModeBtn); h0.AddSpace(10); v0.AddSpace(10); GUILayout h1 = v0.AddLayoutX(); h1.AddSpace(10); h1.AddElement(guiSlider2DTex); h1.AddFlexibleSpace(); h1.AddElement(guiSliderVertTex); h1.AddSpace(10); v0.AddSpace(10); GUILayout h2 = v0.AddLayoutX(); h2.AddSpace(10); h2.AddElement(guiLabelR); h2.AddFlexibleSpace(); h2.AddElement(guiSliderRHorzTex); h2.AddFlexibleSpace(); h2.AddElement(guiInputR); h2.AddSpace(10); v0.AddSpace(5); GUILayout h3 = v0.AddLayoutX(); h3.AddSpace(10); h3.AddElement(guiLabelG); h3.AddFlexibleSpace(); h3.AddElement(guiSliderGHorzTex); h3.AddFlexibleSpace(); h3.AddElement(guiInputG); h3.AddSpace(10); v0.AddSpace(5); GUILayout h4 = v0.AddLayoutX(); h4.AddSpace(10); h4.AddElement(guiLabelB); h4.AddFlexibleSpace(); h4.AddElement(guiSliderBHorzTex); h4.AddFlexibleSpace(); h4.AddElement(guiInputB); h4.AddSpace(10); v0.AddSpace(5); GUILayout h5 = v0.AddLayoutX(); h5.AddSpace(10); h5.AddElement(guiLabelA); h5.AddFlexibleSpace(); h5.AddElement(guiSliderAHorzTex); h5.AddFlexibleSpace(); h5.AddElement(guiInputA); h5.AddSpace(10); if (hdr) { v0.AddSpace(5); GUILayout hExposure = v0.AddLayoutX(); hExposure.AddSpace(10); hExposure.AddElement(guiLabelExposure); hExposure.AddFlexibleSpace(); hExposure.AddElement(guiSliderExposure); hExposure.AddFlexibleSpace(); hExposure.AddElement(guiInputExposure); hExposure.AddSpace(10); } v0.AddSpace(10); GUILayout h6 = v0.AddLayoutX(); h6.AddFlexibleSpace(); h6.AddElement(guiOK); h6.AddSpace(10); h6.AddElement(guiCancel); h6.AddFlexibleSpace(); v0.AddSpace(5); GUIPanel overlay = GUI.AddPanel(-1); overlay.SetWidth(ContentWidth); overlay.SetHeight(ContentHeight); overlay.AddElement(guiSliderVert); overlay.AddElement(guiSliderRHorz); overlay.AddElement(guiSliderGHorz); overlay.AddElement(guiSliderBHorz); overlay.AddElement(guiSliderAHorz); overlay.AddElement(guiSlider2DHandle); colorBox = new ColorSlider2D(guiSlider2DTex, guiSlider2DHandle, ColorBoxWidth, ColorBoxHeight); sideSlider = new ColorSlider1DVert(guiSliderVertTex, guiSliderVert, SliderSideWidth, SliderSideHeight); sliderR = new ColorSlider1DHorz(guiSliderRHorzTex, guiSliderRHorz, SliderIndividualWidth, SliderIndividualHeight); sliderG = new ColorSlider1DHorz(guiSliderGHorzTex, guiSliderGHorz, SliderIndividualWidth, SliderIndividualHeight); sliderB = new ColorSlider1DHorz(guiSliderBHorzTex, guiSliderBHorz, SliderIndividualWidth, SliderIndividualHeight); sliderA = new ColorSlider1DHorz(guiSliderAHorzTex, guiSliderAHorz, SliderIndividualWidth, SliderIndividualHeight); colorBox.OnValueChanged += OnColorBoxValueChanged; Color startA = new Color(0, 0, 0, 1); Color stepA = new Color(1, 1, 1, 0); sliderA.UpdateTexture(startA, stepA, false, false); guiInputA.SetRange(0, 255); guiInputA.Value = 255; guiSliderAHorz.Percent = 1.0f; guiColor.Value = GUIColor; UpdateInputBoxValues(); Update2DSliderValues(); Update1DSliderValues(); UpdateSliderMode(); Update2DSliderTextures(); Update1DSliderTextures(); }