private void CalcFontSize() { GUIStyle style = new GUIStyle(); style.font = this.Text.font; style.fontStyle = this.Text.fontStyle; GUIContent content = new GUIContent() { text = this.Text.text }; this.Text.fontSize = 200; int fontSize = 200; if (!string.IsNullOrEmpty(this.Text.text)) { for (fontSize = 2; fontSize < this.Text.fontSize; fontSize++) { style.fontSize = fontSize; Vector2 size = style.CalcSize(content); size = style.CalcScreenSize(size); if (size.x >= this.Width - 1 || size.y >= this.Height - 1) { break; } } this.Text.fontSize = fontSize + DeltaFontSize; } else { this.Text.fontSize = 8; } }
/// <summary> /// Gets the width of the label. /// </summary> /// <param name="style">The style.</param> /// <param name="content">The content.</param> /// <returns>The width of label.</returns> public static float GetLabelWidth(GUIStyle style, GUIContent content) { Vector2 size = style.CalcSize(content); size = style.CalcScreenSize(size); return(size.x); }
public static void AddMouseLabel(Component comp, string message) { var mouseLabel = new MouseLabel { message = message, boxSize = k_MouseLabelStyle.CalcScreenSize(k_MouseLabelStyle.CalcSize(new GUIContent(message))), }; s_MouseLabels[comp] = mouseLabel; UpdateMouseLabels(); }
public void OnGUI() { Scene curScene = SceneManager.GetActiveScene(); if (curScene.name == "Maze") { GUIStyle tStyle = GUI.skin.GetStyle("label"); tStyle.alignment = TextAnchor.MiddleCenter; tStyle.font = instance.hsFont; tStyle.richText = true; GUIContent tContent = new GUIContent("<color=yellow><b>Scores: </b>" + instance.score + "</color>"); Vector2 tSize = tStyle.CalcScreenSize(tStyle.CalcSize(tContent)); GUI.Label(new Rect(62, 38, tSize.x, tSize.y), tContent, tStyle); } }
// called every frame public void OnGUI() { // do nothing in the main menu if (!(Lib.SceneIsGame() || HighLogic.LoadedScene == GameScenes.EDITOR)) return; // if queue is empty, do nothing if (entries.Count == 0) return; // get current time float time = Time.realtimeSinceStartup; // get first entry in the queue Entry e = entries.Peek(); // if never visualized, remember first time shown if (e.first_seen <= float.Epsilon) e.first_seen = time; // if visualized for too long, remove from the queue and skip this update if (e.first_seen + Settings.MessageLength < time) { entries.Dequeue(); return; } // calculate content size GUIContent content = new GUIContent(e.msg); Vector2 size = style.CalcSize(content); size = style.CalcScreenSize(size); size.x += style.padding.left + style.padding.right; size.y += style.padding.bottom + style.padding.top; // calculate position Rect rect = new Rect((Screen.width - size.x) * 0.5f, (Screen.height - size.y - offset), size.x, size.y); // render the message var prev_style = GUI.skin.label; GUI.skin.label = style; GUI.Label(rect, e.msg); GUI.skin.label = prev_style; }
public static Vector2 CalcScreenSizeForContent(GUIContent content, GUIStyle style) { return(style.CalcScreenSize(style.CalcSize(content))); }
public static Vector2 CalculateTotalSize(this GUIStyle guiStyle, string content) { return(guiStyle.CalcScreenSize(guiStyle.CalcSize(new GUIContent(content)))); }