CalcSize() public méthode

Calculate the size of some content if it is rendered with this style.

public CalcSize ( GUIContent content ) : Vector2
content GUIContent
Résultat Vector2
Exemple #1
0
    void OnGUI()
    {
        if (showStartingScreen) {
            int height = (int)(Screen.height * .2f);
            GUI.Box(new Rect(0, Screen.height / 2 - height / 2, Screen.width, height),"");

            GUIContent text = new GUIContent("" + ((num == 0) ? "GO" : num + ""));

            GUIStyle watStyle = new GUIStyle(textStyle);
            int x = 0;
            if (currTime < .2f) {
                x = (int)(currTime / .2f * Screen.width / 2 - watStyle.CalcSize(text).x / 2);
            } else if (currTime >= .2f && currTime <= .8f) {
                watStyle.fontSize += (int)(20 - 20*((Mathf.Abs(.5f - currTime))/.3f));
                x = (int)(Screen.width / 2 - watStyle.CalcSize(text).x / 2);
            } else if (currTime > .8f) {
                x = (int)((currTime - .8f) / .2f * Screen.width/2 - watStyle.CalcSize(text).x / 2 + Screen.width /2);
            }
            GUI.Label(new Rect(x, Screen.height / 2 - watStyle.CalcSize(text).y / 2, 100, 100),text, watStyle);

            currTime += Time.realtimeSinceStartup - lastTime;
            lastTime = Time.realtimeSinceStartup;
            if (currTime >= 1f) {
                currTime = 0f;
                num--;
            }

            if (num < 0) {
                showStartingScreen = false;
                Time.timeScale = 1;
            }
        }
    }
Exemple #2
0
        public static void ContentPanel(Vector2 panelOrigin, GUIContent content, GUIStyle style, Color panelColor, PanelStyleOption option)
        {
            var rect = new Rect(panelOrigin, style.CalcSize(content) + new Vector2(75, 20));
            style.alignment = TextAnchor.MiddleLeft;
            
            DrawPanel(rect, panelColor, option);

            var labelrect = new Rect(rect.position + new Vector2(5, 10), style.CalcSize(content));

            content.text = TypographyUtilities.ColoredText(Color.Lerp(panelColor, Color.black, 0.8f), content.text);
            GUI.Label(labelrect, content, style);

            FlatEditor.SpaceActiveLayoutRect(0, rect.height + FlatEditor.MinimumElementSpacing);

        }
    void Awake()
    {
        //Don't want to destroy this
        DontDestroyOnLoad (this);

        //Set singleton
        main = this;

        //Generate Black background Texture
        m_LoadingScreen = TextureGenerator.MakeTexture (Color.black);

        //Assign Screen Rect
        m_ScreenRect = new Rect(0, 0, Screen.width, Screen.height);

        //Set up GUIStyle
        m_LoadingStyle = new GUIStyle();
        m_LoadingStyle.normal.textColor = Color.white;
        m_LoadingStyle.alignment = TextAnchor.MiddleCenter;
        m_LoadingStyle.fontSize = 20;

        //Calculate the label Rect
        Vector2 labelSize = m_LoadingStyle.CalcSize (new GUIContent(m_LoadingMessage));
        float labelWidth = labelSize.x;
        float labelHeight = labelSize.y;

        float xPos = (Screen.width/2) - (labelWidth/2);
        float yPos = (Screen.height/2) - (labelHeight/2);

        m_LabelRect = new Rect(xPos, yPos, labelWidth, labelHeight);
    }
        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 );
            }
        }
Exemple #5
0
        public static void Title(string titleText, Heading heading, bool centered, string secondaryText)
        {
            var style = FlatFonts.LatoBlackStyle((int) heading, centered);
            var content = new GUIContent(titleText);
            var titleRect = GUILayoutUtility.GetRect(content, style);
            GUI.Label(titleRect, TypographyUtilities.ColoredText(FlatEditor.TextColor, titleText), style);

            if (secondaryText != null)
            {
                var subStyle = new GUIStyle(style)
                {
                    font = FlatFonts.Lato,
                    fontSize = Mathf.RoundToInt(style.fontSize*0.85f),
                    alignment = TextAnchor.LowerLeft,
                };
                
                var contentSize = subStyle.CalcSize(new GUIContent(secondaryText));
                var offset = new Vector2(style.CalcSize(content).x, ((int) heading / 10) + 1);
                var subRect = new Rect(titleRect.position + offset, contentSize);


                var lightened = new Color32(125, 125, 125,255);

                GUI.Label(subRect, TypographyUtilities.ColoredText(lightened, secondaryText), subStyle);
            }
        }
    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);
    }
	void Update () {
        if(IsTriggered) {
            if(IsCycling) {
                TextObject.text = ChatText[CycleChatIndex];
                TextObject.fontSize = FontSize;
                GUIStyle style = new GUIStyle();
                style.fontSize = FontSize;
                Canvas.sizeDelta = (style.CalcSize(new GUIContent(ChatText[CycleChatIndex])) + Padding) / 100;
                if(Time.time > CycleNextLineTime) {
                    if(CycleChatIndex == ChatText.Count-1) {
                        if(LoopTrigger) {
                            CycleChatIndex = 0;
                            CycleNextLineTime = Time.time + ChatTextTime;
                        } else {
                            IsCycling = false;
                            gameObject.SetActive(false);
                        }
                    } else {
                        CycleChatIndex++;
                        CycleNextLineTime = Time.time + ChatTextTime;
                    }
                }
            }
        } else {
            UpdateText();
        }
	}
 private static void DrawPoseError(Transform node, Bounds bounds)
 {
     if (Camera.current != null)
     {
         GUIStyle style = new GUIStyle(GUI.skin.label) {
             normal = { textColor = Color.red },
             wordWrap = false,
             alignment = TextAnchor.MiddleLeft
         };
         Vector3 position = node.position;
         Vector3 vector2 = node.position + ((Vector3) (Vector3.up * 0.2f));
         if (node.position.x <= node.root.position.x)
         {
             vector2.x = bounds.min.x;
         }
         else
         {
             vector2.x = bounds.max.x;
         }
         GUIContent content = new GUIContent(node.name);
         Rect rect = HandleUtility.WorldPointToSizedRect(vector2, content, style);
         rect.x += 2f;
         if (node.position.x > node.root.position.x)
         {
             rect.x -= rect.width;
         }
         Handles.BeginGUI();
         rect.y -= style.CalcSize(content).y / 4f;
         GUI.Label(rect, content, style);
         Handles.EndGUI();
         Handles.color = kErrorMessageColor;
         Handles.DrawLine(position, vector2);
     }
 }
        private void DrawColumn(IEnumerable<NameValuePair> column, float x, float y, float width, GUIStyle style)
        {
            foreach (var nvp in column)
            {
                var labelContent = new GUIContent(nvp.Label);
                var valueContent = new GUIContent(nvp.Value);

                var labelSize = style.CalcSize(labelContent);
                var valueSize = style.CalcSize(valueContent);

                UnityEngine.GUI.Label(new Rect(x, y, labelSize.x, labelSize.y), labelContent, style);
                UnityEngine.GUI.Label(new Rect(x + width - valueSize.x, y, valueSize.x, valueSize.y), valueContent, style);

                y += labelSize.y + itemPadding;
            }
        }
 public void SetOffset()
 {
     style = new GUIStyle();
     style.normal.textColor = Color.white;
     style.fontSize = Screen.width/38;
     offset = style.CalcSize(new GUIContent(playerName));
     offset = new Vector3(offset.x,Screen.height / 7);
 }
    void OnGUI()
    {
        GUIStyle myStyle = new GUIStyle();
        myStyle.font = myFont;
        myStyle.normal.textColor = Color.white;
        Vector2 size = myStyle.CalcSize (new GUIContent ("" +beaverKilled));

        GUI.Label(new Rect((Screen.width)/2, ((Screen.height - size.y)/2) + yOffset, size.x, size.y),""+beaverKilled,myStyle);
    }
        private float GetTotalMenuItemSize(GUIStyle style)
        {
            float size = 0;

            foreach (var mi in menuItems)
                size += style.CalcSize(new GUIContent(mi.Label)).x;

            return size;
        }
Exemple #13
0
 public static void DrawText(Vector2 position, string text, int fontSize, Color fontColor, string font)
 {
     GUIStyle style = new GUIStyle();
     style.normal.textColor = fontColor;
     style.fontSize = fontSize;
     style.font = (Font)Resources.Load(font);
     Vector2 size = style.CalcSize(new GUIContent(text));
     GUI.Label(new Rect(position.x, position.y, size.x, size.y), text, style);
 }
		protected void DrawOnSelection(Usable usable, float distance, Selector.Reticle reticle, GUIStyle guiStyle, string defaultUseMessage,
		                               Color inRangeColor, Color outOfRangeColor, TextStyle textStyle, Color textStyleColor) {
			if (usable == null) return;
			if ((usable != lastUsable) || string.IsNullOrEmpty(heading)) {
				lastUsable = usable;
				heading = usable.GetName();
				useMessage = string.IsNullOrEmpty(usable.overrideUseMessage) ? defaultUseMessage : usable.overrideUseMessage;
			}
			GameObject selection = usable.gameObject;
			if (selection != lastSelectionDrawn) {
				selectionHeight = Tools.GetGameObjectHeight(selection);
				selectionHeadingSize = guiStyle.CalcSize(new GUIContent(heading));
				selectionUseMessageSize = guiStyle.CalcSize(new GUIContent(useMessage));
			}

			// Set text color based on distance:
			bool inUseRange = (distance <= usable.maxUseDistance);
			guiStyle.normal.textColor = inUseRange ? inRangeColor : outOfRangeColor;

			// Draw heading:
			Vector3 screenPos = Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * selectionHeight));
			screenPos += offset;
			screenPos = new Vector3(screenPos.x, screenPos.y + selectionUseMessageSize.y + selectionHeadingSize.y, screenPos.z);
			if (screenPos.z < 0) return;
			Rect rect = new Rect(screenPos.x - (selectionHeadingSize.x / 2), (Screen.height - screenPos.y) - (selectionHeadingSize.y / 2), selectionHeadingSize.x, selectionHeadingSize.y);
			UnityGUITools.DrawText(rect, heading, guiStyle, textStyle, textStyleColor);
			
			// Draw use message:
			screenPos = Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * (selectionHeight)));
			screenPos += offset;
			screenPos = new Vector3(screenPos.x, screenPos.y + selectionUseMessageSize.y, screenPos.z);
			rect = new Rect(screenPos.x - (selectionUseMessageSize.x / 2), (Screen.height - screenPos.y) - (selectionUseMessageSize.y / 2), selectionUseMessageSize.x, selectionUseMessageSize.y);
			UnityGUITools.DrawText(rect, useMessage, guiStyle, textStyle, textStyleColor);
			
			// Draw reticle:
			if (reticle != null) {
				Texture2D reticleTexture = inUseRange ? reticle.inRange : reticle.outOfRange;
				if (reticleTexture != null) {
					screenPos = Camera.main.WorldToScreenPoint(selection.transform.position + (Vector3.up * 0.5f * selectionHeight));
					rect = new Rect(screenPos.x - (reticle.width / 2), (Screen.height - screenPos.y) - (reticle.height / 2), reticle.width, reticle.height);
					GUI.Label(rect, reticleTexture);
				}
			}
		}
 void UpdateText() {
     if(ChatTextTime > 0 && ChatText.Count > 0) {
         int chatIndex = (int)(((int)Time.time % (int)(ChatTextTime * ChatText.Count)) / ChatTextTime);
         TextObject.text = ChatText[chatIndex];
         TextObject.fontSize = FontSize;
         GUIStyle style = new GUIStyle();
         style.fontSize = FontSize;
         Canvas.sizeDelta = (style.CalcSize(new GUIContent(ChatText[chatIndex])) + Padding) / 100;
     }
 }
Exemple #16
0
    public void show()
    {
        float fAspectRatioWidth = Screen.width / 1024.0f;
        float fAspectRatioHeight = Screen.height / 768.0f;

        GUIStyle style = new GUIStyle();
        GUIContent content = new GUIContent();
        Vector2 vSize;

        GUI.Box(new Rect(306 * fAspectRatioWidth, 25 * fAspectRatioHeight, 643 * fAspectRatioWidth, 449.5f * fAspectRatioHeight), "Inventory");

        int iColumn = 0;
        int iRow = 0;
        for(int i = 0; i < inventory_list.Count; i++)
        {
            if(GUI.Button(new Rect((331 + iColumn * 85) * fAspectRatioWidth, (75 + iRow * 100) * fAspectRatioHeight, 75 * fAspectRatioWidth, 75 * fAspectRatioHeight), inventory_list[i].texLook))
            {
                if(Solution.get().bSolutionEnabled)
                {
                    Solution.get().insertItem(inventory_list[i].sInformation, inventory_list[i].texLook, inventory_list[i].iSolutionTag);
                }
                else
                {
                    for(int j = 0; j < inventory_list.Count; j++)
                    {
                        inventory_list[j].fDrawLabel = 0.0f; //On click disable all other labels shown
                    }

                    inventory_list[i].fDrawLabel = 10.0f; //Show for 10 seconds
                }
            }

            iColumn++;
            if(iColumn > 6) //0-6; 7 items allowed in one row
            {
                iColumn = 0;
                iRow++;
            }

            if(inventory_list[i].fDrawLabel > 0.0f)
            {
                style.fontSize = (int)(24 * (fAspectRatioWidth + fAspectRatioHeight) / 2);
                style.fontStyle = FontStyle.Bold;
                style.normal.textColor = new Color(1, 1, 1, 1); //White text

                string sText = inventory_list[i].sInformation;
                content.text = sText;

                vSize = style.CalcSize(content);

                GUI.Label(new Rect(512 * fAspectRatioWidth, 384 * fAspectRatioHeight, vSize.x, vSize.y), content, style);

            }
        }
    }
    public static void OnGUI(Rect position, Playable p)
    {
        const string msg = "custom\nfor clips";
        var nodeStyle = new GUIStyle("flow node 6");

        Vector2 sizeNeeded = nodeStyle.CalcSize(new GUIContent(msg));
        if (sizeNeeded.x < position.width && sizeNeeded.y < position.height)
            GUI.Label(position, msg, nodeStyle);
        else
            GUI.Label(position, "", nodeStyle);
    }
Exemple #18
0
    public static void placeTxt(string str, int fontSize, float x, float y, bool black=false)
    {
        GUIContent content = new GUIContent(str);

        GUIStyle style = new GUIStyle();
        style.fontSize = fontSize;
        style.normal.textColor = black ? Color.black : Color.white;

        Vector2 size = style.CalcSize(content);
        GUI.Label(new Rect(x - size.x/2, y - size.y, size.x, size.y), content, style);
    }
Exemple #19
0
    public static void blinkTxt(string str, int fontSize, float x, float y)
    {
        GUIContent content = new GUIContent(str);

        GUIStyle style = new GUIStyle();
        style.fontSize = fontSize;
        style.normal.textColor = new Color(255, 255, 255, Mathf.PingPong(Time.time, 1));

        Vector2 size = style.CalcSize(content);
        GUI.Label(new Rect(x - size.x/2, y - size.y, size.x, size.y), content, style);
    }
Exemple #20
0
 public static void DrawCenteredText(Vector2 offset, string text, int fontSize, Color fontColor, string font)
 {
     GUIStyle style = new GUIStyle();
     style.normal.textColor = fontColor;
     style.fontSize = fontSize;
     style.font = (Font)Resources.Load(font);
     Vector2 size = style.CalcSize(new GUIContent(text));
     Vector2 position = new Vector2(Screen.width, Screen.height) / 2 - size / 2;
     position += offset;
     GUI.Label(new Rect(position.x, position.y, size.x, size.y), text, style);
 }
Exemple #21
0
        public static Vector2 CalculateGlyphSize(string glyphName, int fontSize)
        {
            var style = new GUIStyle(EditorStyles.label)
            {
                fontSize = fontSize,
                font = FlatFonts.FontAwesome,
                alignment = TextAnchor.MiddleCenter,
                richText = true
            };

            return style.CalcSize(new GUIContent(GlyphString(glyphName)));
        }
        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 float CalcColumnHeight(IEnumerable<NameValuePair> column, GUIStyle style)
        {
            if (column == null || !column.Any())
                return 0;

            var totalItemPadding = itemPadding * (column.Count() - 1);
            var itemHeight = 0f;

            foreach (var nvp in column)
                itemHeight += style.CalcSize(new GUIContent(nvp.Label)).y;

            return totalItemPadding + itemHeight;
        }
Exemple #24
0
    public static bool placeBtn(string str, int fontSize, float x, float y)
    {
        GUIContent content = new GUIContent(str);

        GUIStyle style = new GUIStyle();
        style.normal.textColor = Color.white;
        style.alignment = TextAnchor.MiddleCenter;
        //style.wordWrap = true;
        style.fontSize = fontSize;

        Vector2 size = style.CalcSize(content);
        return GUI.Button(new Rect(x - size.x/2, y - size.y, size.x, size.y), content, style);
    }
Exemple #25
0
    private void OnGUI()
    {
        float fAspectRatioWidth = Screen.width / 1024.0f;
        float fAspectRatioHeight = Screen.height / 768.0f;

        GUIStyle style = new GUIStyle();
        GUIContent content = new GUIContent();
        Vector2 vSize;

        if(bShowLabelActor)
        {
            style.fontSize = (int)(48 * (fAspectRatioWidth + fAspectRatioHeight) / 2);
            style.fontStyle = FontStyle.Bold;
            style.normal.textColor = new Color(1, 1, 1, 1); //White text

            string sText = "Press "+sDialogButton.ToUpper()+" to talk!";
            content.text = sText;

            vSize = style.CalcSize(content);

            GUI.Label(new Rect(512 * fAspectRatioWidth, 384 * fAspectRatioHeight, vSize.x, vSize.y), content, style);
        }
        else if(bShowLabelItem)
        {
            style.fontSize = (int)(48 * (fAspectRatioWidth + fAspectRatioHeight) / 2);
            style.fontStyle = FontStyle.Bold;
            style.normal.textColor = new Color(1, 1, 1, 1); //White text

            string sText = "Press "+sItemButton.ToUpper()+" to pick up!";
            content.text = sText;

            vSize = style.CalcSize(content);

            GUI.Label(new Rect(512 * fAspectRatioWidth, 384 * fAspectRatioHeight, vSize.x, vSize.y), content, style);
        }
    }
 static public int CalcSize(IntPtr l)
 {
     try {
         UnityEngine.GUIStyle   self = (UnityEngine.GUIStyle)checkSelf(l);
         UnityEngine.GUIContent a1;
         checkType(l, 2, out a1);
         var ret = self.CalcSize(a1);
         pushValue(l, true);
         pushValue(l, ret);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
 static int CalcSize(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         UnityEngine.GUIStyle   obj  = (UnityEngine.GUIStyle)ToLua.CheckObject(L, 1, typeof(UnityEngine.GUIStyle));
         UnityEngine.GUIContent arg0 = (UnityEngine.GUIContent)ToLua.CheckObject(L, 2, typeof(UnityEngine.GUIContent));
         UnityEngine.Vector2    o    = obj.CalcSize(arg0);
         ToLua.Push(L, o);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Exemple #28
0
    public static void DrawText(string text, Vector2 position, int fontSize, Color color, FontStyle fontStyle)
    {
        // Create the label.
        var content = new GUIContent(text);

        // Create the font style.
        var style = new GUIStyle();
        style.alignment = TextAnchor.MiddleLeft;
        style.fontSize = fontSize;
        style.normal.textColor = color;
        style.fontStyle = fontStyle;

        // Draw the text using a label.
        var size = style.CalcSize(content);
        GUI.Label(new Rect(position.x, position.y, size.x, size.y), content, style);
    }
        public static void VectorImageDataField(string label, VectorImageData targetData, Object targetObject)
        {
            string code = targetData.glyph.unicode;
            string name = targetData.glyph.name;
            Font font = targetData.font;
            GUIStyle iconStyle = new GUIStyle { font = font, fontSize = 16 };

            float offsetH = 0;

            offsetH += 40;
			using (new GUILayout.HorizontalScope())
			{
				EditorGUILayout.PrefixLabel(label);
				EditorGUILayout.LabelField("", GUILayout.MaxWidth(-12f));
				
				if (!string.IsNullOrEmpty(name))
				{
					GUIContent widthLabel = new GUIContent(IconDecoder.Decode(code));
					float widthLabelWidth = iconStyle.CalcSize(widthLabel).x;
					EditorGUILayout.LabelField(widthLabel, iconStyle, GUILayout.MaxWidth(widthLabelWidth));
					widthLabel = new GUIContent(name);
					widthLabelWidth = GUIStyle.none.CalcSize(widthLabel).x;
					EditorGUILayout.LabelField(name, GUILayout.MaxWidth(widthLabelWidth + 4));
					GUILayout.FlexibleSpace();
				}
				else
				{
					EditorGUILayout.LabelField("No icon selected", GUILayout.MaxWidth(96f));
					GUILayout.FlexibleSpace();
				}
				
				if (GUILayout.Button("Pick Icon"))
				{
					VectorImagePickerWindow.Show(targetData, targetObject);
				}
				
				if (!string.IsNullOrEmpty(name))
				{
					if (GUILayout.Button(IconDecoder.Decode(@"\ue14c"), new GUIStyle { font = VectorImageManager.GetIconFont(VectorImageManager.materialDesignIconsFontName), fontSize = 20 }))
					{
						targetData.font = null;
						targetData.glyph = new Glyph();
						EditorUtility.SetDirty(targetObject);
					}
				}
			}
        }
Exemple #30
0
    void adjustForAspect()
    {
        float aspect = (float)Screen.width / Screen.height;
        Vector2 offset = Vector2.zero;
        for (int i = 0; i < texts.Length; ++i) {
            GUIText text = texts[i];
            GUIStyle style = new GUIStyle();
            style.font = text.font;
            style.fontSize = text.fontSize;
            style.fontStyle = text.fontStyle;
            Vector2 size = style.CalcSize(new GUIContent(text.text));

            if (aspect > 1.5f) {
                text.pixelOffset = new Vector2(-Screen.width / 2, Screen.height / 2);
                text.pixelOffset += new Vector2(Screen.width * 0.02f, -Screen.height * 0.05f);
                text.pixelOffset += offset;
                text.fontSize = 36;
                text.alignment = TextAlignment.Left;
                offset += new Vector2(0.0f, -size.y);
                textRoomFactor = 1.0f;
            } else {
                text.pixelOffset = new Vector2(-Screen.width / 2, -Screen.height / 2);
                text.pixelOffset += new Vector2(Screen.width * 0.05f, Screen.height * 0.05f + size.y);
                text.pixelOffset += offset;
                text.fontSize = 30;
                text.alignment = TextAlignment.Center;
                offset += new Vector2(Screen.width * 0.3f, 0.0f);
                textRoomFactor = 0.8f;
            }
        }

        Transform button = quitButton.transform.parent;

        if (textRoomFactor < 1.0f) {
            transform.localScale = fixedScale * textRoomFactor;
            transform.localPosition = fixedPosititon + textRoomFactor * Vector3.up;

            Ray ray = Camera.main.ScreenPointToRay(new Vector3(Screen.width - 40.0f, 40.0f, 0.0f));
            button.position = ray.origin + ray.direction * 7.0f;
        } else {
            transform.localScale = fixedScale;
            transform.localPosition = fixedPosititon + Vector3.right * fixedScale.x * 1.7f;

            Ray ray = Camera.main.ScreenPointToRay(new Vector3(60.0f, 60.0f, 0.0f));
            button.position = ray.origin + ray.direction * 7.0f;
        }
    }
    void OnSceneGUI()
    {
        if(!Application.isPlaying)
            return;
        Handles.BeginGUI();
        serializedObject.Update();
        RobotController robot = (RobotController)target;

        string buffer = "";
        for(int i = 0; i < robot.lines.Count; i++) {
            buffer += robot.lines[i].Trim() + "\n";
        }

        Vector3 pos;
        pos = robot.transform.position;

        Font font = UnityEditor.AssetDatabase.LoadAssetAtPath<Font>("Assets/GUI/Courier.ttf");
        GUIStyle debugStyle = new GUIStyle(GUI.skin.textArea);
        debugStyle.font = font;
        debugStyle.fontSize = 14;
        GUIStyle debugLabelStyle = new GUIStyle(GUI.skin.label);
        debugLabelStyle.font = font;
        debugLabelStyle.fontSize = 14;
        Vector2 size = debugStyle.CalcSize(new GUIContent(buffer));
        size.y -= debugStyle.lineHeight;
        Rect rectangle = new Rect(5, 20, size.x, size.y);

        GUILayout.Window(2, rectangle, (id) => {

            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(size.x)};
            GUILayout.TextArea(buffer, debugStyle, options);

            Battery battery = robot.GetComponentInChildren<Battery>();
            if(battery != null) {

                battery.currentCapacity = GUILayout.HorizontalSlider(battery.currentCapacity, 0, battery.maximumCapacity, options);
                GUILayout.BeginHorizontal(options);
                GUILayout.Label("0", debugLabelStyle);
                GUILayout.Label(battery.currentCapacity + "", debugLabelStyle);
                GUILayout.Label(battery.maximumCapacity + "", debugLabelStyle);
                GUILayout.EndHorizontal();
            }

        }, robot.name);

        Handles.EndGUI();
    }
Exemple #32
0
    /// <summary>
    /// Draw a label.
    /// </summary>
    /// <param name="textArea">The designated area to draw in</param>
    /// <param name="text">The text to draw</param>
    /// <param name="style">The style to draw with</param>
    /// <param name="alignRight">if true, align the text to the right border of the draw area</param>
    /// <returns>The area actualy used for drawing</returns>
    public static Rect DrawLabel(Rect textArea, string text, GUIStyle style, bool alignRight)
    {
        Vector2 textSize = style.CalcSize(new GUIContent(text));

        if (alignRight)
        {
            // Offset the left corner
            textArea.x = textArea.x + textArea.width - textSize.x;
        }

        textArea.width = Mathf.Min(textArea.width, textSize.x);
        textArea.height = Mathf.Min(textArea.height, textSize.y);

        GUI.Label(textArea, text, style);

        return textArea;
    }
Exemple #33
0
        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);
        }
 private GUIGridSizer(GUIContent[] contents, int xCount, GUIStyle buttonStyle, GUILayoutOption[] options) : base(0f, 0f, 0f, 0f, GUIStyle.none)
 {
     this.m_Count  = contents.Length;
     this.m_XCount = xCount;
     this.ApplyStyleSettings(buttonStyle);
     this.ApplyOptions(options);
     if (xCount != 0 && contents.Length != 0)
     {
         float num  = (float)(Mathf.Max(buttonStyle.margin.left, buttonStyle.margin.right) * (this.m_XCount - 1));
         float num2 = (float)(Mathf.Max(buttonStyle.margin.top, buttonStyle.margin.bottom) * (this.rows - 1));
         if (buttonStyle.fixedWidth != 0f)
         {
             this.m_MinButtonWidth = (this.m_MaxButtonWidth = buttonStyle.fixedWidth);
         }
         if (buttonStyle.fixedHeight != 0f)
         {
             this.m_MinButtonHeight = (this.m_MaxButtonHeight = buttonStyle.fixedHeight);
         }
         if (this.m_MinButtonWidth == -1f)
         {
             if (this.minWidth != 0f)
             {
                 this.m_MinButtonWidth = (this.minWidth - num) / (float)this.m_XCount;
             }
             if (this.maxWidth != 0f)
             {
                 this.m_MaxButtonWidth = (this.maxWidth - num) / (float)this.m_XCount;
             }
         }
         if (this.m_MinButtonHeight == -1f)
         {
             if (this.minHeight != 0f)
             {
                 this.m_MinButtonHeight = (this.minHeight - num2) / (float)this.rows;
             }
             if (this.maxHeight != 0f)
             {
                 this.m_MaxButtonHeight = (this.maxHeight - num2) / (float)this.rows;
             }
         }
         if (this.m_MinButtonHeight == -1f || this.m_MaxButtonHeight == -1f || this.m_MinButtonWidth == -1f || this.m_MaxButtonWidth == -1f)
         {
             float num3 = 0f;
             float num4 = 0f;
             foreach (GUIContent content in contents)
             {
                 Vector2 vector = buttonStyle.CalcSize(content);
                 num4 = Mathf.Max(num4, vector.x);
                 num3 = Mathf.Max(num3, vector.y);
             }
             if (this.m_MinButtonWidth == -1f)
             {
                 if (this.m_MaxButtonWidth != -1f)
                 {
                     this.m_MinButtonWidth = Mathf.Min(num4, this.m_MaxButtonWidth);
                 }
                 else
                 {
                     this.m_MinButtonWidth = num4;
                 }
             }
             if (this.m_MaxButtonWidth == -1f)
             {
                 if (this.m_MinButtonWidth != -1f)
                 {
                     this.m_MaxButtonWidth = Mathf.Max(num4, this.m_MinButtonWidth);
                 }
                 else
                 {
                     this.m_MaxButtonWidth = num4;
                 }
             }
             if (this.m_MinButtonHeight == -1f)
             {
                 if (this.m_MaxButtonHeight != -1f)
                 {
                     this.m_MinButtonHeight = Mathf.Min(num3, this.m_MaxButtonHeight);
                 }
                 else
                 {
                     this.m_MinButtonHeight = num3;
                 }
             }
             if (this.m_MaxButtonHeight == -1f)
             {
                 if (this.m_MinButtonHeight != -1f)
                 {
                     this.maxHeight = Mathf.Max(this.maxHeight, this.m_MinButtonHeight);
                 }
                 this.m_MaxButtonHeight = this.maxHeight;
             }
         }
         this.minWidth  = this.m_MinButtonWidth * (float)this.m_XCount + num;
         this.maxWidth  = this.m_MaxButtonWidth * (float)this.m_XCount + num;
         this.minHeight = this.m_MinButtonHeight * (float)this.rows + num2;
         this.maxHeight = this.m_MaxButtonHeight * (float)this.rows + num2;
     }
 }
Exemple #35
0
 private GUIGridSizer(GUIContent[] contents, int xCount, GUIStyle buttonStyle, GUILayoutOption[] options) : base(0f, 0f, 0f, 0f, GUIStyle.none)
 {
     this.m_MinButtonWidth  = -1f;
     this.m_MaxButtonWidth  = -1f;
     this.m_MinButtonHeight = -1f;
     this.m_MaxButtonHeight = -1f;
     this.m_Count           = contents.Length;
     this.m_XCount          = xCount;
     this.ApplyStyleSettings(buttonStyle);
     this.ApplyOptions(options);
     if ((xCount != 0) && (contents.Length != 0))
     {
         float num  = Mathf.Max(buttonStyle.margin.left, buttonStyle.margin.right) * (this.m_XCount - 1);
         float num2 = Mathf.Max(buttonStyle.margin.top, buttonStyle.margin.bottom) * (this.rows - 1);
         if (buttonStyle.fixedWidth != 0f)
         {
             this.m_MinButtonWidth = this.m_MaxButtonWidth = buttonStyle.fixedWidth;
         }
         if (buttonStyle.fixedHeight != 0f)
         {
             this.m_MinButtonHeight = this.m_MaxButtonHeight = buttonStyle.fixedHeight;
         }
         if (this.m_MinButtonWidth == -1f)
         {
             if (base.minWidth != 0f)
             {
                 this.m_MinButtonWidth = (base.minWidth - num) / ((float)this.m_XCount);
             }
             if (base.maxWidth != 0f)
             {
                 this.m_MaxButtonWidth = (base.maxWidth - num) / ((float)this.m_XCount);
             }
         }
         if (this.m_MinButtonHeight == -1f)
         {
             if (base.minHeight != 0f)
             {
                 this.m_MinButtonHeight = (base.minHeight - num2) / ((float)this.rows);
             }
             if (base.maxHeight != 0f)
             {
                 this.m_MaxButtonHeight = (base.maxHeight - num2) / ((float)this.rows);
             }
         }
         if (((this.m_MinButtonHeight == -1f) || (this.m_MaxButtonHeight == -1f)) || ((this.m_MinButtonWidth == -1f) || (this.m_MaxButtonWidth == -1f)))
         {
             float a    = 0f;
             float num4 = 0f;
             foreach (GUIContent content in contents)
             {
                 Vector2 vector = buttonStyle.CalcSize(content);
                 num4 = Mathf.Max(num4, vector.x);
                 a    = Mathf.Max(a, vector.y);
             }
             if (this.m_MinButtonWidth == -1f)
             {
                 if (this.m_MaxButtonWidth != -1f)
                 {
                     this.m_MinButtonWidth = Mathf.Min(num4, this.m_MaxButtonWidth);
                 }
                 else
                 {
                     this.m_MinButtonWidth = num4;
                 }
             }
             if (this.m_MaxButtonWidth == -1f)
             {
                 if (this.m_MinButtonWidth != -1f)
                 {
                     this.m_MaxButtonWidth = Mathf.Max(num4, this.m_MinButtonWidth);
                 }
                 else
                 {
                     this.m_MaxButtonWidth = num4;
                 }
             }
             if (this.m_MinButtonHeight == -1f)
             {
                 if (this.m_MaxButtonHeight != -1f)
                 {
                     this.m_MinButtonHeight = Mathf.Min(a, this.m_MaxButtonHeight);
                 }
                 else
                 {
                     this.m_MinButtonHeight = a;
                 }
             }
             if (this.m_MaxButtonHeight == -1f)
             {
                 if (this.m_MinButtonHeight != -1f)
                 {
                     base.maxHeight = Mathf.Max(base.maxHeight, this.m_MinButtonHeight);
                 }
                 this.m_MaxButtonHeight = base.maxHeight;
             }
         }
         base.minWidth  = (this.m_MinButtonWidth * this.m_XCount) + num;
         base.maxWidth  = (this.m_MaxButtonWidth * this.m_XCount) + num;
         base.minHeight = (this.m_MinButtonHeight * this.rows) + num2;
         base.maxHeight = (this.m_MaxButtonHeight * this.rows) + num2;
     }
 }
Exemple #36
0
        private GUIGridSizer(GUIContent[] contents, int xCount, GUIStyle buttonStyle, GUILayoutOption[] options) : base(0, 0, 0, 0, GUIStyle.none)
        {
            m_Count  = contents.Length;
            m_XCount = xCount;

            // Most settings comes from the button style (can we stretch, etc). Hence, I apply the style here
            ApplyStyleSettings(buttonStyle);

            // We can have custom options coming from userland. We apply this last so it overrides
            ApplyOptions(options);

            if (xCount == 0 || contents.Length == 0)
            {
                return;
            }

            // internal horizontal spacing
            float totalHorizSpacing = Mathf.Max(buttonStyle.margin.left, buttonStyle.margin.right) * (m_XCount - 1);
            //          Debug.Log (String.Format ("margins: {0}, {1}   totalHoriz: {2}", buttonStyle.margin.left, buttonStyle.margin.right, totalHorizSpacing));
            // internal horizontal margins
            float totalVerticalSpacing = Mathf.Max(buttonStyle.margin.top, buttonStyle.margin.bottom) * (rows - 1);


            // Handle fixedSize buttons
            if (buttonStyle.fixedWidth != 0)
            {
                m_MinButtonWidth = m_MaxButtonWidth = buttonStyle.fixedWidth;
            }
            //          Debug.Log ("buttonStyle.fixedHeight " + buttonStyle.fixedHeight);
            if (buttonStyle.fixedHeight != 0)
            {
                m_MinButtonHeight = m_MaxButtonHeight = buttonStyle.fixedHeight;
            }

            // Apply GUILayout.Width/Height/whatever properties.
            if (m_MinButtonWidth == -1)
            {
                if (minWidth != 0)
                {
                    m_MinButtonWidth = (minWidth - totalHorizSpacing) / m_XCount;
                }
                if (maxWidth != 0)
                {
                    m_MaxButtonWidth = (maxWidth - totalHorizSpacing) / m_XCount;
                }
            }

            if (m_MinButtonHeight == -1)
            {
                if (minHeight != 0)
                {
                    m_MinButtonHeight = (minHeight - totalVerticalSpacing) / rows;
                }
                if (maxHeight != 0)
                {
                    m_MaxButtonHeight = (maxHeight - totalVerticalSpacing) / rows;
                }
            }
            //          Debug.Log (String.Format ("minButtonWidth {0}, maxButtonWidth {1}, minButtonHeight {2}, maxButtonHeight{3}", minButtonWidth, maxButtonWidth, minButtonHeight, maxButtonHeight));

            // if anything is left unknown, we need to iterate over all elements and figure out the sizes.
            if (m_MinButtonHeight == -1 || m_MaxButtonHeight == -1 || m_MinButtonWidth == -1 || m_MaxButtonWidth == -1)
            {
                // figure out the max size. Since the buttons are in a grid, the max size determines stuff.
                float calcHeight = 0, calcWidth = 0;
                foreach (GUIContent i in contents)
                {
                    Vector2 size = buttonStyle.CalcSize(i);
                    calcWidth  = Mathf.Max(calcWidth, size.x);
                    calcHeight = Mathf.Max(calcHeight, size.y);
                }

                // If the user didn't supply minWidth, we need to calculate that
                if (m_MinButtonWidth == -1)
                {
                    // if the user has supplied a maxButtonWidth, the buttons can never get larger.
                    if (m_MaxButtonWidth != -1)
                    {
                        m_MinButtonWidth = Mathf.Min(calcWidth, m_MaxButtonWidth);
                    }
                    else
                    {
                        m_MinButtonWidth = calcWidth;
                    }
                }

                // If the user didn't supply maxWidth, we need to calculate that
                if (m_MaxButtonWidth == -1)
                {
                    // if the user has supplied a minButtonWidth, the buttons can never get smaller.
                    if (m_MinButtonWidth != -1)
                    {
                        m_MaxButtonWidth = Mathf.Max(calcWidth, m_MinButtonWidth);
                    }
                    else
                    {
                        m_MaxButtonWidth = calcWidth;
                    }
                }

                // If the user didn't supply minWidth, we need to calculate that
                if (m_MinButtonHeight == -1)
                {
                    // if the user has supplied a maxButtonWidth, the buttons can never get larger.
                    if (m_MaxButtonHeight != -1)
                    {
                        m_MinButtonHeight = Mathf.Min(calcHeight, m_MaxButtonHeight);
                    }
                    else
                    {
                        m_MinButtonHeight = calcHeight;
                    }
                }

                // If the user didn't supply maxWidth, we need to calculate that
                if (m_MaxButtonHeight == -1)
                {
                    // if the user has supplied a minButtonWidth, the buttons can never get smaller.
                    if (m_MinButtonHeight != -1)
                    {
                        maxHeight = Mathf.Max(maxHeight, m_MinButtonHeight);
                    }
                    m_MaxButtonHeight = maxHeight;
                }
            }
            // We now know the button sizes. Calculate min & max values from that
            minWidth  = m_MinButtonWidth * m_XCount + totalHorizSpacing;
            maxWidth  = m_MaxButtonWidth * m_XCount + totalHorizSpacing;
            minHeight = m_MinButtonHeight * rows + totalVerticalSpacing;
            maxHeight = m_MaxButtonHeight * rows + totalVerticalSpacing;
            //          Debug.Log (String.Format ("minWidth {0}, maxWidth {1}, minHeight {2}, maxHeight{3}", minWidth, maxWidth, minHeight, maxHeight));
        }
Exemple #37
0
        public static int Toolbar(int selected, GUIContent[] contents, bool[] enabled, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle gUIStyle;
            GUIStyle gUIStyle2;
            GUIStyle gUIStyle3;

            GUI.FindStyles(ref style, out gUIStyle, out gUIStyle2, out gUIStyle3, "left", "mid", "right");
            Vector2  vector    = default(Vector2);
            int      num       = contents.Length;
            GUIStyle gUIStyle4 = (num > 1) ? gUIStyle : style;
            GUIStyle gUIStyle5 = (num > 1) ? gUIStyle2 : style;
            GUIStyle gUIStyle6 = (num > 1) ? gUIStyle3 : style;
            float    num2      = 0f;

            for (int i = 0; i < contents.Length; i++)
            {
                bool flag = i == num - 2;
                if (flag)
                {
                    gUIStyle5 = gUIStyle6;
                }
                Vector2 vector2 = gUIStyle4.CalcSize(contents[i]);
                if (buttonSize != GUI.ToolbarButtonSize.Fixed)
                {
                    if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                    {
                        vector.x += vector2.x;
                    }
                }
                else
                {
                    bool flag2 = vector2.x > vector.x;
                    if (flag2)
                    {
                        vector.x = vector2.x;
                    }
                }
                bool flag3 = vector2.y > vector.y;
                if (flag3)
                {
                    vector.y = vector2.y;
                }
                bool flag4 = i == num - 1;
                if (flag4)
                {
                    num2 += (float)gUIStyle4.margin.right;
                }
                else
                {
                    num2 += (float)Mathf.Max(gUIStyle4.margin.right, gUIStyle5.margin.left);
                }
                gUIStyle4 = gUIStyle5;
            }
            if (buttonSize != GUI.ToolbarButtonSize.Fixed)
            {
                if (buttonSize == GUI.ToolbarButtonSize.FitToContents)
                {
                    vector.x += num2;
                }
            }
            else
            {
                vector.x = vector.x * (float)contents.Length + num2;
            }
            return(GUI.Toolbar(GUILayoutUtility.GetRect(vector.x, vector.y, style, options), selected, contents, null, style, buttonSize, enabled));
        }
Exemple #38
0
        // Make a toolbar
        public static int Toolbar(int selected, GUIContent[] contents, GUIStyle style, GUI.ToolbarButtonSize buttonSize, params GUILayoutOption[] options)
        {
            GUIStyle firstStyle, midStyle, lastStyle;

            GUI.FindStyles(ref style, out firstStyle, out midStyle, out lastStyle, "left", "mid", "right");

            Vector2  size         = new Vector2();
            int      count        = contents.Length;
            GUIStyle currentStyle = count > 1 ? firstStyle : style;
            GUIStyle nextStyle    = count > 1 ? midStyle : style;
            GUIStyle endStyle     = count > 1 ? lastStyle : style;
            float    margins      = 0;

            for (int i = 0; i < contents.Length; i++)
            {
                if (i == count - 2)
                {
                    nextStyle = endStyle;
                }

                Vector2 thisSize = currentStyle.CalcSize(contents[i]);
                switch (buttonSize)
                {
                case GUI.ToolbarButtonSize.Fixed:
                    if (thisSize.x > size.x)
                    {
                        size.x = thisSize.x;
                    }
                    break;

                case GUI.ToolbarButtonSize.FitToContents:
                    size.x += thisSize.x;
                    break;
                }

                if (thisSize.y > size.y)
                {
                    size.y = thisSize.y;
                }

                // add spacing
                if (i == count - 1)
                {
                    margins += currentStyle.margin.right;
                }
                else
                {
                    margins += Mathf.Max(currentStyle.margin.right, nextStyle.margin.left);
                }

                currentStyle = nextStyle;
            }

            switch (buttonSize)
            {
            case GUI.ToolbarButtonSize.Fixed:
                size.x = size.x * contents.Length + margins;
                break;

            case GUI.ToolbarButtonSize.FitToContents:
                size.x += margins;
                break;
            }

            return(GUI.Toolbar(GUILayoutUtility.GetRect(size.x, size.y, style, options), selected, contents, style, buttonSize));
        }
Exemple #39
0
        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);
        }
        private void OnGUI()
        {
            if (whiteStyle == null)
            {
                whiteStyle = new GUIStyle();
                Texture2D img    = new Texture2D(2, 2);
                Color[]   colors = new Color[img.width * img.height];
                for (int i = 0; i < colors.Length; i++)
                {
                    colors[i] = Color.white;
                }
                img.SetPixels(colors);
                img.Apply();
                whiteStyle.normal.background = img;
            }

            if (colorButtonStyle == null)
            {
                colorButtonStyle = new GUIStyle("button");
                colorButtonStyle.normal.background = whiteStyle.normal.background;
                colorButtonStyle.active.background = whiteStyle.normal.background;
                colorButtonStyle.hover.background  = whiteStyle.normal.background;
            }
            if (labelStyle == null)
            {
                labelStyle = new GUIStyle("label");
                labelStyle.normal.textColor = progressMsgColor;
                labelStyle.alignment        = TextAnchor.MiddleCenter;
            }

            Rect rect = new Rect(progressRect);

            rect.x      *= Screen.width;
            rect.y      *= Screen.height;
            rect.width  *= Screen.width;
            rect.height *= Screen.height;

            GUI.Box(new Rect(0, 0, Screen.width, Screen.height), GUIContent.none, whiteStyle);
            GUI.backgroundColor = progressBackgroundColor;
            GUI.Box(rect, GUIContent.none, whiteStyle);
            GUI.backgroundColor = progressForegroundColor;
            GUI.Box(new Rect(rect.x, rect.y, rect.width * progress, rect.height), GUIContent.none, whiteStyle);
            GUI.backgroundColor = Color.white;


            string msg = "", progressText = "";
            string versionStr = "";

            if (!string.IsNullOrEmpty(versionFormat) && AssetBundles.Version != null)
            {
                versionStr = versionFormat.FormatStringWithKey(formatValues);
            }

            switch (AssetBundles.Status)
            {
            case AssetBundleStatus.Downloading:
                if (!string.IsNullOrEmpty(downloadMsgFormat) && AssetBundles.DownloadTotal > 0)
                {
                    msg          = downloadMsgFormat.FormatStringWithKey(formatValues);
                    progressText = downloadProgressFormat.FormatStringWithKey(formatValues);
                }
                break;

            case AssetBundleStatus.Preloading:
                if (!string.IsNullOrEmpty(preloadMsgFormat) && AssetBundles.PreloadedTotal > 0)
                {
                    msg          = preloadMsgFormat.FormatStringWithKey(formatValues);
                    progressText = preloadProgressFormat.FormatStringWithKey(formatValues);
                }
                break;

            case AssetBundleStatus.Error:
                msg = downloadErrorMsg;
                break;
            }

            Vector2 size = labelStyle.CalcSize(new GUIContent(versionStr));

            GUI.Label(new Rect(rect.x, rect.y - size.y, size.x, size.y), versionStr, labelStyle);

            using (new GUILayout.AreaScope(rect, GUIContent.none))
                using (new GUILayout.HorizontalScope())
                {
                    GUILayout.FlexibleSpace();
                    GUILayout.Label(msg, labelStyle, GUILayout.ExpandWidth(false), GUILayout.Height(rect.height));
                    GUILayout.FlexibleSpace();

                    if (AssetBundles.Status == AssetBundleStatus.None || AssetBundles.Status == AssetBundleStatus.Error)
                    {
                        GUI.backgroundColor = retryButtonBackgroundColor;
                        if (GUILayout.Button(retryButtonText, colorButtonStyle, GUILayout.ExpandWidth(false), GUILayout.Height(rect.height)))
                        {
                            AssetBundles.InitializeAsync();
                        }
                        GUI.backgroundColor = Color.white;
                    }
                    else
                    {
                        GUILayout.Label(progressText, labelStyle, GUILayout.ExpandWidth(false), GUILayout.Height(rect.height));
                    }
                }
        }