Tanoda
pb_PanelToggleFixColor.cs
Go to the documentation of this file.
1using UnityEngine;
2using UnityEngine.UI;
3using System.Collections;
4
5namespace GILES.Interface
6{
11 {
13 public GameObject panel;
14 public Sprite showImage, hideImage;
15 private Vector2 originalSize;
16 private Vector3 originalPosition;
17 public bool xDir, yDir;
18#if DANA
19 private readonly Color onColor = new Color(1f, 1f, 1f, 1f),
20 offColor = new Color(1f, 1f, 1f, 0.2f);
21 private readonly Color blueColor = new Color(0f, 38f/255f, 137f/255f, 1f),
22 whiteColor = new Color(1f, 1f, 1f, 1f);
23#elif UNITY_WEBGL
24
25 private readonly Color onColor = new Color(57/255f, 190/255f, 187/255f, 1f),
26 offColor = new Color(1f, 1f, 1f, 1f);
27#else
28 private readonly Color onColor = new Color(0.2235294f, 0.6352941f, 0.8941177f, 1f),
29 offColor = new Color(.0f, .0f, .0f, 1f);
30#endif
31 private void Start()
32 {
33 base.Start();
34 originalSize = panel.GetComponent<RectTransform>().sizeDelta;
35 originalPosition = panel.GetComponent<RectTransform>().localPosition;
36 }
37 public void DoToggle()
38 {
39#if !UNITY_WEBGL
40 panel.SetActive(!panel.activeInHierarchy);
41 panel.transform.SetAsLastSibling();
42
43 ColorBlock block = selectable.colors;
44 block.normalColor = panel.activeInHierarchy ? onColor : offColor;
45 selectable.colors = block;
46#else
47
48 var cg = panel.GetComponent<CanvasGroup>();
49 var alpha = cg.alpha;
50
51 cg.alpha = Mathf.Abs(alpha - 1);
52 cg.blocksRaycasts = cg.alpha == 1f;
53 cg.interactable = cg.alpha == 1f;
54
55 panel.transform.SetAsLastSibling();
56
57 ColorBlock block = selectable.colors;
58 block.normalColor = cg.alpha == 1f ? onColor : offColor;
59 selectable.colors = block;
60#endif
61 }
62 public void DoToggleNew()
63 {
64#if !UNITY_WEBGL
65 panel.SetActive(!panel.activeInHierarchy);
66 panel.transform.SetAsLastSibling();
67
68 if (selectable.GetComponent<Image>()) SetColor();
69
70
71#else
72
73 var cg = panel.GetComponent<CanvasGroup>();
74 var alpha = cg.alpha;
75
76 cg.alpha = Mathf.Abs(alpha - 1);
77 cg.blocksRaycasts = cg.alpha == 1f;
78 cg.interactable = cg.alpha == 1f;
79
80 panel.transform.SetAsLastSibling();
81
82 ColorBlock block = selectable.colors;
83 block.normalColor = cg.alpha == 1f ? onColor : offColor;
84 selectable.colors = block;
85#endif
86 }
87 public void ModeSelectorToggle()
88 {
89 if (selectable.name.Contains("Envir"))
90 {
92 pb_Scene.instance.EditEnvironmentToggle();
93
94 }
95 if (selectable.name.Contains("Tools"))
96 {
98 }
99 else
100 {
102 }
103 SetColor();
104 }
105 public void DoShowHide()
106 {
107#if !UNITY_WEBGL
108 StartCoroutine(showHidePanel(!panel.transform.Find("Window Title Bar").gameObject.activeInHierarchy));
109 panel.transform.SetAsLastSibling();
110
111 ColorBlock block = selectable.colors;
112 block.normalColor = panel.activeInHierarchy ? onColor : offColor;
113 selectable.colors = block;
114#else
115
116 var cg = panel.GetComponent<CanvasGroup>();
117 var alpha = cg.alpha;
118
119 cg.alpha = Mathf.Abs(alpha - 1);
120 cg.blocksRaycasts = cg.alpha == 1f;
121 cg.interactable = cg.alpha == 1f;
122
123 panel.transform.SetAsLastSibling();
124
125 ColorBlock block = selectable.colors;
126 block.normalColor = cg.alpha == 1f ? onColor : offColor;
127 selectable.colors = block;
128#endif
129 }
130 IEnumerator showHidePanel(bool show)
131 {
132 float time = 0;
133 float duration = 0.75f;
134 RectTransform rt = panel.GetComponent<RectTransform>();
135 Vector2 targetSize = rt.sizeDelta;
136 Vector3 targetPos = rt.localPosition;
137 var canvaspos = GetComponentInParent<Canvas>().GetComponent<RectTransform>().localPosition;
138 if (xDir)
139 {
140 targetSize.x = 0;
141 var asd = rt.anchorMin;
142 if (rt.anchorMin.x == 1)
143 {
144 targetPos.x = canvaspos.x;
145 }
146 else
147 {
148 targetPos.x = -canvaspos.x;
149 }
150
151 }
152 if (yDir)
153 {
154 targetSize.y = 0;
155 targetPos.y = -canvaspos.y;
156 }
157
158 while (time <= duration)
159 {
160 time += Time.deltaTime;
161 if (!show)
162 {
163 rt.sizeDelta = Vector2.Lerp(rt.sizeDelta, targetSize/*new Vector2(rt.sizeDelta.x, 0)*/, time / duration);
164 rt.localPosition = Vector3.Lerp(rt.localPosition, targetPos/*new Vector3(rt.localPosition.x, -canvaspos.y, rt.localPosition.z)*/, time / duration);
165 }
166
167 else
168 {
169 rt.sizeDelta = Vector2.Lerp(rt.sizeDelta, originalSize, time / duration);
170 rt.localPosition = Vector3.Lerp(rt.localPosition, originalPosition, time / duration);
171 }
172
173 yield return null;
174 }
175 if (panel.transform.Find("Window Title Bar").gameObject.activeInHierarchy) GetComponent<Image>().sprite = showImage;
176 else GetComponent<Image>().sprite = hideImage;
177 panel.transform.Find("Window Title Bar").gameObject.SetActive(!panel.transform.Find("Window Title Bar").gameObject.activeInHierarchy);
178 }
179 private void SetColor()
180 {
181#if DANA
182 var imageColor = selectable.GetComponent<Image>().color;
183 var iconColor = selectable.gameObject.transform.GetChild(0).GetComponent<Image>().color;
184 if (panel.activeInHierarchy)
185 {
186 imageColor = whiteColor;
187 iconColor = blueColor;
188
189 }
190 else
191 {
192 imageColor = blueColor;
193 iconColor = whiteColor;
194 }
195 selectable.GetComponent<Image>().color = imageColor;
196 selectable.gameObject.transform.GetChild(0).GetComponent<Image>().color = iconColor;
197#endif
198 }
199 }
200}
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
GameObject panel
The panel to enable / disable with this toggle.
static void Clear()
Definition: pb_Selection.cs:61
static ToolPositioner instance
void EditToolPositions()