DifferentialSlider(string label, string unit, double log10_lower_rate, double log10_upper_rate, double min_value = double.NegativeInfinity, double max_value = double.PositiveInfinity, ValueFormatter formatter = null, UnityEngine.Color?text_colour = null) { label_ = label; unit_ = unit; if (formatter == null) { format_ = v => v.ToString("#,0.000", Culture.culture); } else { format_ = formatter; } log10_lower_rate_ = log10_lower_rate; log10_upper_rate_ = log10_upper_rate; min_value_ = min_value; max_value_ = max_value; text_colour_ = text_colour; }
/// <summary> /// Initializes the components of the button to the specified values. /// </summary> /// <param name="ID">The unique id (if any) of this object.</param> /// <param name="T">The Text object representing the test and styling of the button label.</param> /// <param name="B">The image object representing the button background.</param> /// <param name="X">The x positioning of the button relative to the parent as governed by the horizontal alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>X Position</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>x units from parent's left edge</term> /// </item> /// <item> /// <term>Left</term> /// <term>x units from parent's left edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>x position is ignored</term> /// </item> /// <item> /// <term>Right</term> /// <term>x units from parent's right edge</term> /// </item> /// </list> /// </param> /// <param name="Y">The y positioning of the button relative to the parent as governed by the vertical alignment as follows: /// <list type="table"> /// <listheader> /// <term>Alignment</term> /// <term>Y Position</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>y units from parent's top edge</term> /// </item> /// <item> /// <term>Top</term> /// <term>y units from parent's top edge</term> /// </item> /// <item> /// <term>Center</term> /// <term>y position is ignored</term> /// </item> /// <item> /// <term>Bottom</term> /// <term>y units from parent's bottom edge</term> /// </item> /// </list> /// </param> /// <param name="W">The width of the button.</param> /// <param name="H">The height of the button.</param> /// <param name="HAlign">The horizontal alignemnt of the label within the parent rect as specified by the following values: /// <list type="table"> /// <listheader> /// <term>String Value</term> /// <term>Alignment.Type</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>null</term> /// </item> /// <item> /// <term>left</term> /// <term>Alignment.Type.Left</term> /// </item> /// <item> /// <term>center</term> /// <term>Alignment.Type.Center</term> /// </item> /// <item> /// <term>right</term> /// <term>Alignment.Type.Right</term> /// </item> /// </list> /// </param> /// <param name="VAlign">The horizontal alignemnt of the label within the parent rect as specified by the following values: /// <list type="table"> /// <listheader> /// <term>String Value</term> /// <term>Alignment.Type</term> /// </listheader> /// <item> /// <term>null or empty</term> /// <term>null</term> /// </item> /// <item> /// <term>top</term> /// <term>Alignment.Type.Top</term> /// </item> /// <item> /// <term>center</term> /// <term>Alignment.Type.Center</term> /// </item> /// <item> /// <term>bottom</term> /// <term>Alignment.Type.Bottom</term> /// </item> /// </list> /// </param> /// <example> /// Instantiate a button object with an id of "myButton" (child objects omitted for clarity) spaced 10% from the left edge of the parent rect, measuring 100x100 virtual units and centered vertically: /// <code> /// Button button = new Button("myButton", textLabel, imgBackground, "10%", null, "100", "100", null, "center"); /// </code> /// </example> public Button(string ID, Text T, UnityEngine.Color?TextDisabled, Image B, string X, string Y, string W, string H, string HAlign, string VAlign, string Enabled, string Visible) : base(ID, X, Y, W, H, HAlign, VAlign, Visible) { text = T == null ? null : new Text(T); textDisabled = TextDisabled; _background = B; _guiDispatcher = new GUIEventDispatcher(/*this*/); enabled = Enabled == null || Enabled == "" ? true : bool.Parse(Enabled); }
public static UnityEngine.Color?[] ParseColours(params string[] htmlColours) { if (htmlColours == null || htmlColours.Length <= 0) { return(null); } UnityEngine.Color?[] result = new UnityEngine.Color?[htmlColours.Length]; for (int i = 0, len = result.Length; i < len; i++) { result[i] = ParseColour(htmlColours[i]); } return(AllNull(result) ? null : result); }
// Rates are in units of |value| per real-time second. public DifferentialSlider(string label, string unit, double log10_lower_rate, double log10_upper_rate, double zero_value = 0, double min_value = double.NegativeInfinity, double max_value = double.PositiveInfinity, ValueFormatter formatter = null, ValueParser parser = null, UnityEngine.Color?text_colour = null, int label_width = 3, int field_width = 5) { label_ = label; label_width_ = label_width; field_width_ = field_width; unit_ = unit; if (formatter == null) { // TODO(egg): Is this just "N3"? formatter_ = v => v.ToString("#,0.000", Culture.culture); } else { formatter_ = formatter; } if (parser == null) { // As a special exemption we allow a comma as the decimal separator. parser_ = (string s, out double value) => double.TryParse(s.Replace(',', '.'), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowThousands | NumberStyles.AllowTrailingWhite, Culture.culture.NumberFormat, out value); } else { parser_ = parser; } log10_lower_rate_ = log10_lower_rate; log10_upper_rate_ = log10_upper_rate; zero_value_ = zero_value; min_value_ = min_value; max_value_ = max_value; text_colour_ = text_colour; }
// Rates are in units of |value| per real-time second. public DifferentialSlider(string label, string unit, double log10_lower_rate, double log10_upper_rate, ValueFormatter formatter, UnityEngine.TextAnchor alignment = UnityEngine.TextAnchor.MiddleRight, ValueParser parser = null, double zero_value = 0, double min_value = double.NegativeInfinity, double max_value = double.PositiveInfinity, UnityEngine.Color?text_colour = null, int label_width = 3, int field_width = 5) { label_ = label; label_width_ = label_width; field_width_ = field_width; unit_ = unit; alignment_ = alignment; formatter_ = formatter; if (parser == null) { // As a special exemption we allow a comma as the decimal separator and // the hyphen-minus instead of the minus sign. // We also turn figure spaces back into leading 0s, and remove grouping // marks, since .NET does not like those in the fractional part. parser_ = (string s, out double value) => double.TryParse( s.Replace(',', '.').Replace('-', '−') .Replace(figure_space, '0').Replace("'", ""), NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign | NumberStyles.AllowLeadingWhite | NumberStyles.AllowThousands | NumberStyles.AllowTrailingWhite, Culture.culture.NumberFormat, out value); } else { parser_ = parser; } log10_lower_rate_ = log10_lower_rate; log10_upper_rate_ = log10_upper_rate; zero_value_ = zero_value; min_value_ = min_value; max_value_ = max_value; text_colour_ = text_colour; }
/// <summary> /// Presents the input field visually on the screen. /// </summary> /// <param name="VirtualScale">The scaling factor used to map virtual units to pixel units if component unit type is virtual.</param> /// <param name="Parent">The parent rect (in pixel units) that this object resides within.</param> public override void Present(float VirtualScale, UnityEngine.Rect Parent) { UnityEngine.Rect rPx = rect.ToPixelRect(VirtualScale, Parent); UnityEngine.GUIStyle style = text.CalculateGUIStyle(VirtualScale); style.clipping = UnityEngine.TextClipping.Clip; style.normal.background = null; style.active.background = null; style.hover.background = null; style.focused.background = null; bool focus = UnityEngine.GUI.GetNameOfFocusedControl() == id; if (background != null) { if (!focus && backgroundUnfocus != null) { UnityEngine.Color?orig = background.rgba; background.rgba = backgroundUnfocus; background.Present(VirtualScale, rPx); background.rgba = orig; } else { background.Present(VirtualScale, rPx); } } if (icon != null) { // Resize the icon so the height matches the input box height whilst preserving the aspect ratio float aspect = (float)icon.img.width / (float)icon.img.height; icon.rect.dim.y.value = rPx.height; icon.rect.dim.x.value = rPx.height * aspect; icon.Present(1.0f, rPx); // Reduce the text area of the input box by the width of the icon rPx.width -= (float)icon.rect.dim.x.value; } // Left and right padding of text from sides of input box float xOffset = padding.ToPixel(VirtualScale, rPx.width); rPx.x += xOffset; rPx.width -= xOffset * 2; // Focus and unfocus colour if (focus && text.colour != null) { style.normal.textColor = (UnityEngine.Color)text.colour; } else if (textUnfocus != null) { style.normal.textColor = (UnityEngine.Color)textUnfocus; } UnityEngine.GUI.SetNextControlName(id); // Cursor colour UnityEngine.Color cursOrig = UnityEngine.GUI.skin.settings.cursorColor; UnityEngine.GUI.skin.settings.cursorColor = style.normal.textColor; // Normal input box if (type == Type.Plain) { if (maxLength <= 0) { text.text = UnityEngine.GUI.TextField(rPx, text.text, style); } else { text.text = UnityEngine.GUI.TextField(rPx, text.text, maxLength, style); } } // Password input box else if (type == Type.Password) { if (maxLength <= 0) { text.text = UnityEngine.GUI.PasswordField(rPx, text.text, "*"[0], style); } else { text.text = UnityEngine.GUI.PasswordField(rPx, text.text, "*"[0], maxLength, style); } } UnityEngine.GUI.skin.settings.cursorColor = cursOrig; }
private static void PostScreenMessage(string message, float duration = 5.0f, ScreenMessageStyle style = ScreenMessageStyle.UPPER_CENTER, UnityEngine.Color?color = null) { if (color == null) { ScreenMessages.PostScreenMessage(message, duration, style); } else { ScreenMessages.PostScreenMessage(message, duration, style, color.Value); } }