本文整理汇总了C#中UnityEngine.GUIStyle.CalcMinMaxWidth方法的典型用法代码示例。如果您正苦于以下问题:C# GUIStyle.CalcMinMaxWidth方法的具体用法?C# GUIStyle.CalcMinMaxWidth怎么用?C# GUIStyle.CalcMinMaxWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.GUIStyle
的用法示例。
在下文中一共展示了GUIStyle.CalcMinMaxWidth方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例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;
}
示例3: 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 );
}
示例4: DrawHoverInfo
//.........这里部分代码省略.........
int height=160;
int h_offset = 20;
//get pos X and Y once every second to prevent flicker
getMousePos();
/*for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width+w_offset)/2, posY-230, width+w_offset, height), "");
style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter;
GUI.Label(new Rect(posX-width/2, posY-240, width, height), ability.name, style);
style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight;
GUI.Label(new Rect(posX-width/2-5, posY-240, width, height), ability.cost+"AP", style);
style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true;
GUI.Label(new Rect(posX-width/2, posY-190, width, height), ability.desp, style);
GUI.color=Color.white;*/
//for(int i=0; i<3; i++) GUI.Box(new Rect(posX-(width +w_offset)/2, posY, width+w_offset, height), "");
GUI.Box(new Rect(posX-(width/2)/2, Screen.height-posY+40, width/2, height-20), ""); // to remove flicker comment out this line
style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter;
GUI.Label(new Rect(posX-(width)/2, Screen.height-posY+40+h_offset, width, height), "Attack", style);
if(cost>0){
style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight;
GUI.Label(new Rect(posX-width/2-5, Screen.height-posY+50+h_offset, width, height), cost+"AP", style);
}
//reposition to be at location of mouse
style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true;
GUI.Label(new Rect(posX-width/2, Screen.height-posY+60+h_offset, width, height), text, style);
if(counter){
style.fontSize=14; style.normal.textColor=UI.colorH; style.wordWrap=false;
GUI.Label(new Rect(posX-width/2, Screen.height-posY+40+h_offset, width, height), "Target will counter attack", style);
}
#else
int width=500;
int height=160;
for(int i=0; i<3; i++) GUI.Box(new Rect(Screen.width/2-width/2, Screen.height-230, width, height), "");
style.fontSize=20; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperCenter;
GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-240, width, height), "Attack", style);
if(cost>0){
style.fontSize=16; style.normal.textColor=UI.colorH; style.alignment=TextAnchor.UpperRight;
GUI.Label(new Rect(Screen.width/2-width/2-5, Screen.height-220, width, height), cost+"AP", style);
}
//reposition to be at location of mouse
style.fontSize=16; style.normal.textColor=UI.colorN; style.alignment=TextAnchor.UpperCenter; style.wordWrap=true;
GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-190, width, height), text, style);
if(counter){
style.fontSize=14; style.normal.textColor=UI.colorH; style.wordWrap=false;
GUI.Label(new Rect(Screen.width/2-width/2, Screen.height-120, width, height), "Target will counter attack", style);
}
#endif
GUI.color=Color.white;
}
else{
if(tileHovered.walkableToSelected && selectedUnit!=null){
//Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos);
//hoverObject.transform.localPosition=screenPos+new Vector3(-40, 40, 0);
List<Vector3> list=AStar.SearchWalkablePos(tileHovered, selectedUnit.occupiedTile);
int dist=list.Count;
string text="Move: "+(dist*selectedUnit.APCostMove)+"AP";
//string text="Move: "+Random.Range(0, 9999)+"AP";
GUIContent cont=new GUIContent(text);
GUI.color=Color.white;
GUIStyle style=new GUIStyle();
style.fontStyle=FontStyle.Bold;
style.fontSize=16;
style.normal.textColor=UI.colorN;
style.alignment=TextAnchor.LowerRight;
Camera cam=CameraControl.GetActiveCamera();
Vector3 screenPos = cam.WorldToScreenPoint(tileHovered.pos);
screenPos.y=Screen.height-screenPos.y;
float widthMin=0; float widthMax=0;
style.CalcMinMaxWidth(cont, out widthMin, out widthMax);
#if ibox
#else
GUI.Box(new Rect(screenPos.x-widthMax-50, screenPos.y-50, widthMax+25, 22), "");
GUI.Label(new Rect(screenPos.x-widthMax-50, screenPos.y-50, widthMax+25-4, 20), text, style);
#endif
}
}
}
示例5: DrawAlarmLine
//.........这里部分代码省略.........
// strTextToDisplay = strTextToDisplay.Remove(strTextToDisplay.Length - 2);
// KACResources.styleAlarmText.CalcMinMaxWidth(new GUIContent(strTextToDisplay), out fOutMin, out fOutMax);
//}
////String strLabelText = strTextToDisplay + strTimeToAlarm;
//String strTimeText = String.Format("({0})", KerbalTime.PrintInterval(tmpAlarm.Remaining, Settings.TimeFormat));
//String strLabelText = tmpAlarm.Name;
//GUIStyle styleLabel = new GUIStyle(KACResources.styleAlarmText);
//if ((!tmpAlarm.Enabled || tmpAlarm.Actioned))
// styleLabel.normal.textColor=Color.gray;
//GUIStyle styleTime = new GUIStyle(styleLabel);
//styleTime.stretchWidth = true;
//GUIContent contAlarmLabel = new GUIContent(strLabelText, tmpAlarm.Notes);
//GUIContent contAlarmTime = new GUIContent(strTimeText, tmpAlarm.Notes);
////calc correct width for first part
//KACResources.styleAlarmText.CalcMinMaxWidth(contAlarmTime, out fOutMin, out fOutMax);
//styleLabel.CalcMinMaxWidth(contAlarmLabel, out fOutMin1, out fOutMax1);
//int intMaxWidth = intTestheight;
//if (fOutMax1 + fOutMax > intMaxWidth)
// fOutMax1 = intMaxWidth - fOutMax;
//if ((alarmEdit == tmpAlarm) && _ShowEditPane)
//{
// intMaxWidth -= 20;
//}
//float width1 = fOutMin1;
String strLabelText = "";
strLabelText = String.Format("{0} ({1})", tmpAlarm.Name, KACTime.PrintInterval(tmpAlarm.Remaining, Settings.TimeFormat));
GUIStyle styleLabel = new GUIStyle( KACResources.styleAlarmText);
if ((!tmpAlarm.Enabled || tmpAlarm.Actioned))
styleLabel.normal.textColor=Color.gray;
GUIContent contAlarmLabel = new GUIContent(strLabelText, tmpAlarm.Notes);
//Calc the line height
////////////////////////////////////////////////////
//Currently the max width doesnt work out when an alarm is in edit mode correctly in edit mode
//Also need to test max list length and when the scrollbar kicks in
///////////////////////////////////////////////////
Single sOutMin1,sOutMax1;
styleLabel.CalcMinMaxWidth(contAlarmLabel,out sOutMin1, out sOutMax1);
tmpAlarm.AlarmLineWidth = Convert.ToInt32(sOutMax1);
Int32 intMaxwidth = 220;// 228;
if (_ShowEditPane && (alarmEdit == tmpAlarm)) intMaxwidth = 198;// 216;
tmpAlarm.AlarmLineHeight = Convert.ToInt32(styleLabel.CalcHeight(contAlarmLabel, intMaxwidth));
//Draw a button that looks like a label.
if (GUILayout.Button(contAlarmLabel, styleLabel, GUILayout.MaxWidth(218)))
{
if (!_ShowSettings)
{
if (alarmEdit == tmpAlarm)
{
//If there was an alarm open, then save em again
if (_ShowEditPane) Settings.Save();
_ShowEditPane = !_ShowEditPane;
}
else
{
//If there was an alarm open, then save em again
if (_ShowEditPane) Settings.Save();
alarmEdit = tmpAlarm;
_ShowEditPane = true;
_ShowSettings = false;
_ShowAddPane = false;
}
}
}
if ((alarmEdit == tmpAlarm) && _ShowEditPane)
{
GUILayout.Label(new GUIContent(KACResources.iconEdit, "Editing..."), KACResources.styleLabelWarp);
}
if (tmpAlarm.PauseGame)
{
GUILayout.Label(new GUIContent(KACResources.GetPauseListIcon(tmpAlarm.WarpInfluence),"Pause"), KACResources.styleLabelWarp);
}
else if (tmpAlarm.HaltWarp)
{
GUILayout.Label(new GUIContent(KACResources.GetWarpListIcon(tmpAlarm.WarpInfluence), "Kill Warp"), KACResources.styleLabelWarp);
}
else
{
GUILayout.Label(new GUIContent(KACResources.iconNone), KACResources.styleLabelWarp);
}
if (GUILayout.Button(new GUIContent(KACResources.btnRedCross,"Delete Alarm"), GUI.skin.button, GUILayout.MaxWidth(20), GUILayout.MaxHeight(20)))
blnReturn = true;
GUILayout.EndHorizontal();
return blnReturn;
}
示例6: ShowScore
private void ShowScore(GameObject obj, Transform offsetX, GUIStyle style, string score)
{
Vector3 rawPosition = obj.transform.position;
rawPosition.x = offsetX.position.x;
Vector3 start = Camera.main.WorldToScreenPoint(rawPosition);
start.y = Screen.height - start.y;
float minWidth, maxWidth;
string text = TextFormatting.AddSpacingBetweenCharacters(score);
GUIContent content = new GUIContent(text);
style.CalcMinMaxWidth(content, out minWidth, out maxWidth);
float height = style.CalcHeight(content, maxWidth);
height /= 2.0f;
float halfWidth = maxWidth / 2.0f;
GUI.Label(new Rect(start.x - halfWidth - 3, start.y + 2 - height, maxWidth, 120), FontColorUtils.Shadow(text), style);
GUI.Label(new Rect(start.x - halfWidth, start.y - height, maxWidth, 120), FontColorUtils.MainGameScore(text), style);
}
示例7: 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) {
float width = position.width, minWidth = 0f, maxWidth = 0f;
foreach (var v in listContent) {
try {
listStyle.CalcMinMaxWidth(v, out minWidth, out maxWidth);
if (width < maxWidth) { width = maxWidth; }
} catch {}
}
Rect listRect = new Rect(position.x, position.y, 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;
}
示例8: Hyperlink
public static void Hyperlink(string Label, string Url, GUIStyle gsBase)
{
if (GUILayout.Button(Label, gsBase))
Application.OpenURL(Url);
Rect r = GUILayoutUtility.GetLastRect();
float mw, Mw;
float h = gsBase.CalcHeight(new GUIContent(Label), r.width) - gsBase.padding.top - gsBase.padding.bottom;
gsBase.CalcMinMaxWidth(new GUIContent(Label), out mw, out Mw);
//Vector2 v = gsBase.CalcSize(new GUIContent(Label));
Rect nr = new Rect(
r.x + gsBase.padding.left,
r.y + gsBase.padding.top + h,
Mw - gsBase.padding.left - gsBase.padding.right,
1);
Color oldC = GUI.color;
GUI.color = gsBase.normal.textColor;
GUI.DrawTexture(nr, wHiteTex);
GUI.color = oldC;
#if UNITY_EDITOR
UnityEditor.EditorGUIUtility.AddCursorRect(r, UnityEditor.MouseCursor.Link);
#endif
}