public CalcHeight ( |
||
content | ||
width | float | |
return | float |
/// <summary> /// Calculates text height by ignoring bold style of the font. This will not work with inline bold tags. /// NOTE: This will not fix occasional new line when text ends right before end. /// </summary> /// <param name="content">Text content.</param> /// <param name="style">Text style.</param> /// <param name="width">Fixed width of text container.</param> /// <returns>Returns calculated height of the text.</returns> public static float CalculateHeight(GUIContent content, GUIStyle style, float width) { float height; // Bold fonts have much higher chance of having one new line to many than normal font. // There were no issues with missing new lines even with couple of extreme cases. (but extra new lines can occur) if (style.fontStyle == FontStyle.Bold) { style.fontStyle = FontStyle.Normal; style.wordWrap = true; style.fixedWidth = width; style.fixedHeight = 0; Texture2D t = new Texture2D(1,1); content.image = t; style.imagePosition = ImagePosition.ImageLeft; float min, max; style.CalcMinMaxWidth(content, out min, out max); style.clipping = TextClipping.Overflow; height = style.CalcHeight(content, min); style.fontStyle = FontStyle.Bold; } else { height = style.CalcHeight(content, width); } return height; }
public int List(Rect rect, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { if(fshow) { fshow = false; isClickedComboButton = false; } bool done = false; int cID = GUIUtility.GetControlID(FocusType.Passive); switch(Event.current.GetTypeForControl(cID)) { case EventType.mouseUp: { if(isClickedComboButton) { done = true; } } break; } if(GUI.Button(rect, buttonContent, buttonStyle)) { if(useid==-1) { useid = cID; isClickedComboButton = false; } if(useid!=cID) { fshow = true; useid = cID; } isClickedComboButton = true; } if(isClickedComboButton) { Rect listRect = new Rect(rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1.0f)+11, rect.width, listStyle.CalcHeight(listContent[0], 1.0f) * listContent.Length); GUI.Box(listRect, "", boxStyle); int newSelectedItemIndex = GUI.SelectionGrid(listRect, selectedItemIndex, listContent, 1, listStyle); if( newSelectedItemIndex != selectedItemIndex) { selectedItemIndex = newSelectedItemIndex; } } if(done) { isClickedComboButton = false; } return GetSelectedItemIndex(); }
public void MakeWindow(int id) { GUI.color = new Color(1, 1, 1, 0.8f); Functions.DrawBackground(new Rect(0, 0, width, height), bgTexture); GUI.color = Color.white; GUIStyle style = new GUIStyle(GUI.skin.label); style.alignment = TextAnchor.UpperCenter; style.font = font; style.fontSize = 16; GUI.Label(new Rect((windowRect.width - 100) / 2, 0, 100, 30), "Chat", style); Rect innerRect = new Rect(25, 40, width - 50, height * 0.5f); style = new GUIStyle(GUI.skin.label); style.alignment = TextAnchor.UpperLeft; float rectHeight = 0; for (int i = 0; i < msgList.Count; i++) { rectHeight += style.CalcHeight(new GUIContent(msgList[i]), innerRect.width - 25); } GUI.Box(new Rect(innerRect.x - 10, innerRect.y - 10, innerRect.width + 20, innerRect.height + 20), ""); scrollViewVector = GUI.BeginScrollView(innerRect, scrollViewVector, new Rect(0, 0, innerRect.width - 25, rectHeight)); float yStart = 0; for (int i = 0; i < msgList.Count; i++) { float msgHeight = style.CalcHeight(new GUIContent(msgList[i]), innerRect.width - 25); GUI.Label(new Rect(0, yStart, innerRect.width - 25, msgHeight), msgList[i], style); yStart += msgHeight; } GUI.EndScrollView(); GUI.SetNextControlName("chat_field"); message = GUI.TextField(new Rect(innerRect.x - 10, innerRect.y + innerRect.height + 20, 300, 20), message, 100); style = new GUIStyle(GUI.skin.button); style.alignment = TextAnchor.UpperCenter; buttonRect = new Rect(320, innerRect.y + innerRect.height + 20, 60, 20); if (GUI.Button(buttonRect, "Send", style)) { SendMessage(); } if (Input.GetKeyUp(KeyCode.Return)) { if (GUI.GetNameOfFocusedControl() != "chat_field") { GUI.FocusControl("chat_field"); } } }
protected override void Initialize() { base.Initialize(); alignToCenter = true; IsDraggable = true; showOKButton = true; WindowRect = new Rect( 0, 0, 350, 120 ); messageStyle = new GUIStyle( GUI.skin.label ); messageStyle.wordWrap = true; messageSize = messageStyle.CalcSize( new GUIContent( message ) ); if ( messageSize.x > 350 ) { var height = messageStyle.CalcHeight( new GUIContent( message ), 330 ); messageRect = new Rect( 10, WindowRect.height / 2 - height / 2, 330, height ); messageStyle.alignment = TextAnchor.MiddleCenter; } else { messageRect = new Rect( WindowRect.width / 2 - messageSize.x / 2, WindowRect.height / 2 - messageSize.y / 2, messageSize.x, messageSize.y ); } }
public void OnGUI() { var delta = Time.deltaTime * 1f; // Decrease the elapsed time. _elapsedTime -= delta; if(_elapsedTime < 0.0f) { _transparency = Mathf.Lerp (_transparency,0f, delta); } // Draw the GUI if we're supposed to show it. if(_transparency > 0.01f) { var content = new GUIContent(text); // Create the font style. var style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; style.fontSize = 24; // Tobii EyeX color: EC0088 style.normal.textColor = new Color(0.925f, 0f, 0.533f, _transparency); // Calculate the boundaries. var height = style.CalcHeight(content, width) + 30; var bounds = new Rect((Screen.width - width) / 2, Screen.height / 2 - (height / 2), width, height); // Draw the background rectangle. DrawRectangle(bounds); // Draw the label. GUI.Label(bounds, content, style); } }
public override void OnInspectorGUI() { Comment _target = (Comment)this.target; // bool _wordWrap = GUI.skin.textField.wordWrap; // GUI.skin.textField.wordWrap = true; GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(_target.Text), Screen.width); Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, _target.Text, style); if (GUI.changed) { _target.Text = text; } // GUI.skin.textField.wordWrap = _wordWrap; }
public static void InitOnMainThread() { lock (s_mutex) { if (s_mainThread != null) { return; } if (Runtime.IsEditor) { try { GUIStyle style = new GUIStyle(); style.CalcHeight(GUIContent.none, 0); } catch (ArgumentException) { #if LUNAR_DEBUG UnityEngine.Debug.Log("ThreadUtils.Init() is not called on the main thread"); #endif return; } } s_mainThread = Thread.CurrentThread; } }
public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent[] listContent, GUIStyle boxStyle, GUIStyle listStyle) { bool done = false; if (showList) { Rect listRect = new Rect(position.x, position.y, position.width, listStyle.CalcHeight(listContent[0], 1.0f) * listContent.Length); int controlID = GUIUtility.GetControlID(contextMenuHash, FocusType.Passive); switch (Event.current.GetTypeForControl(controlID)) { case EventType.MouseUp: listEntry = getListEntry(Event.current.mousePosition, listRect, listContent.Length); Event.current.Use(); done = true; showList = false; break; } GUI.Box(listRect, "", boxStyle); //Use a selection grid for display purpose only (not for selection functionality) GUI.SelectionGrid(listRect, 0, listContent, 1, listStyle); } return done; }
public static bool List(Rect position, ref bool showList, ref int listEntry, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { int controlID = GUIUtility.GetControlID (popupListHash, FocusType.Passive); bool done = false; switch (Event.current.GetTypeForControl (controlID)) { case EventType.mouseDown: if (position.Contains (Event.current.mousePosition)) { GUIUtility.hotControl = controlID; showList = true; } break; case EventType.mouseUp: if (showList) { done = true; } break; } GUI.Label (position, buttonContent, buttonStyle); if (showList) { Rect listRect = new Rect (position.x, position.y, position.width, listStyle.CalcHeight (listContent [0], 1.0f) * listContent.Length); GUI.Box (listRect, "", boxStyle); listEntry = GUI.SelectionGrid (listRect, listEntry, listContent, 1, listStyle); } if (done) { showList = false; } return done; }
void OnGUI() { if (triggered){ if (timer > UI_DisplayDuration){ triggered = false; timer = 0.0f; } else{ timer += Time.deltaTime; } centeredTextStyle = new GUIStyle("label"); centeredTextStyle.alignment = TextAnchor.MiddleCenter; centeredTextStyle.fontSize = UI_FontSize; UI_Height = (int)(centeredTextStyle.CalcHeight(UI_Content, UI_Width)); if (UI_Location == Location.ABOVE_CHAR){ Vector3 screenPos = Camera.mainCamera.WorldToScreenPoint(player.transform.position); UI_X = (int)(screenPos.x - UI_Width/2); UI_Y = (int)(-screenPos.y + (UI_OffSet * -0.01 * Screen.height) + Screen.height); } else{ // Positioning the UI on the Top or Bottom of the Screen UI_X = Screen.width/2 - UI_Width/2; UI_Y = (UI_Location == Location.TOP) ? UI_OffSet : (Screen.height - UI_OffSet - UI_Height); } GUI.Box (new Rect (UI_X, UI_Y - UI_Height, UI_Width + 5, UI_Height + 5), ""); GUI.Label (new Rect (UI_X, UI_Y - UI_Height, UI_Width + 5, UI_Height + 5), UI_Content.text, centeredTextStyle); } }
public override float GetPropertyHeight (SerializedProperty prop, GUIContent label) { //override height to adjust for word wrapping. GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; return Mathf.Clamp(style.CalcHeight(new GUIContent(prop.stringValue), Screen.width - 34) + 16f, 32f, 128f); }
void OnGUI() { int newTime = secondsUntilTimeout - (int)Time.timeSinceLevelLoad; string text; text = (newTime <= 0) ? postTimerText : preTimerText; //Application.LoadLevel("creditsScene"); int minute = ((int)(newTime / 60)); int second = ((int)(newTime % 60)); string newText = (second < 10) ? (minute.ToString() + ":" + "0" + second.ToString()) : (minute.ToString() + ":" + second.ToString()); UI_Content.text = newText; centeredTextStyle = new GUIStyle("label"); centeredTextStyle.alignment = TextAnchor.MiddleCenter; centeredTextStyle.fontSize = UI_FontSize; centeredTextStyle.normal.textColor = Color.red; UI_Height = (int)(centeredTextStyle.CalcHeight(UI_Content, UI_Width)); UI_X = Screen.width/2 - UI_Width/2; UI_Y = UI_OffSet; GUI.Label (new Rect (UI_X, UI_Y - UI_Height - (UI_OffSet * 0.4f), UI_Width + 5, UI_Height + 5), text, centeredTextStyle); GUI.Label (new Rect (UI_X, UI_Y - UI_Height, UI_Width + 5, UI_Height + 5), UI_Content.text, centeredTextStyle); }
public void CalcGUIContentSize(GUIContent content, GUIStyle style, out float width, out float height) { float minWidth; float maxWidth; //GetPadding(); style.CalcMinMaxWidth(content, out minWidth, out maxWidth); float threshold = 250; if (maxWidth < threshold) { style.wordWrap = false; Vector2 size = style.CalcSize(content); style.wordWrap = true; maxWidth = size.x; } width = Mathf.Clamp(maxWidth, 0, threshold); height = Mathf.Clamp(style.CalcHeight(content, width), 21, 150); //Debug.LogWarning(string.Format("min: {0}, max: {1} => w: {2}, isHeightDependentonwidht: {3}", minWidth, maxWidth, width, style)); //SetPadding(l, t, r, b); }
/// <summary> /// Creates an instance of ExtendedNotification /// </summary> /// <param name="text">The text to display on the notification</param> /// <param name="color">The color of the notification</param> /// <param name="duration">The duration of the notification</param> /// <param name="style">The style of the notification</param> public ExtendedNotification( string text, Color color, float duration, GUIStyle style ) { Text = new GUIContent( text ); Color = color; Duration = duration; style.CalcMinMaxWidth( Text, out Size.y, out Size.x ); Size.y = style.CalcHeight( Text, Size.x ); }
public int List(Rect rect, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { if (forceToUnShow) { forceToUnShow = false; this.isClickedComboButton = false; } bool flag = false; int controlID = GUIUtility.GetControlID(FocusType.Passive); if ((Event.current.GetTypeForControl(controlID) == EventType.MouseUp) && this.isClickedComboButton) { flag = true; } if (GUI.Button(rect, buttonContent, buttonStyle)) { if (useControlID == -1) { useControlID = controlID; this.isClickedComboButton = false; } if (useControlID != controlID) { forceToUnShow = true; useControlID = controlID; } this.isClickedComboButton = true; } if (this.isClickedComboButton) { Rect position = new Rect(rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1f), rect.width, listStyle.CalcHeight(listContent[0], 1f) * listContent.Length); GUI.Box(position, string.Empty, boxStyle); int num2 = GUI.SelectionGrid(position, this.selectedItemIndex, listContent, 1, listStyle); if (num2 != this.selectedItemIndex) { this.selectedItemIndex = num2; } } if (flag) { this.isClickedComboButton = false; } return this.GetSelectedItemIndex(); }
public Vector2 CalcSize(UIDELogEntry entry) { if (entry == null) return new Vector2(0,0); string message = GetMessage(entry); GUIContent content = new GUIContent(message); GUIStyle wordWrapLabel = new GUIStyle(GUI.skin.label); wordWrapLabel.wordWrap = true; float desiredWidth = editor.textEditorRect.width-editor.editorWindow.defaultSkin.verticalScrollbar.fixedWidth*2; float height = wordWrapLabel.CalcHeight(content,desiredWidth); height += GUI.skin.label.margin.top+GUI.skin.label.margin.bottom; GUIStyle noWordWrapStyle = new GUIStyle(GUI.skin.label); noWordWrapStyle.wordWrap = false; Vector2 size = noWordWrapStyle.CalcSize(content); size.x = Mathf.Min(desiredWidth,size.x); size.y = height; size.x += GUI.skin.label.margin.left+GUI.skin.label.margin.right; //size.x += GUI.skin.label.margin.left+GUI.skin.label.margin.right; if (entry.stackItems.Count > 0) { size.y += GUI.skin.label.CalcHeight(new GUIContent("Call Stack"),size.x); size.y += GUI.skin.label.margin.top+GUI.skin.label.margin.bottom; //expandStack = EditorGUILayout.Foldout(expandStack,"Call Stack"); if (expandStack) { for (int i = Mathf.Min(entry.stackItems.Count-1,4-1); i >= 0; i--) { LogStackItem item = entry.stackItems[i]; Vector2 s = GUI.skin.button.CalcSize(new GUIContent(FormatLogStackItem(item))); size.y += s.y; size.y += GUI.skin.button.margin.top+GUI.skin.label.margin.bottom; size.x = Mathf.Max(size.x,s.x); //GUILayout.Button(item.contextString+" "+Path.GetFileName(item.filename)+" "+item.line); } } } string buttonText = "Go there"; size.y += GUI.skin.button.CalcHeight(new GUIContent(buttonText),size.x); size.y += GUI.skin.button.margin.top+GUI.skin.button.margin.bottom; size.x += boxStyle.padding.left+boxStyle.padding.right; size.y += boxStyle.padding.top+boxStyle.padding.bottom; size.x += closeButtonStyle.fixedWidth; size.y = Mathf.Min(size.y,editor.textEditorRect.height-editor.desiredTabBarHeight-editor.editorWindow.defaultSkin.horizontalScrollbar.fixedHeight); return size; }
private void UpdateScrollOffset() { int cursorIndex = this.cursorIndex; graphicalCursorPos = style.GetCursorPixelPosition(new Rect(0f, 0f, position.width, position.height), m_Content, cursorIndex); Rect rect = style.padding.Remove(position); Vector2 vector = style.CalcSize(m_Content); Vector2 vector2 = new Vector2(vector.x, style.CalcHeight(m_Content, position.width)); if (vector2.x < position.width) { scrollOffset.x = 0f; } else if (m_RevealCursor) { if (graphicalCursorPos.x + 1f > scrollOffset.x + rect.width) { scrollOffset.x = graphicalCursorPos.x - rect.width; } if (graphicalCursorPos.x < scrollOffset.x + (float)style.padding.left) { scrollOffset.x = graphicalCursorPos.x - (float)style.padding.left; } } if (vector2.y < rect.height) { scrollOffset.y = 0f; } else if (m_RevealCursor) { if (graphicalCursorPos.y + style.lineHeight > scrollOffset.y + rect.height + (float)style.padding.top) { scrollOffset.y = graphicalCursorPos.y - rect.height - (float)style.padding.top + style.lineHeight; } if (graphicalCursorPos.y < scrollOffset.y + (float)style.padding.top) { scrollOffset.y = graphicalCursorPos.y - (float)style.padding.top; } } if (scrollOffset.y > 0f && vector2.y - scrollOffset.y < rect.height) { scrollOffset.y = vector2.y - rect.height - (float)style.padding.top - (float)style.padding.bottom; } scrollOffset.y = ((!(scrollOffset.y < 0f)) ? scrollOffset.y : 0f); m_RevealCursor = false; }
public GenericMenu() { backgroundStyle = new GUIStyle (GUI.skin.box); backgroundStyle.contentOffset = new Vector2 (2, 2); itemStyle = new GUIStyle (GUI.skin.label); selectedStyle = new GUIStyle (GUI.skin.label); selectedStyle.normal.background = GUIExt.ColorToTex (new Color (0.75f, 0.75f, 0.75f)); expandRight = NodeEditorFramework.NodeEditor.LoadTexture ("Textures/expandRight.png"); itemHeight = itemStyle.CalcHeight (new GUIContent ("text"), 100); seperator = new GUIStyle(); seperator.normal.background = GUIExt.ColorToTex (new Color (0.6f, 0.6f, 0.6f)); seperator.margin = new RectOffset(0, 0, 7, 7); }
static public int CalcHeight(IntPtr l) { try { UnityEngine.GUIStyle self = (UnityEngine.GUIStyle)checkSelf(l); UnityEngine.GUIContent a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); var ret = self.CalcHeight(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
static int CalcHeight(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); UnityEngine.GUIStyle obj = (UnityEngine.GUIStyle)ToLua.CheckObject(L, 1, typeof(UnityEngine.GUIStyle)); UnityEngine.GUIContent arg0 = (UnityEngine.GUIContent)ToLua.CheckObject(L, 2, typeof(UnityEngine.GUIContent)); float arg1 = (float)LuaDLL.luaL_checknumber(L, 3); float o = obj.CalcHeight(arg0, arg1); LuaDLL.lua_pushnumber(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public static void DrawRequiredEngineVersionError(string version) { // Create the label. var text = string.Format("This functionality requires EyeX Engine version {0} or higher.", version); var content = new GUIContent(text); // Create the font style. var style = new GUIStyle(); style.alignment = TextAnchor.MiddleCenter; style.fontSize = 18; style.normal.textColor = new Color(0.953f, 0.569f, 0.039f, 1f); // Calculate the boundaries. var height = style.CalcHeight(content, 700) + 30; var bounds = new Rect((Screen.width - 700) / 2f, Screen.height / 2f - (height / 2), 700, height); // Draw the label. GUI.Label(bounds, content, style); }
protected override void DrawGUI() { if (GameSettings.PlayerActor != null) { GUIStyle inputStyle = new GUIStyle("textfield"); inputStyle.normal.background = null; GUIStyle logStyle = new GUIStyle("textarea"); logStyle.normal.background = null; logStyle.focused.background = null; logStyle.active.background = null; logStyle.hover.background = null; float textHeight = logStyle.CalcHeight(new GUIContent(log), 300); GUI.Box(new Rect(10, GameSettings.UIHeight - 245, 300, 200), ""); GUI.BeginScrollView(new Rect(10, GameSettings.UIHeight - 245, 300, 200), new Vector2(0, float.MaxValue), new Rect(10, GameSettings.UIHeight - 245, 300, textHeight)); GUI.TextArea(new Rect(10, GameSettings.UIHeight - 245, 300, textHeight), log, logStyle); GUI.EndScrollView(); if (Event.current.Equals(Event.KeyboardEvent("return"))) { message = message.Trim(); if (message.Length > 0) { GameSettings.PlayerActor.RaiseEvent<ChatMessage>((ev) => { ev.Message = message; }); } message = ""; } GUI.Box(new Rect(10, GameSettings.UIHeight - 35, 300, 25), ""); message = GUI.TextField(new Rect(10, GameSettings.UIHeight - 35, 300, 25), message, inputStyle); } }
public Vector2 CalcSize(UIDELogEntry entry) { if (entry == null) return new Vector2(0,0); string message = GetMessage(entry); GUIContent content = new GUIContent(message); GUIStyle wordWrapLabel = new GUIStyle(GUI.skin.label); wordWrapLabel.wordWrap = true; float desiredWidth = editor.textEditorRect.width-editor.editorWindow.defaultSkin.verticalScrollbar.fixedWidth*2; float height = wordWrapLabel.CalcHeight(content,desiredWidth); height += GUI.skin.label.margin.top+GUI.skin.label.margin.bottom; GUIStyle noWordWrapStyle = new GUIStyle(GUI.skin.label); noWordWrapStyle.wordWrap = false; Vector2 size = noWordWrapStyle.CalcSize(content); size.x = Mathf.Min(desiredWidth,size.x); size.y = height; size.x += GUI.skin.label.margin.left+GUI.skin.label.margin.right; //size.x += GUI.skin.label.margin.left+GUI.skin.label.margin.right; string buttonText = "Go there"; size.y += GUI.skin.button.CalcHeight(new GUIContent(buttonText),size.x); size.y += GUI.skin.button.margin.top+GUI.skin.button.margin.bottom; size.x += boxStyle.padding.left+boxStyle.padding.right; size.y += boxStyle.padding.top+boxStyle.padding.bottom; size.x += closeButtonStyle.fixedWidth; size.y = Mathf.Min(size.y,editor.textEditorRect.height-editor.desiredTabBarHeight-editor.editorWindow.defaultSkin.horizontalScrollbar.fixedHeight); return size; }
public Vector2 GetSize(IGuiElement element) { if (element == null) { throw new ArgumentNullException("element"); } if (!(element is ITextGuiElement)) { throw new ArgumentException("ExpandText only works on ITextGuiElements", "element"); } if (element.Style == null) { throw new Exception("ExpandText does not work with the built in unity style"); } ITextGuiElement textElement = (ITextGuiElement)element; UnityEngine.GUIStyle unityStyle = textElement.Style.GenerateUnityGuiStyle(); unityStyle.wordWrap = false; GUIContent textContent = new GUIContent(textElement.Text); Vector2 size = unityStyle.CalcSize(textContent); if (size.x > mLineWrapWidth) { size.x = mLineWrapWidth; unityStyle.wordWrap = true; size.y = unityStyle.CalcHeight(textContent, mLineWrapWidth); } size.x += textElement.Style.InternalMargins.Left + textElement.Style.InternalMargins.Right; size.y += textElement.Style.InternalMargins.Top + textElement.Style.InternalMargins.Bottom; return(size); }
public int List( Rect rect, GUIContent buttonContent, GUIContent[] listContent, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle ) { if( forceToUnShow ) { forceToUnShow = false; isClickedComboButton = false; } bool done = false; int controlID = GUIUtility.GetControlID( FocusType.Passive ); switch( Event.current.GetTypeForControl(controlID) ) { case EventType.mouseUp: { if( isClickedComboButton ) { // done = true; } } break; } if( GUI.Button( rect, buttonContent, buttonStyle ) ) { if( useControlID == -1 ) { useControlID = controlID; isClickedComboButton = false; } if( useControlID != controlID ) { forceToUnShow = true; useControlID = controlID; } isClickedComboButton = true; } if( isClickedComboButton ) { float items_height = listStyle.CalcHeight(listContent[0], 1.0f) * (listContent.Length + 5); Rect listRect = new Rect( rect.x, rect.y + listStyle.CalcHeight(listContent[0], 1.0f), rect.width, items_height); scrollViewVector = GUI.BeginScrollView (new Rect (rect.x, rect.y + rect.height, rect.width * 1.4f, 200), scrollViewVector, new Rect (rect.x, rect.y, rect.width, items_height + rect.height), false, false); GUI.Box( new Rect(rect.x, rect.y, rect.width, items_height + rect.height) , "", boxStyle ); int newSelectedItemIndex = GUI.SelectionGrid( listRect, selectedItemIndex, listContent, 1, listStyle ); if( newSelectedItemIndex != selectedItemIndex ) { selectedItemIndex = newSelectedItemIndex; done = true; } GUI.EndScrollView(); } if( done ) isClickedComboButton = false; return GetSelectedItemIndex(); }
// List(Rect(0,0,100,100), false, 0, GUIContent("Select Colour"), listColours "button", "box", generalListStyle) private void List(Rect position, bool expandList, int listEntry, GUIContent defaultListEntry, GUIContent[] listToUse, GUIStyle buttonStyle, GUIStyle boxStyle, GUIStyle listStyle) { int controlID = GUIUtility.GetControlID(dropdownListHash, FocusType.Passive); if(Event.current.GetTypeForControl(controlID) == EventType.mouseDown && (!GlobalVarAdvSearch.dropDownListOpen || bOpen)) { if (position.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = controlID; showList = !showList; if(showList == true) { GlobalVarAdvSearch.dropDownListOpen = true; bOpen = true; } else { GlobalVarAdvSearch.dropDownListOpen = false; bOpen = false; } } } if(Event.current.GetTypeForControl(controlID) == EventType.mouseDown && !position.Contains(Event.current.mousePosition)) { GUIUtility.hotControl = controlID; } GUI.Label(position, defaultListEntry, buttonStyle); if(expandList) { //list rectangle Rect listRect = new Rect(position.x, position.y+20, position.width, listStyle.CalcHeight(listToUse[0], 1.0f) * 7); GUI.Box(listRect, "", boxStyle); GUIContent[] tempArray = new GUIContent[7]; tempArray[0] = new GUIContent("\t\tGo up"); tempArray[6] = new GUIContent("\t\tGo down"); for(int i = 1; i <= 5; i++) { tempArray[i] = listToUse[offset + i - 1]; } listEntrySelected = GUI.SelectionGrid(listRect, listEntrySelected, tempArray, 1, listStyle); if(listEntrySelected != 0 && listEntrySelected != 6 && defaultEntryNumber != (listEntrySelected - 1)) { GUIUtility.hotControl = controlID; defaultEntryNumber = listEntrySelected - 1; selected = defaultEntryNumber + offset; showList = !showList; if(showList == true) { GlobalVarAdvSearch.dropDownListOpen = true; bOpen = true; } else { GlobalVarAdvSearch.dropDownListOpen = false; bOpen = false; } } if(listEntrySelected == 0 && lastEntry != listEntrySelected) { if(offset > 0) { offset--; } lastEntry = listEntrySelected; } if(listEntrySelected == 6 && lastEntry != listEntrySelected) { if(offset < (listToUse.Length - 5)) { offset++; } lastEntry = listEntrySelected; } if(Input.GetMouseButtonDown(0)) { bPress = true; } if(Input.GetMouseButtonUp(0)) { if(bPress) { lastEntry = -1; bPress = false; } } } }
/** * <summary>Draws the element using OnGUI</summary> * <param name = "_style">The GUIStyle to draw with</param> * <param name = "_slot">Ignored by this subclass</param> * <param name = "zoom">The zoom factor</param> * <param name = "isActive">If True, then the element will be drawn as though highlighted</param> */ public override void Display(GUIStyle _style, int _slot, float zoom, bool isActive) { base.Display (_style, _slot, zoom, isActive); _style.wordWrap = true; _style.alignment = anchor; if (zoom < 1f) { _style.fontSize = (int) ((float) _style.fontSize * zoom); } if (Application.isPlaying) { if (labelType == AC_LabelType.DialogueLine) { if (useCharacterColour) { _style.normal.textColor = speechColour; } if (newLabel != "" || updateIfEmpty) { if (sizeType == AC_SizeType.Manual && autoAdjustHeight) { GUIContent content = new GUIContent (newLabel); relativeRect.height = _style.CalcHeight (content, relativeRect.width); } } } } if (textEffects != TextEffects.None) { AdvGame.DrawTextEffect (ZoomRect (relativeRect, zoom), newLabel, _style, Color.black, _style.normal.textColor, 2, textEffects); } else { GUI.Label (ZoomRect (relativeRect, zoom), newLabel, _style); } }
public float GetHelpBoxHeight() { var style = new GUIStyle( "HelpBox" ); var content = new GUIContent( HelpBoxAttribute.Message ); return Mathf.Max( style.CalcHeight( content, Screen.width - ( HelpBoxAttribute.Type != HelpBoxType.None ? 53 : 21) ), 40); }
/// <summary> /// Draw the label's properties. /// </summary> protected override bool ShouldDrawProperties () { mLabel = mWidget as UILabel; GUILayout.BeginHorizontal(); #if DYNAMIC_FONT mFontType = (FontType)EditorGUILayout.EnumPopup(mFontType, "DropDown", GUILayout.Width(74f)); if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(64f))) #else mFontType = FontType.NGUI; if (NGUIEditorTools.DrawPrefixButton("Font", GUILayout.Width(74f))) #endif { if (mFontType == FontType.NGUI) { ComponentSelector.Show<UIFont>(OnNGUIFont); } else { ComponentSelector.Show<Font>(OnUnityFont, new string[] { ".ttf", ".otf" }); } } bool isValid = false; SerializedProperty fnt = null; SerializedProperty ttf = null; if (mFontType == FontType.NGUI) { GUI.changed = false; fnt = NGUIEditorTools.DrawProperty("", serializedObject, "mFont", GUILayout.MinWidth(40f)); if (fnt.objectReferenceValue != null) { if (GUI.changed) serializedObject.FindProperty("mTrueTypeFont").objectReferenceValue = null; NGUISettings.ambigiousFont = fnt.objectReferenceValue; isValid = true; } } else { GUI.changed = false; ttf = NGUIEditorTools.DrawProperty("", serializedObject, "mTrueTypeFont", GUILayout.MinWidth(40f)); if (ttf.objectReferenceValue != null) { if (GUI.changed) serializedObject.FindProperty("mFont").objectReferenceValue = null; NGUISettings.ambigiousFont = ttf.objectReferenceValue; isValid = true; } } GUILayout.EndHorizontal(); if (mFontType == FontType.Unity) { EditorGUILayout.HelpBox("Dynamic fonts suffer from issues in Unity itself where your characters may disappear, get garbled, or just not show at times. Use this feature at your own risk.\n\n" + "When you do run into such issues, please submit a Bug Report to Unity via Help -> Report a Bug (as this is will be a Unity bug, not an NGUI one).", MessageType.Warning); } EditorGUI.BeginDisabledGroup(!isValid); { UIFont uiFont = (fnt != null) ? fnt.objectReferenceValue as UIFont : null; Font dynFont = (ttf != null) ? ttf.objectReferenceValue as Font : null; if (uiFont != null && uiFont.isDynamic) { dynFont = uiFont.dynamicFont; uiFont = null; } if (dynFont != null) { GUILayout.BeginHorizontal(); { EditorGUI.BeginDisabledGroup((ttf != null) ? ttf.hasMultipleDifferentValues : fnt.hasMultipleDifferentValues); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); NGUISettings.fontSize = prop.intValue; prop = NGUIEditorTools.DrawProperty("", serializedObject, "mFontStyle", GUILayout.MinWidth(40f)); NGUISettings.fontStyle = (FontStyle)prop.intValue; NGUIEditorTools.DrawPadding(); EditorGUI.EndDisabledGroup(); } GUILayout.EndHorizontal(); NGUIEditorTools.DrawProperty("Material", serializedObject, "mMaterial"); } else if (uiFont != null) { GUILayout.BeginHorizontal(); SerializedProperty prop = NGUIEditorTools.DrawProperty("Font Size", serializedObject, "mFontSize", GUILayout.Width(142f)); EditorGUI.BeginDisabledGroup(true); if (!serializedObject.isEditingMultipleObjects) { if (mLabel.overflowMethod == UILabel.Overflow.ShrinkContent) GUILayout.Label(" Actual: " + mLabel.finalFontSize + "/" + mLabel.defaultFontSize); else GUILayout.Label(" Default: " + mLabel.defaultFontSize); } EditorGUI.EndDisabledGroup(); NGUISettings.fontSize = prop.intValue; GUILayout.EndHorizontal(); } bool ww = GUI.skin.textField.wordWrap; GUI.skin.textField.wordWrap = true; SerializedProperty sp = serializedObject.FindProperty("mText"); if (sp.hasMultipleDifferentValues) { NGUIEditorTools.DrawProperty("", sp, GUILayout.Height(128f)); } else { GUIStyle style = new GUIStyle(EditorStyles.textField); style.wordWrap = true; float height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 100f); bool offset = true; if (height > 90f) { offset = false; height = style.CalcHeight(new GUIContent(sp.stringValue), Screen.width - 20f); } else { GUILayout.BeginHorizontal(); GUILayout.BeginVertical(GUILayout.Width(76f)); GUILayout.Space(3f); GUILayout.Label("Text"); GUILayout.EndVertical(); GUILayout.BeginVertical(); } Rect rect = EditorGUILayout.GetControlRect(GUILayout.Height(height)); GUI.changed = false; string text = EditorGUI.TextArea(rect, sp.stringValue, style); if (GUI.changed) sp.stringValue = text; if (offset) { GUILayout.EndVertical(); GUILayout.EndHorizontal(); } } GUI.skin.textField.wordWrap = ww; SerializedProperty ov = NGUIEditorTools.DrawPaddedProperty("Overflow", serializedObject, "mOverflow"); NGUISettings.overflowStyle = (UILabel.Overflow)ov.intValue; NGUIEditorTools.DrawPaddedProperty("Alignment", serializedObject, "mAlignment"); if (dynFont != null) NGUIEditorTools.DrawPaddedProperty("Keep crisp", serializedObject, "keepCrispWhenShrunk"); EditorGUI.BeginDisabledGroup(mLabel.bitmapFont != null && mLabel.bitmapFont.packedFontShader); GUILayout.BeginHorizontal(); SerializedProperty gr = NGUIEditorTools.DrawProperty("Gradient", serializedObject, "mApplyGradient", GUILayout.Width(95f)); EditorGUI.BeginDisabledGroup(!gr.hasMultipleDifferentValues && !gr.boolValue); { NGUIEditorTools.SetLabelWidth(30f); NGUIEditorTools.DrawProperty("Top", serializedObject, "mGradientTop", GUILayout.MinWidth(40f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); NGUIEditorTools.SetLabelWidth(50f); GUILayout.Space(79f); NGUIEditorTools.DrawProperty("Bottom", serializedObject, "mGradientBottom", GUILayout.MinWidth(40f)); NGUIEditorTools.SetLabelWidth(80f); } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Effect", GUILayout.Width(76f)); sp = NGUIEditorTools.DrawProperty("", serializedObject, "mEffectStyle", GUILayout.MinWidth(16f)); EditorGUI.BeginDisabledGroup(!sp.hasMultipleDifferentValues && !sp.boolValue); { NGUIEditorTools.DrawProperty("", serializedObject, "mEffectColor", GUILayout.MinWidth(10f)); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); { GUILayout.Label(" ", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mEffectDistance.x", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mEffectDistance.y", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); } } EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); EditorGUI.EndDisabledGroup(); sp = NGUIEditorTools.DrawProperty("Float spacing", serializedObject, "mUseFloatSpacing", GUILayout.Width(100f)); if (!sp.boolValue) { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("Spacing", GUILayout.Width(56f)); NGUIEditorTools.SetLabelWidth(20f); NGUIEditorTools.DrawProperty("X", serializedObject, "mFloatSpacingX", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawProperty("Y", serializedObject, "mFloatSpacingY", GUILayout.MinWidth(40f)); NGUIEditorTools.DrawPadding(); NGUIEditorTools.SetLabelWidth(80f); GUILayout.EndHorizontal(); } NGUIEditorTools.DrawProperty("Max Lines", serializedObject, "mMaxLineCount", GUILayout.Width(110f)); GUILayout.BeginHorizontal(); sp = NGUIEditorTools.DrawProperty("BBCode", serializedObject, "mEncoding", GUILayout.Width(100f)); EditorGUI.BeginDisabledGroup(!sp.boolValue || mLabel.bitmapFont == null || !mLabel.bitmapFont.hasSymbols); NGUIEditorTools.SetLabelWidth(60f); NGUIEditorTools.DrawPaddedProperty("Symbols", serializedObject, "mSymbols"); NGUIEditorTools.SetLabelWidth(80f); EditorGUI.EndDisabledGroup(); GUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); return isValid; }
public override void OnTextEditorGUI(int windowID) { if (mouseOverError != null) { Rect rect = mouseOverRect; rect.y -= editor.doc.scroll.y; rect.y += editor.tabRect.height; rect.x += editor.lineNumberWidth; GUIContent content = new GUIContent(mouseOverError.description); GUIStyle style = new GUIStyle(errorDescriptionStyle); style.wordWrap = true; style.padding.left = style.padding.right; GUIStyle styleNoWordWrap = new GUIStyle(style); styleNoWordWrap.wordWrap = false; rect.width = Mathf.Min(rect.width,styleNoWordWrap.CalcSize(content).x); rect.width += style.padding.left+style.padding.right+4; rect.height = style.CalcHeight(content,rect.width); rect.y += editor.charSize.y; GUI.Box(rect,"",shadowStyle); GUI.Box(rect,"",outlineStyle); GUI.Label(rect,content,style); } }
//show tooptip when a build button is hovered void ShowToolTip(int ID) { //get the tower component first UnitTower[] towerList=BuildManager.GetTowerList(); UnitTower tower=towerList[ID]; //create a new GUIStyle to highlight the tower name with different font size and color GUIStyle tempGUIStyle=new GUIStyle(); tempGUIStyle.fontStyle=FontStyle.Bold; tempGUIStyle.fontSize=16; //create the GUIContent that shows the tower's name string towerName=tower.unitName; GUIContent guiContentTitle=new GUIContent(towerName); //calculate the height required float heightT=tempGUIStyle.CalcHeight(guiContentTitle, 150); //switch to normal guiStyle and calculate the height needed to display cost tempGUIStyle.fontStyle=FontStyle.Normal; int[] cost=tower.GetCost(); float heightC=0; for(int i=0; i<cost.Length; i++){ if(cost[i]>0){ heightC+=25; } } //create a guiContent showing the tower description string towerDesp=tower.GetDescription(); GUIContent guiContent=new GUIContent(""+towerDesp); //calculate the height require to show the tower description float heightD= GUI.skin.GetStyle("Label").CalcHeight(guiContent, 150); //sum up all the height, so the tooltip box size can be known float height=heightT+heightC+heightD+10; //set the tooltip draw position int y=32; int x=5; //if this is a fixed or drag and drop mode, tooltip always appear at bottom left corner instaed of top left corner if(buildMenuType==_BuildMenuType.Fixed || buildMode==_BuildMode.DragNDrop){ y=(int)(Screen.height-height-buildListRect.height-bottomPanelRect.height-2); x=(int)(Mathf.Floor(Input.mousePosition.x/50))*50; } //define the rect then draw the box Rect rect=new Rect(x, y, 160, height); for(int i=0; i<2; i++) GUI.Box(rect, ""); //display all the guiContent assigned ealier GUI.BeginGroup(rect); //show tower name, format it to different text style, size and color tempGUIStyle.fontStyle=FontStyle.Bold; tempGUIStyle.fontSize=16; tempGUIStyle.normal.textColor=new Color(1, 1, 0, 1f); GUI.Label(new Rect(5, 5, 150, heightT), guiContentTitle, tempGUIStyle); //show tower's cost //get the resourceList from GameControl so we have all the information Resource[] rscList=GameControl.GetResourceList(); //loop throught all the resource type in the cost list for(int i=0; i<cost.Length; i++){ //only show it this the cost required something from this type of resource if(cost[i]>0){ //check if the resource type has a icon or not if(rscList[i].icon!=null){ //show the cost with the resource type icon, draw the icon first then the cost value GUI.Label(new Rect(5, 5+heightT+i*20, 25, 25), rscList[i].icon); GUI.Label(new Rect(5+25, 5+heightT+i*20+2, 150, 25), "- "+cost[i].ToString()); } else{ //show the cost with the resource type name GUI.Label(new Rect(5, 5+heightT+i*20, 150, 25), " - "+cost[i].ToString()+rscList[i].name); } } } //show desciption GUI.Label(new Rect(5, 5+heightC+heightT, 150, heightD), guiContent); GUI.EndGroup(); }
public TextBubble(IGuiManager guiManager, string text, Transform worldPointToFollow, Camera camera) { mTweakablesHandler = new TweakablesHandler(mTweakablesPath, this); IgnoreUnusedVariableWarning(mTweakablesHandler); if (guiManager == null) { throw new ArgumentNullException("guiManager"); } mGuiManager = guiManager; XmlGuiFactory loadTextBubble = new XmlGuiFactory(mResourcePath, guiManager); IGuiStyle bubbleStyle = null; IGuiStyle textStyle = null; foreach (IGuiStyle style in loadTextBubble.ConstructAllStyles()) { if (style == null) { continue; } if (style.Name == "TextBubbleStyleWindow") { bubbleStyle = style; } else if (style.Name == "TextBubbleStyleBase") { textStyle = style; } } if (bubbleStyle == null) { throw new Exception("Unable to load TextBubbleStyleWindow from xml file at 'Resources/" + mResourcePath + ".xml'"); } if (textStyle == null) { throw new Exception("Unable to load TextBubbleStyleBase from xml file at 'Resources/" + mResourcePath + ".xml'"); } foreach (IGuiElement element in loadTextBubble.ConstructAllElements()) { if (element is Window && element.Name == "TextBubbleWindow") { mBubbleWindow = (Window)element; } } if (mBubbleWindow == null) { throw new Exception("Unable to load TextBubbleWindow from xml file at 'Resources/" + mResourcePath + ".xml'"); } mFollowWorldSpaceObject = new FollowWorldSpaceObject ( camera, worldPointToFollow, GuiAnchor.BottomLeft, new Vector2(0.0f, 0), // SDN: TODO: make these offsets configurable new Vector3(0.0f, 1.8f, 0.0f) ); guiManager.SetTopLevelPosition ( mBubbleWindow, mFollowWorldSpaceObject ); Textbox bubbleText = mBubbleWindow.SelectSingleElement <Textbox>("**/TextBubbleTextbox"); mBubbleWindow.Style = bubbleStyle; bubbleText.Text = text; Image bubbleImage = mBubbleWindow.SelectSingleElement <Image>("**/TextBubbleImage"); GuiFrame mainFrame = mBubbleWindow.SelectSingleElement <GuiFrame>("**/TextBubbleFrame"); mainFrame.RemoveChildWidget(bubbleImage); // Set the size of the window to be the smallest that draws the entire chat message UnityEngine.GUIStyle unityStyle = bubbleText.Style.GenerateUnityGuiStyle(); unityStyle.wordWrap = false; GUIContent textContent = new GUIContent(text); Vector2 size = unityStyle.CalcSize(textContent); if (size.x > mMaxWidth) { size.x = mMaxWidth; unityStyle.wordWrap = true; size.y = unityStyle.CalcHeight(textContent, mMaxWidth); } if (size.x < mMinWidth) { size.x = mMinWidth; } size.x += mBubbleWindow.Style.InternalMargins.Left + mBubbleWindow.Style.InternalMargins.Right; size.y += mBubbleWindow.Style.InternalMargins.Top + mBubbleWindow.Style.InternalMargins.Bottom; mBubbleWindow.GuiSize = new FixedSize(size); }
internal static string ScrollableTextAreaInternal(Rect position, string text, ref Vector2 scrollPosition, GUIStyle style) { if (Event.current.type == EventType.Layout) return text; int controlId = GUIUtility.GetControlID(EditorGUI.s_TextAreaHash, FocusType.Keyboard, position); float height1 = style.CalcHeight(GUIContent.Temp(text), position.width); Rect rect = new Rect(0.0f, 0.0f, position.width, height1); Vector2 contentOffset = style.contentOffset; if ((double) position.height < (double) rect.height) { Rect position1 = position; position1.width = GUI.skin.verticalScrollbar.fixedWidth; position1.height -= 2f; ++position1.y; position1.x = position.x + position.width - position1.width; position.width -= position1.width; float height2 = style.CalcHeight(GUIContent.Temp(text), position.width); rect = new Rect(0.0f, 0.0f, position.width, height2); if (position.Contains(Event.current.mousePosition) && Event.current.type == EventType.ScrollWheel) { float num = scrollPosition.y + Event.current.delta.y * 10f; scrollPosition.y = Mathf.Clamp(num, 0.0f, rect.height); Event.current.Use(); } scrollPosition.y = GUI.VerticalScrollbar(position1, scrollPosition.y, position.height, 0.0f, rect.height); if (!EditorGUI.s_RecycledEditor.IsEditingControl(controlId)) { style.contentOffset -= scrollPosition; style.Internal_clipOffset = scrollPosition; } else EditorGUI.s_RecycledEditor.scrollOffset.y = scrollPosition.y; } EventType type = Event.current.type; bool changed; string str = EditorGUI.DoTextField(EditorGUI.s_RecycledEditor, controlId, EditorGUI.IndentedRect(position), text, style, (string) null, out changed, false, true, false); if (type != Event.current.type) scrollPosition = EditorGUI.s_RecycledEditor.scrollOffset; style.contentOffset = contentOffset; style.Internal_clipOffset = Vector2.zero; return str; }
protected virtual void DrawFlowchartView(Flowchart flowchart) { Block[] blocks = flowchart.GetComponents<Block>(); foreach (Block block in blocks) { flowchart.scrollViewRect.xMin = Mathf.Min(flowchart.scrollViewRect.xMin, block.nodeRect.xMin - 400); flowchart.scrollViewRect.xMax = Mathf.Max(flowchart.scrollViewRect.xMax, block.nodeRect.xMax + 400); flowchart.scrollViewRect.yMin = Mathf.Min(flowchart.scrollViewRect.yMin, block.nodeRect.yMin - 400); flowchart.scrollViewRect.yMax = Mathf.Max(flowchart.scrollViewRect.yMax, block.nodeRect.yMax + 400); } // Calc rect for script view Rect scriptViewRect = new Rect(0, 0, this.position.width / flowchart.zoom, this.position.height / flowchart.zoom); EditorZoomArea.Begin(flowchart.zoom, scriptViewRect); DrawGrid(flowchart); GLDraw.BeginGroup(scriptViewRect); if (Event.current.button == 0 && Event.current.type == EventType.MouseDown && !mouseOverVariables) { flowchart.selectedBlock = null; if (!EditorGUI.actionKey) { flowchart.ClearSelectedCommands(); } Selection.activeGameObject = flowchart.gameObject; } // The center of the Flowchart depends on the block positions and window dimensions, so we calculate it // here in the FlowchartWindow class and store it on the Flowchart object for use later. CalcFlowchartCenter(flowchart, blocks); // Draw connections foreach (Block block in blocks) { DrawConnections(flowchart, block, false); } foreach (Block block in blocks) { DrawConnections(flowchart, block, true); } GUIStyle windowStyle = new GUIStyle(); windowStyle.stretchHeight = true; BeginWindows(); windowBlockMap.Clear(); for (int i = 0; i < blocks.Length; ++i) { Block block = blocks[i]; float nodeWidthA = nodeStyle.CalcSize(new GUIContent(block.blockName)).x + 10; float nodeWidthB = 0f; if (block.eventHandler != null) { nodeWidthB = nodeStyle.CalcSize(new GUIContent(block.eventHandler.GetSummary())).x + 10; } block.nodeRect.width = Mathf.Max(Mathf.Max(nodeWidthA, nodeWidthB), 120); block.nodeRect.height = 40; if (Event.current.button == 0) { if (Event.current.type == EventType.MouseDrag && dragWindowId == i) { block.nodeRect.x += Event.current.delta.x; block.nodeRect.y += Event.current.delta.y; forceRepaintCount = 6; } else if (Event.current.type == EventType.MouseUp && dragWindowId == i) { Vector2 newPos = new Vector2(block.nodeRect.x, block.nodeRect.y); block.nodeRect.x = startDragPosition.x; block.nodeRect.y = startDragPosition.y; Undo.RecordObject(block, "Node Position"); block.nodeRect.x = newPos.x; block.nodeRect.y = newPos.y; dragWindowId = -1; forceRepaintCount = 6; } } Rect windowRect = new Rect(block.nodeRect); windowRect.x += flowchart.scrollPos.x; windowRect.y += flowchart.scrollPos.y; GUILayout.Window(i, windowRect, DrawWindow, "", windowStyle); GUI.backgroundColor = Color.white; windowBlockMap.Add(block); } EndWindows(); // Draw Event Handler labels foreach (Block block in blocks) { if (block.eventHandler != null) { string handlerLabel = ""; EventHandlerInfoAttribute info = EventHandlerEditor.GetEventHandlerInfo(block.eventHandler.GetType()); if (info != null) { handlerLabel = "<" + info.EventHandlerName + "> "; } GUIStyle handlerStyle = new GUIStyle(EditorStyles.whiteLabel); handlerStyle.wordWrap = true; handlerStyle.margin.top = 0; handlerStyle.margin.bottom = 0; handlerStyle.alignment = TextAnchor.MiddleCenter; Rect rect = new Rect(block.nodeRect); rect.height = handlerStyle.CalcHeight(new GUIContent(handlerLabel), block.nodeRect.width); rect.x += flowchart.scrollPos.x; rect.y += flowchart.scrollPos.y - rect.height; GUI.Label(rect, handlerLabel, handlerStyle); } } // Draw play icons beside all executing blocks if (Application.isPlaying) { foreach (Block b in blocks) { if (b.IsExecuting()) { b.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; b.activeCommand.executingIconTimer = Time.realtimeSinceStartup + Block.executingIconFadeTime; forceRepaintCount = 6; } if (b.executingIconTimer > Time.realtimeSinceStartup) { Rect rect = new Rect(b.nodeRect); rect.x += flowchart.scrollPos.x - 37; rect.y += flowchart.scrollPos.y + 3; rect.width = 34; rect.height = 34; if (!b.IsExecuting()) { float alpha = (b.executingIconTimer - Time.realtimeSinceStartup) / Block.executingIconFadeTime; alpha = Mathf.Clamp01(alpha); GUI.color = new Color(1f, 1f, 1f, alpha); } if (GUI.Button(rect, FungusEditorResources.texPlayBig as Texture, new GUIStyle())) { SelectBlock(flowchart, b); } GUI.color = Color.white; } } } PanAndZoom(flowchart); GLDraw.EndGroup(); EditorZoomArea.End(); }
void DisplayActivity() { ActivityScrollView = EditorGUILayout.BeginScrollView( ActivityScrollView, GUILayout.Height( Screen.height - 325 ) ); { GUIStyle style = new GUIStyle( "Label" ); style.wordWrap = true; style.fixedWidth = Screen.width - 40; for( int i = 0; i < Task.Posts.Count; ++i ) { TodoListTaskPost post = Task.Posts[ i ]; GUIStyle postStyle = new GUIStyle( TodoList.GetHeadlineStyle() ); postStyle.fixedHeight = postStyle.CalcHeight( new GUIContent( post.Text ), Screen.width - 40 ) + 25; EditorGUILayout.BeginVertical( postStyle ); { DisplayActivityPostHeader( post ); if( post.Text != "" ) { style.fixedHeight = style.CalcHeight( new GUIContent( post.Text ), Screen.width - 40 ); EditorGUILayout.SelectableLabel( post.Text, style ); } } EditorGUILayout.EndVertical(); } EditorGUILayout.BeginVertical( TodoList.GetHeadlineStyle() ); { DisplayActivityPostHeader( null, true ); } EditorGUILayout.EndVertical(); } EditorGUILayout.EndScrollView(); }