Tanoda
AddItems.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Runtime.Serialization;
5using UnityEngine;
7using UnityEngine.UI;
8
9[Serializable]
10public class AddItems : MonoBehaviour
11{
12 public GameObject ASlot;
13 public GameObject ActionSlot;
14 public GameObject GOSlot;
15 public GameObject GameObjectSlot;
16 GameObject collector;
17 float width;
18 float height;
19 RectTransform rt;
20 GameObject Acopy;
21 GameObject GOcopy;
23 ReferenceSaver rsgo;
25 Stack<GameObject> goStackA = new Stack<GameObject>();
26 Stack<GameObject> goStackGO = new Stack<GameObject>();
27 GameObject actionGO;
28 public Vector2 OriginalSize;
29 public GameObject AddNewButton;
30 GameObject RemoveTheButton;
31 public GameObject ItemGO;
32 public GameObject ItemAction;
33 GameObject ItemActionFind;
34 public Text textfield;
35 public GameObject Count;
36 CanvasGroup cggo;
37 String action;
38 Transform[] GameObjectSlotChildren;
39 int GOCount;
40 ActionObject[] ActionSlotChildren;
41 float x;
42 //public static AddItems Instance;
43 public void Start()
44 {
45 collector = GetComponentInParent<CollectorAction>().gameObject;
46 RemoveTheButton = GameObject.Find("RemoveItem");
47 rt = (RectTransform)collector.transform;
48 width = rt.rect.width;
49 height = rt.rect.height;
50 actionGO = GameObject.Find("Actions");
51 ItemActionFind = GameObject.Find("ItemAction");
52 rs = ItemActionFind.GetComponent<ReferenceSaver>();
53
54 }
55 public void AddButton()
56 {
57 collector = GetComponentInParent<CollectorAction>().gameObject;
58 rt = (RectTransform)collector.transform;
59 width = rt.rect.width;
60 height = rt.rect.height;
61 Acopy = Instantiate(ItemAction);
62 Acopy.transform.parent = ActionSlot.transform;
63 Acopy.transform.localScale = new Vector3(1, 1, 1);
64 GOcopy = Instantiate(ItemGO);
65 GOcopy.transform.parent = GameObjectSlot.transform;
66 rt.sizeDelta = new Vector2(width, height += 350);
67 rs = Acopy.GetComponent<ReferenceSaver>();
68 rs.Reference = GOcopy;
69 rsgo = GOcopy.GetComponent<ReferenceSaver>();
70 rsgo.Reference = Acopy;
71 goStackA.Push(Acopy);
72 goStackGO.Push(GOcopy);
73 }
74 public GameObject _AddButton()
75 {
76 collector = GetComponentInParent<CollectorAction>().gameObject;
77 rt = (RectTransform)collector.transform;
78 width = rt.rect.width;
79 height = rt.rect.height;
80 Acopy = Instantiate(ItemAction);
81 Acopy.transform.parent = ActionSlot.transform;
82 Acopy.transform.localScale = new Vector3(1, 1, 1);
83 GOcopy = Instantiate(ItemGO);
84 GOcopy.transform.parent = GameObjectSlot.transform;
85 rt.sizeDelta = new Vector2(width, height += 350);
86 rs = Acopy.GetComponent<ReferenceSaver>();
87 rs.Reference = GOcopy;
88 rsgo = GOcopy.GetComponent<ReferenceSaver>();
89 rsgo.Reference = Acopy;
90 goStackA.Push(Acopy);
91 goStackGO.Push(GOcopy);
92 return Acopy;
93 }
94
95 public void RemoveButton()
96 {
97 if (height > 450)
98 {
99 width = rt.rect.width;
100 height = rt.rect.height;
101 rt.sizeDelta = new Vector2(width, height -= 350);
102 GameObject destroyA = goStackA.Pop();
103 GameObject destroyGO = goStackGO.Pop();
104 Destroy(destroyA);
105 Destroy(destroyGO);
106 }
107
108 }
109
110 IEnumerator Minimalize(Vector2 startSize, Vector2 endSize, Action action)
111 {
112 float time = 0;
113 float duration = 0.75f;
114
115 while (time <= duration)
116 {
117 time += Time.deltaTime;
118 rt.sizeDelta = Vector2.Lerp(startSize, endSize, time / duration);
119 LineDrawer.Instance.ReDraw(gameObject.GetComponentInParent<CollectorAction>().name);
120 yield return null;
121 }
122 action();
123
124 }
125
126
127 public void scale()
128
129 {
130
131 textfield.text = ActionCount().ToString(); //actionGO.transform.childCount.ToString();
132 if (ActionSlot.transform.localScale == new Vector3(1, 1, 1))
133 {
134
135 OriginalSize = rt.sizeDelta;
136 if (OriginalSize == Vector2.zero)
137 {
138 OriginalSize = collector.GetComponent<CollectorAction>().OriginalSize;
139 }
140 ActionSlot.transform.localScale = new Vector3(0, 0, 0);
141 GameObjectSlot.transform.localScale = new Vector3(0, 0, 0);
142 //actionGO.transform.localScale = new Vector3(0, 0, 0);
143 AddNewButton.transform.localScale = new Vector3(0, 0, 0);
144 //RemoveTheButton.transform.localScale = new Vector3(0, 0, 0);
145 StartCoroutine(Minimalize(new Vector2(width, height), new Vector2(200, 200), actionMinimalize));
146 }
147 else
148 {
149 if (OriginalSize == Vector2.zero)
150 {
151 OriginalSize = collector.GetComponent<CollectorAction>().OriginalSize;
152 }
153 StartCoroutine(Minimalize(new Vector2(200, 200), OriginalSize, actionMaximalize));
154 Count.SetActive(false);
155 }
156
157 }
158 public void actionMinimalize()
159 {
160 Count.SetActive(true);
161 }
162
163 public void actionMaximalize()
164 {
165 ActionSlot.transform.localScale = new Vector3(1, 1, 1);
166 GameObjectSlot.transform.localScale = new Vector3(1, 1, 1);
167 //actionGO.transform.localScale = new Vector3(1, 1, 1);
168 AddNewButton.transform.localScale = new Vector3(1, 1, 1);
169 }
170
171 public void showPreviewGameObject(GameObject value)
172 {
173 rsp = value.GetComponent<ReferenceSaver>();
174 if (rsp.Reference.transform.localScale == Vector3.zero && rsp.Reference.GetComponentInChildren<ActionObject>().action.Contains("GameObject"))
175 {
176 if (rsp.Reference.GetComponentInChildren<ActionObject>().transform.localPosition != Vector3.zero)
177 {
178 rsp.Reference.GetComponentInChildren<ActionObject>().transform.localPosition = Vector3.zero;
179 }
180 width = rt.rect.width;
181 height = rt.rect.height;
182 Counter();
183 GameObjectSlot.transform.localScale = new Vector3(1, 1, 1);
184 if (GOCount == 0)
185 {
186 StartCoroutine(AppearGameObject(new Vector3(0, 0, 0), new Vector3(0.5f, 0.5f, 0.5f), new Vector2(width = 520, height), new Vector2(width = 700, height), 0, 0.5f));
187 }
188 else
189 {
190 StartCoroutine(AppearGameObject(new Vector3(0, 0, 0), new Vector3(0.5f, 0.5f, 0.5f), new Vector2(width = 800, height), new Vector2(width = 800, height), 0, 0.5f));
191 }
192 }
193
194
195 }
196 public void hidePreviewGameObject(GameObject value)
197 {
198 rsp = value.GetComponent<ReferenceSaver>();
199 if (rsp.Reference.transform.localScale != new Vector3(0, 0, 0) && rsp.Reference.GetComponentInChildren<ActionObject>().action.Contains("GameObject"))
200 {
201 width = rt.rect.width;
202 height = rt.rect.height;
203 Counter();
204 if (GOCount == 0)
205 {
206 GameObjectSlot.transform.localScale = new Vector3(0, 0, 0);
207 StartCoroutine(AppearGameObject(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0, 0, 0), new Vector2(width = 700, height), new Vector2(width = 520, height), 0.5f, 0));
208 }
209 else
210 {
211 StartCoroutine(AppearGameObject(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(0, 0, 0), new Vector2(width = 800, height), new Vector2(width = 800, height), 0.5f, 0));
212 }
213 }
214 }
215 IEnumerator WaitUntilEnd(Vector3 EndScale)
216 {
217 while (rsp.Reference.transform.localScale == EndScale);
218 {
219 yield return null;
220 }
221 }
222
223 public void showFullGameObject(GameObject value)
224 {
225 //eventTrigger = value.transform.GetChild(0).GetComponent<EventTrigger>();
226 var eventTrigger = value.GetComponentInChildren<ItemAction>();
227 width = rt.rect.width;
228 height = rt.rect.height;
229 rsp = value.GetComponent<ReferenceSaver>();
230 Counter();
231 if (rsp.Reference.transform.localScale == new Vector3(0.5f, 0.5f, 0.5f))
232 {
233 GameObjectSlot.transform.localScale = new Vector3(1, 1, 1);
234 eventTrigger.enabled = false;
235 if (GOCount == 0)
236 {
237 StartCoroutine(AppearGameObject(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1, 1, 1), new Vector2(width = 700, height), new Vector2(width = 800, height), 0, 1));
238 }
239 else
240 {
241 StartCoroutine(AppearGameObject(new Vector3(0.5f, 0.5f, 0.5f), new Vector3(1, 1, 1), new Vector2(width = 800, height), new Vector2(width = 800, height), 0, 1));
242 }
243 }
244
245 if (rsp.Reference.transform.localScale == new Vector3(0, 0, 0))
246 {
247 GameObjectSlot.transform.localScale = new Vector3(1, 1, 1);
248 eventTrigger.enabled = false;
249 if (GOCount == 0)
250 {
251 StartCoroutine(AppearGameObject(new Vector3(0, 0, 0), new Vector3(1, 1, 1), new Vector2(width = 520, height), new Vector2(width = 800, height), 0, 1));
252 }
253 else
254 {
255 StartCoroutine(AppearGameObject(new Vector3(0, 0, 0), new Vector3(1, 1, 1), new Vector2(width = 800, height), new Vector2(width = 800, height), 0, 1));
256 }
257 }
258
259 if (rsp.Reference.transform.localScale == new Vector3(1, 1, 1))
260 {
261 GameObjectSlot.transform.localScale = new Vector3(1, 1, 1);
262 eventTrigger.enabled = true;
263 if (GOCount <= 1)
264 {
265 StartCoroutine(AppearGameObject(new Vector3(1, 1, 1), new Vector3(0, 0, 0), new Vector2(width = 800, height), new Vector2(width = 520, height), 1, 0));
266 }
267 else
268 {
269 StartCoroutine(AppearGameObject(new Vector3(1, 1, 1), new Vector3(0, 0, 0), new Vector2(width = 800, height), new Vector2(width = 800, height), 1, 0));
270 }
271
272 }
273
274
275 }
276
277
278
279 IEnumerator AppearGameObject(Vector3 startScale, Vector3 endScale, Vector2 startSize, Vector2 endSize, float startAlpha, float endAlpha)
280 {
281 float time = 0;
282 float duration = 0.75f;
283 x = rsp.Reference.transform.localScale.x;
284 cggo = rsp.Reference.GetComponent<CanvasGroup>();
285 GameObject clone = rsp.Reference.GetComponentInChildren<GameObjectAction>().gameObject;
286 while (time <= duration)
287 {
288 time += Time.deltaTime;
289 rsp.Reference.transform.localScale = Vector3.Lerp(startScale, endScale, time / duration);
290 cggo.alpha = Mathf.Lerp(startAlpha, endAlpha, time / duration);
291 if (GOCount<=1)
292 {
293 rt.sizeDelta = Vector2.Lerp(startSize, endSize, time / duration);
294 }
295 if (endScale != new Vector3(0, 0, 0) && rsp.Reference.transform.localScale != Vector3.zero)
296 {
298 }
299 else
300 {
301 if (rsp.Reference.transform.localScale.x > 0)
302 {
304 }
305 }
306 LineDrawer.Instance.ReDraw(clone.GetComponentInParent<CollectorAction>().name);
307 yield return null;
308 }
309 }
310
311 public void Counter()
312 {
313 GameObjectSlotChildren = GameObjectSlot.GetComponentsInChildren<Transform>();
314 GOCount = 0;
315 foreach (var a in GameObjectSlotChildren)
316 {
317 if (a.name.Contains("ItemGO"))
318 {
319 if (a.transform.localScale == new Vector3(1, 1, 1))
320 {
321 GOCount++;
322 }
323
324 }
325 }
326 }
327 public void refreshConnectionPos(GameObject ConnectedGO)
328 {
329 ConnectedGO = rsp.Reference.GetComponentInChildren<GameObjectAction>().gameObject;
330 var diff = new Vector2(0, 0);
331 var rect = ConnectedGO.GetComponent<RectTransform>();
332 var newPosition = rect.position + new Vector3(diff.x, diff.y, transform.position.z);
333 var oldPos = rect.position;
334 rect.position = newPosition;
335
336 try
337 {
338 LineDrawer.Instance.ReDraw(ConnectedGO.name);
339 }
340 catch (Exception e)
341 {
342 Console.WriteLine(e);
343 }
344 }
345
346 public int ActionCount()
347 {
348 int ActionCount = 0;
349 ActionSlotChildren = ActionSlot.GetComponentsInChildren<ActionObject>();
350 foreach (var a in ActionSlotChildren)
351 {
352 if (a.GetComponent<ActionObject>())
353 {
354 ActionCount++;
355 }
356 }
357 return ActionCount;
358 }
359}
string action
Definition: ActionObject.cs:32
void showFullGameObject(GameObject value)
Definition: AddItems.cs:223
GameObject _AddButton()
Definition: AddItems.cs:74
Text textfield
Definition: AddItems.cs:34
void showPreviewGameObject(GameObject value)
Definition: AddItems.cs:171
void AddButton()
Definition: AddItems.cs:55
GameObject ItemAction
Definition: AddItems.cs:32
void RemoveButton()
Definition: AddItems.cs:95
void Start()
Definition: AddItems.cs:43
Vector2 OriginalSize
Definition: AddItems.cs:28
void actionMinimalize()
Definition: AddItems.cs:158
void scale()
Definition: AddItems.cs:127
GameObject GameObjectSlot
Definition: AddItems.cs:15
int ActionCount()
Definition: AddItems.cs:346
GameObject ItemGO
Definition: AddItems.cs:31
GameObject ASlot
Definition: AddItems.cs:12
void Counter()
Definition: AddItems.cs:311
GameObject ActionSlot
Definition: AddItems.cs:13
GameObject GOSlot
Definition: AddItems.cs:14
void hidePreviewGameObject(GameObject value)
Definition: AddItems.cs:196
void actionMaximalize()
Definition: AddItems.cs:163
GameObject Count
Definition: AddItems.cs:35
GameObject AddNewButton
Definition: AddItems.cs:29
void refreshConnectionPos(GameObject ConnectedGO)
Definition: AddItems.cs:327
static LineDrawer Instance
Definition: LineDrawer.cs:16
void ReDraw(string id)
Definition: LineDrawer.cs:235
GameObject Reference