/// <summary> /// Draws an RGB slider using the GUI and the given arguments. /// </summary> /// <param name="scaleToScreen">If true, the values of "layout" will be scaled by the screen dimensions.</param> public static Color RGBSlider(Color currentRGB, RGBLayout layout, bool scaleToScreen) { Color oldColor = GUI.contentColor; //Layout data. if (scaleToScreen) { layout = new RGBLayout(layout); layout.ScreenPos = new Vector2(Screen.width * layout.ScreenPos.x, Screen.height * layout.ScreenPos.y); layout.LabelOffset = new Vector2(Screen.width * layout.LabelOffset.x, Screen.height * layout.LabelOffset.y); layout.SliderWidth = Screen.width * layout.SliderWidth; layout.SliderYSpacing = Screen.height * layout.SliderYSpacing; layout.BackgroundBorderSize = new Vector2(Screen.width * layout.BackgroundBorderSize.x, Screen.height * layout.BackgroundBorderSize.y); } Vector2 screenPos = new Vector2(layout.ScreenPos.x, layout.ScreenPos.y); Vector2 labelOffset = new Vector2(layout.LabelOffset.x, layout.LabelOffset.y); float width = layout.SliderWidth; float sliderYSpacing = layout.SliderYSpacing; Vector2 backgroundBorderSize = new Vector2(layout.BackgroundBorderSize.x, layout.BackgroundBorderSize.y); //Get screen rectangles. Rect backgroundRect = new Rect(screenPos.x - backgroundBorderSize.x, screenPos.y - backgroundBorderSize.y, width + (2.0f * backgroundBorderSize.x), (2.0f * backgroundBorderSize.y) + (2.0f * (SliderHeight - SliderHeight + sliderYSpacing))); Rect sliderRect = new Rect(screenPos.x, screenPos.y, width, SliderHeight); //Draw the background. GUI.backgroundColor = Color.white; GUI.Box(backgroundRect, "", WorldConstants.GUIStyles.RGBBoxes); //Draw the sliders. GUI.color = new Color(currentRGB.r, 0.0f, 0.0f); GUI.Label(new Rect(sliderRect.x + labelOffset.x, sliderRect.y + labelOffset.y, sliderRect.width, RGBSliderTextHeight), "Red"); currentRGB.r = GUI.HorizontalSlider(sliderRect, currentRGB.r, 0.0f, 1.0f, WorldConstants.GUIStyles.RGBSliders, WorldConstants.GUIStyles.RGBSliderNubs); sliderRect.y += sliderYSpacing; GUI.color = new Color(0.0f, currentRGB.g, 0.0f); GUI.Label(new Rect(sliderRect.x + labelOffset.x, sliderRect.y + labelOffset.y, sliderRect.width, RGBSliderTextHeight), "Green"); currentRGB.g = GUI.HorizontalSlider(sliderRect, currentRGB.g, 0.0f, 1.0f, WorldConstants.GUIStyles.RGBSliders, WorldConstants.GUIStyles.RGBSliderNubs); sliderRect.y += sliderYSpacing; GUI.color = new Color(0.0f, 0.0f, currentRGB.b); GUI.Label(new Rect(sliderRect.x + labelOffset.x, sliderRect.y + labelOffset.y, sliderRect.width, RGBSliderTextHeight), "Blue"); currentRGB.b = GUI.HorizontalSlider(sliderRect, currentRGB.b, 0.0f, 1.0f, WorldConstants.GUIStyles.RGBSliders, WorldConstants.GUIStyles.RGBSliderNubs); GUI.contentColor = oldColor; return(currentRGB); }
public RGBLayout(RGBLayout copy) : this(copy.ScreenPos, copy.LabelOffset, copy.SliderWidth, copy.SliderYSpacing, copy.BackgroundBorderSize) { }