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


C# GUIStyle.CalcHeight方法代码示例

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


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

示例1: List

    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();
    }
开发者ID:gato0429,项目名称:GlobalGame2016,代码行数:60,代码来源:uteComboBox.cs

示例2: CalculateHeight

        /// <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;
        }
开发者ID:phicuong08,项目名称:memorymatch,代码行数:39,代码来源:TextFormatting.cs

示例3: MakeWindow

    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");
            }
        }
    }
开发者ID:hunvil,项目名称:ConvergeGame_Client,代码行数:50,代码来源:Chat.cs

示例4: OnInspectorGUI

		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;
		
		}
开发者ID:OmegaDEVAU,项目名称:Simulator,代码行数:25,代码来源:CommentInspector.cs

示例5: 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

示例6: OnGUI

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

示例7: 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

示例8: OnGUI

	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);
		}	
	}
开发者ID:etang4,项目名称:GGJ2016,代码行数:35,代码来源:Instructions.cs

示例9: InitOnMainThread

        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;
            }
        }
开发者ID:mswf,项目名称:game-a-week,代码行数:29,代码来源:ThreadUtils.cs

示例10: List

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

示例11: List

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

示例12: OnGUI

    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);
        }
    }
开发者ID:n8fern,项目名称:Toy-Hell,代码行数:32,代码来源:TriggerBox.cs

示例13: GetPropertyHeight

	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);
	}
开发者ID:jawadmn,项目名称:Roll-the-Ball,代码行数:7,代码来源:TextBlockPropertyDrawer.cs

示例14: ExtendedNotification

        /// <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 );
        }
开发者ID:Miguel-Barreiro,项目名称:ExtendedEditor,代码行数:16,代码来源:ExtendedNotification.cs

示例15: List

 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();
 }
开发者ID:Lessica,项目名称:Something-of-SHIPWAR-GAMES,代码行数:43,代码来源:ComboBox.cs


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