9 public static class pb_GUIUtility
12 public static readonly
Color PANEL_COLOR =
new Color(.27f, .27f, .27f, .5f);
15 public static readonly
Color ITEM_BACKGROUND_COLOR =
new Color(.15f, .15f, .15f, 1f);
18 public const int PADDING = 4;
22 public static readonly RectOffset PADDING_RECT_OFFSET =
new RectOffset(PADDING, PADDING, PADDING, PADDING);
26 private static Font _defaultFont;
31 public static Vector2 ScreenToGUIPoint(Vector2 v)
33 v.y = Screen.height - v.y;
40 public static Font DefaultFont()
42 if(_defaultFont ==
null)
43 _defaultFont = (Font) Resources.GetBuiltinResource(typeof(Font),
"Arial.ttf");
51 public static Font GetFont(
string fontName)
53 return Resources.Load<Font>(
"Required/Font/" + fontName);
59 public static GameObject CreateLabeledVerticalPanel(
string label)
61 GameObject go =
new GameObject();
64 go.AddComponent<
Image>().color = PANEL_COLOR;
66 AddVerticalLayoutGroup(go);
68 CreateLabel( label ).transform.SetParent(go.transform);
76 public static GameObject CreateHorizontalGroup()
78 GameObject go =
new GameObject();
80 HorizontalLayoutGroup group = go.AddComponent<HorizontalLayoutGroup>();
81 group.padding =
new RectOffset(2,2,2,2);
82 group.childForceExpandWidth =
true;
83 group.childForceExpandHeight =
false;
91 public static GameObject CreateLabel(
string text)
93 GameObject go =
new GameObject();
94 go.name =
"Label Field";
95 Text field = go.AddComponent<Text>();
96 string temp = text.Replace(
"UnityEngine.",
"");
99 field.font = pb_GUIUtility.DefaultFont();
100 go.AddComponent<LayoutElement>().minHeight = 24;
101 field.alignment = TextAnchor.MiddleLeft;
108 public static void AddVerticalLayoutGroup(GameObject go)
110 AddVerticalLayoutGroup(
112 pb_GUIUtility.PADDING_RECT_OFFSET,
113 pb_GUIUtility.PADDING,
121 public static void AddVerticalLayoutGroup(GameObject go, RectOffset padding,
int spacing,
bool childForceExpandWidth,
bool childForceExpandHeight)
123 VerticalLayoutGroup group = go.AddComponent<VerticalLayoutGroup>();
124 group.padding = padding;
125 group.spacing = spacing;
126 group.childForceExpandWidth = childForceExpandWidth;
127 group.childForceExpandHeight = childForceExpandHeight;
133 public static Selectable GetNextSelectable(Selectable current)
138 Selectable next = current.FindSelectableOnRight();
146 next = current.FindSelectableOnDown();
151 Selectable left = next;
155 left = left.FindSelectableOnLeft();
170 public static Rect GetScreenRect(
this RectTransform rectTransform)
173 rectTransform.GetWorldCorners(world);
176 return new Rect(min.x, max.y, max.x - min.x, max.y - min.y);
System.Drawing.Image Image