当前位置: 首页>>代码示例>>C#>>正文


C# GUIStyle.CalcSize方法代码示例

本文整理汇总了C#中UnityEngine.GUIStyle.CalcSize方法的典型用法代码示例。如果您正苦于以下问题:C# GUIStyle.CalcSize方法的具体用法?C# GUIStyle.CalcSize怎么用?C# GUIStyle.CalcSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在UnityEngine.GUIStyle的用法示例。


在下文中一共展示了GUIStyle.CalcSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnGUI

    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;
            }
        }
    }
开发者ID:pmlamotte,项目名称:2Pac,代码行数:33,代码来源:GameStart.cs

示例2: ContentPanel

        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);

        }
开发者ID:li5414,项目名称:UnityFlatEditor,代码行数:15,代码来源:Panels.cs

示例3: Initialize

        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 );
            }
        }
开发者ID:dannisliang,项目名称:ExtendedEditor,代码行数:27,代码来源:ExtendedDialogBox.cs

示例4: CalcGUIContentSize

    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);
    }
开发者ID:azanium,项目名称:PopBloop-Unity,代码行数:25,代码来源:UIBubbleView.cs

示例5: Update

	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();
        }
	}
开发者ID:DoubleDeez,项目名称:heirloom,代码行数:27,代码来源:ChatBubbleController.cs

示例6: DrawPoseError

 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);
     }
 }
开发者ID:randomize,项目名称:VimConfig,代码行数:34,代码来源:AvatarSkeletonDrawer.cs

示例7: DrawColumn

        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;
            }
        }
开发者ID:mildsauce45,项目名称:NowItsOurTurn,代码行数:16,代码来源:PartyStatusPanel.cs

示例8: Title

        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);
            }
        }
开发者ID:li5414,项目名称:UnityFlatEditor,代码行数:26,代码来源:Text.cs

示例9: Awake

    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);
    }
开发者ID:SexySicilianSoprano,项目名称:thegreatdeepblue,代码行数:30,代码来源:LevelLoader.cs

示例10: SetOffset

 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);
 }
开发者ID:muneishik,项目名称:ChatUni,代码行数:8,代码来源:myThirdPersonController.cs

示例11: GetTotalMenuItemSize

        private float GetTotalMenuItemSize(GUIStyle style)
        {
            float size = 0;

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

            return size;
        }
开发者ID:mildsauce45,项目名称:NowItsOurTurn,代码行数:9,代码来源:HorizontalMenu.cs

示例12: DrawText

 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);
 }
开发者ID:lynnhaotran,项目名称:DMAProject-2,代码行数:9,代码来源:AlexUtil.cs

示例13: OnGUI

    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);
    }
开发者ID:pixel-stuff,项目名称:Angry-Beavers-mobile,代码行数:9,代码来源:ScoreGUI.cs

示例14: DrawOnSelection

		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);
				}
			}
		}
开发者ID:ahvdesign,项目名称:Tower-Defense-Q,代码行数:44,代码来源:SelectorFollowTarget.cs

示例15: UpdateText

 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;
     }
 }
开发者ID:DoubleDeez,项目名称:heirloom,代码行数:10,代码来源:ChatBubbleController.cs


注:本文中的UnityEngine.GUIStyle.CalcSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。