Tanoda
pb_GUIStyle.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
4
5namespace GILES.Interface
6{
10 [System.Serializable]
11 [CreateAssetMenuAttribute(menuName = "Level Editor GUI Style", fileName = "RT GUI Style", order = pb_Config.ASSET_MENU_ORDER)]
12 public class pb_GUIStyle : ScriptableObject
13 {
14 [SerializeField] private Font _font;
15
17 public Color color = Color.white;
18
20 public Color normalColor = new Color(.2f, .2f, .2f, .7f);
21
23 public Color highlightedColor = new Color(.27f, .27f, .27f, 1f);
24
26 public Color pressedColor = new Color(.37f, .37f, .37f, 1f);
27
29 public Color disabledColor = new Color(.7f, .7f, .7f, 1f);
30
32 public Texture2D image;
33
35 public Sprite sprite;
36
38 public Font font
39 {
40 get
41 {
42 return _font == null ? (Font) Resources.GetBuiltinResource(typeof(Font), "Arial.ttf") : _font;
43 }
44
45 set { _font = value; }
46 }
47
49 public Color fontColor = Color.white;
50
51 public static pb_GUIStyle Create(
53 Color? normalColor = null,
54 Color? highlightedColor = null,
55 Color? pressedColor = null,
56 Color? disabledColor = null,
57 Texture2D image = null,
58 Sprite sprite = null,
59 Font font = null,
60 Color? fontColor = null)
61 {
62 pb_GUIStyle style = ScriptableObject.CreateInstance<pb_GUIStyle>();
63
64 style.color = color;
65 style.image = image;
66 style.sprite = sprite;
67 style.font = font;
68
69 if(normalColor != null) style.normalColor = (Color) normalColor;
71 if(pressedColor != null) style.pressedColor = (Color) pressedColor;
72 if(disabledColor != null) style.disabledColor = (Color) disabledColor;
73 if(fontColor != null) style.fontColor = (Color) fontColor;
74
75 return style;
76 }
77
78 public virtual void Apply(Graphic element)
79 {
80 element.color = element is Text ? fontColor : color;
81 pb_Reflection.SetValue(element, "font", font);
82 pb_Reflection.SetValue(element, "image", image);
83 pb_Reflection.SetValue(element, "sprite", sprite);
84 }
85
86 public virtual void Apply(Selectable element)
87 {
88 ColorBlock block = element.colors;
89
90 block.disabledColor = disabledColor;
91 block.highlightedColor = highlightedColor;
92 block.normalColor = normalColor;
93 block.pressedColor = pressedColor;
94
95 element.colors = block;
96 }
97 }
98}
UnityEngine.Color Color
Definition: TestScript.cs:32
virtual void Apply(Graphic element)
Definition: pb_GUIStyle.cs:78
Color fontColor
Text tint.
Definition: pb_GUIStyle.cs:49
Color disabledColor
Background color tint when disabled.
Definition: pb_GUIStyle.cs:29
static pb_GUIStyle Create(Color color, Color? normalColor=null, Color? highlightedColor=null, Color? pressedColor=null, Color? disabledColor=null, Texture2D image=null, Sprite sprite=null, Font font=null, Color? fontColor=null)
Definition: pb_GUIStyle.cs:51
Sprite sprite
Sprite to use (if applicable).
Definition: pb_GUIStyle.cs:35
Font font
Font to use. If null the default Arial is used.
Definition: pb_GUIStyle.cs:39
Color pressedColor
Background color tint when pressed.
Definition: pb_GUIStyle.cs:26
virtual void Apply(Selectable element)
Definition: pb_GUIStyle.cs:86
Color highlightedColor
Background color tint when hovering or highlighted.
Definition: pb_GUIStyle.cs:23
Texture2D image
Image to use (if applicable).
Definition: pb_GUIStyle.cs:32
Color color
Background image tint.
Definition: pb_GUIStyle.cs:17
Color normalColor
The default color of a button.
Definition: pb_GUIStyle.cs:20