本文整理汇总了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;
}
}
}
示例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);
}
示例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 );
}
}
示例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);
}
示例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();
}
}
示例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);
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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;
}
}