Tanoda
CollectorAction.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Linq;
5using System.Runtime.Serialization;
6using UnityEngine;
7using UnityEngine.UI;
9
10public class CollectorAction : ActionObject, ISerializable
11{
12 GameObject inGO;
13 int ChildIndex;
14 private List<GameObject> inputs;
15 private Dictionary<string, bool> inputStatus;
16 internal int savedInputCount;
17 List<GameObject> inputsList;
18 public GameObject SlotHolder;
20 public GameObject ActionSlot;
21 public GameObject GameObjectSlot;
22 ReferenceSaver[] ActionChildren;
23 public List<string> ActionChildrenList = new List<string>();
24 ReferenceSaver[] GameObjectChildren;
25 public List<string> GameObjectChildrenList = new List<string>();
26 List<String> GameObjectConnectionList = new List<String>();
27 List<String> ActionConnectionList = new List<String>();
28 ActionObject[] ActionSlotChildren;
29 bool firstTriggered;
30 int childCount;
31 public int ActionChildCount;
32 public bool inOrder;
33 internal bool Welding;
35 string line;
36 int a;
37 int i;
38 float width;
39 float height;
40 public Toggle toggle;
41 public Toggle weldToggle;
42 GameObject collector;
43 RectTransform rt;
44 public bool isSmall;
45 public Vector2 OriginalSize;
46 public int ActionCount;
47 private GameObject weldedGO;
48 private List<Transform> originalParents;
49
50 private void Awake()
51 {
52 action = GetType().Name;
53 }
54
55 void Start()
56 {
57 base.Start();
58 inputStatus = new Dictionary<string, bool>();
59 originalParents = new List<Transform>();
60 _Instance = this;
61 inputsList = new List<GameObject>();
62 firstTriggered = true;
63
64 a = 0;
65 i = -1;
66 }
67 public void Order(bool newValue)
68 {
69 inOrder = newValue;
70 }
71 public void Weld(bool newWeldValue)
72 {
73 Welding = newWeldValue;
74 }
75
76 public override void Triggered(string id)
77 {
78 ActionSlotChildren = ActionSlot.GetComponentsInChildren<ActionObject>();
79 childCount = CountChildWithComponent();
80 if (Welding && ActionSlot.GetComponentInChildren<GameObjectAction>())
81 {
82 StartCoroutine(LateReparent());
83 return;
84 }
85
86 if (firstTriggered)
87 {
88 foreach (Transform a in ActionSlot.transform)
89 {
90 if (a.GetComponentInChildren<ActionObject>())
91 {
92 inputsList.Add(a.GetComponentInChildren<ActionObject>().gameObject);
93 }
94 else
95 {
96
97 }
98 }
99 }
100 if (inOrder)
101 {
102 ActionSlotChildren = ActionSlot.GetComponentsInChildren<ActionObject>();
103
104 if (firstTriggered)
105 {
106 base.Triggered(id);
107 firstTriggered = false;
108 }
109 if (a < childCount)
110 {
111 Controller.Instance.DirektTrigger(ActionSlotChildren[a].inPuts[1].name);
112 a++;
113 }
114 inputStatus[id] = true;
115 i++;
116 if (i == inputsList.Count)
117 {
118 TriggerOutput(outPuts[0].name);
119 if (Welding && !ActionSlot.GetComponentInChildren<GameObjectAction>())
120 {
121 Reparent();
122 }
123 Reset();
124 }
125 }
126 if (!inOrder)
127 {
128 if (firstTriggered)
129 {
130 base.Triggered(id);
131 firstTriggered = false;
132 foreach (var b in ActionSlotChildren)
133 {
134 Controller.Instance.DirektTrigger(b.inPuts[1].name);
135 }
136 }
137 inputStatus[id] = true;
138 i++;
139 if (i == inputsList.Count)
140 {
141 TriggerOutput(outPuts[0].name);
142 if (Welding && !ActionSlot.GetComponentInChildren<GameObjectAction>())
143 {
144 Reparent();
145 }
146 Reset();
147 }
148 }
149
150
151 }
152 IEnumerator LateReparent()
153 {
154 yield return new WaitForEndOfFrame();
155 Reparent();
156 TriggerOutput(outPuts[0].name);
157 }
158
159 internal void Reparent() //Weld
160 {
161 var list = GetGOs();
162 if (list != null && list.Length > 1)
163 {
164 var parent = list[0].transform;
165 weldedGO = list[0];
166 for (var i = 1; i < list.Length; i++)
167 {
168 if (list[i] == null) continue;
169 originalParents.Add(list[i].transform.parent);
170 list[i].transform.SetParent(parent, true);
171 }
172 }
173 }
174 GameObject[] GetGOs()
175 {
176 try
177 {
178 var list = new List<string>();
179 var ObjectList = SlotHolder.GetComponentsInChildren<GameObjectAction>();
180 foreach (var obj in ObjectList)
181 {
182 list.Add(obj.name);
183 }
184
185 var retval = new List<GameObject>();
186 foreach (var s in ObjectList)
187 {
188 var goname = "UNKNOWN";
189
190 retval.Add(s.GetGameObject());
191 goname = s.GetGameObject().name;
192 }
193
194
195
196 return retval.ToArray();
197 }
198 catch (Exception)
199 {
200 return null;
201 }
202 }
203 int CountChildWithComponent()
204 {
205 int childCount = 0;
206 ActionSlotChildren = ActionSlot.GetComponentsInChildren<ActionObject>();
207 foreach (var a in ActionSlotChildren)
208 {
209 if (!a.action.Contains("GameObject"))
210 {
211 childCount++;
212 }
213 }
214 return childCount;
215 }
216
217 public override void Reset()
218 {
219 base.Reset();
220 foreach (var key in inputStatus.Keys.ToList())
221 inputStatus[key] = false;
222 }
223
224
225
226 public void SetTheChildren()
227 {
228 Debug.Log(gameObject.name);
229 for (int j = 1; j < ActionChildCount; j++)
230 {
231 StartCoroutine(LoadChildren());
232 }
233 }
234
235 public void MoveTheChildren()
236 {
237 collector = gameObject.GetComponentInParent<CollectorAction>().gameObject;
238 rt = (RectTransform)collector.transform;
239 width = rt.rect.width;
240 height = rt.rect.height;
241
242 for (int j = 0; j < ActionChildCount; j++)
243 {
244 StartCoroutine(Parenting(j));
245 }
246 }
247
248 IEnumerator LoadChildren()
249 {
250 yield return null;
252 }
253
254
255 IEnumerator Parenting(int Value)
256 {
257 for (int i = 0; i < 5; i++)
258 {
259 yield return null;
260 while (LoadingManager.instance.isLoading)
261 {
262 yield return null;
263 }
264 }
265
266 yield return null;
267 Debug.Log(Value);
268 var Acopy = ActionSlot.transform.GetChild(Value);
269 var Gcopy = Acopy.GetComponent<ReferenceSaver>();
270 GameObject gameAction;
271 GameObject gameGameObject;
272 GameObject connectionAction;
273 GameObject connectionGameObject;
274 DropArea ActionDrop;
275 if (ActionChildrenList[Value] != "")
276 {
277 gameAction = Controller.Instance.GetActionById(ActionChildrenList[Value]).gameObject;
278 MouseDragBehaviour ActionDrag = gameAction.GetComponent<MouseDragBehaviour>();
279 ActionDrop = ActionSlot.transform.GetChild(Value).GetComponentInChildren<DropArea>();
280 ActionDrop.Drop(ActionDrag);
281 ActionConnectionList = Controller.Instance.GetOutputConnectionsToObject(gameAction.name);
282 connectionAction = gameAction.transform.parent.Find(ActionConnectionList[0]).gameObject;
283 ActionDrag.transform.parent = ActionDrop.transform.parent;
284 connectionAction.transform.parent = ActionDrop.transform.parent;
285 ActionDrop.gameObject.AddComponent<Reserved>();
286 connectionAction.GetComponent<UILineRenderer>().enabled = false;
287 gameAction.transform.localPosition = new Vector3(0,-125,0);
288 gameAction.transform.localScale = Vector3.one;
289 }
290 if (GameObjectChildrenList[Value] != "")
291 {
292 Acopy.transform.Find("ExtendGO").gameObject.SetActive(true);
293 gameGameObject = Controller.Instance.GetActionById(GameObjectChildrenList[Value]).gameObject;
294 GameObjectConnectionList = new List<String>();
295 GameObjectConnectionList = Controller.Instance.GetOutputConnectionsToObject(gameGameObject.name);
296 connectionGameObject = gameGameObject.transform.parent.Find(GameObjectConnectionList[0]).gameObject;
297 MouseDragBehaviour GameObjectDrag = gameGameObject.GetComponent<MouseDragBehaviour>();
298 DropArea GameObjectDrop = Gcopy.Reference.GetComponentInChildren<DropArea>();
299 GameObjectDrop.Drop(GameObjectDrag);
300 FullCircle(GameObjectDrop);
301 GameObjectDrag.transform.parent = GameObjectDrop.transform.parent;
302 GameObjectDrag.transform.localScale = Vector3.one;
303 GameObjectDrag.transform.localPosition = Vector3.zero;
304 connectionGameObject.transform.parent = GameObjectDrop.transform.parent;
305 GameObjectDrop.gameObject.AddComponent<Reserved>();
306 }
307 if (isSmall)
308 {
309 //OriginalSize = rt.sizeDelta;
310 ActionSlot.transform.localScale = new Vector3(0, 0, 0);
311 GameObjectSlot.transform.localScale = new Vector3(0, 0, 0);
312 addItems.transform.localScale = new Vector3(0, 0, 0);
313 rt.sizeDelta = new Vector2(200,200);
314 addItems.Count.SetActive(true);
315 ActionCount = 0;
316 ActionSlotChildren = ActionSlot.GetComponentsInChildren<ActionObject>();
317 foreach (var a in ActionSlotChildren)
318 {
319 if (a.GetComponent<ActionObject>())
320 {
321 ActionCount++;
322 }
323 }
324 addItems.textfield.text = ActionCount.ToString();
325 }
326 if (inOrder)
327 {
328 toggle.GetComponent<Toggle>().isOn = true;
329 }
330 else
331 {
332 toggle.GetComponent<Toggle>().isOn = false;
333 }
334 if (Welding)
335 {
336 weldToggle.GetComponent<Toggle>().isOn = true;
337 }
338 else
339 {
340 weldToggle.GetComponent<Toggle>().isOn = false;
341 }
342 }
343
344
345 public override void OutputAdded(string id)
346 {
347 base.OutputAdded(id);
348 }
349
350 public override void InputAdded(string id)
351 {
352 base.InputAdded(id);
353 foreach (var i in inPuts)
354 {
355 if (i.name == id)
356 {
357 inGO = i;
358 break;
359 }
360 }
361 //ChildIndex = inGO.transform.GetSiblingIndex();
362 //inGO.transform.SetSiblingIndex(ChildIndex-1);
363 }
364
365 public void FullCircle(DropArea dropArea)
366 {
367 Sprite FullCircle = Resources.Load<Sprite>("T_ReticleClosed");
368 ReferenceSaver rsgo = dropArea.transform.parent.GetComponent<ReferenceSaver>();
369 rsgo.Reference.transform.Find("ExtendGO").transform.Find("ExtendButton").gameObject.GetComponent<Image>().sprite = FullCircle;
370 }
371
372 public CollectorAction(SerializationInfo info, StreamingContext context) : base(info, context)
373 {
374 ActionChildCount = info.GetInt32("childCount");
375 ActionChildrenList = (List<string>)info.GetValue("actionchildren", typeof(List<string>));
376 GameObjectChildrenList = (List<string>)info.GetValue("gameobjectchildren", typeof(List<string>));
377 isSmall = info.GetBoolean("size");
378 OriginalSize = (Vector2)info.GetValue("sizedelta", typeof(Vector2));
379 inOrder = info.GetBoolean("inorder");
380 Welding = info.GetBoolean("welding");
381 }
382
383 public new void GetObjectData(SerializationInfo info, StreamingContext context)
384 {
385 collector = gameObject.GetComponentInParent<CollectorAction>().gameObject;
386 rt = (RectTransform)collector.transform;
387 width = rt.rect.width;
388 height = rt.rect.height;
390 if (width == 200)
391 {
392 isSmall = true;
393 }
394 else
395 {
396 isSmall = false;
397 }
398 ActionChildrenList = new List<string>();
399 GameObjectChildrenList = new List<string>();
400 ActionChildCount = ActionSlot.transform.childCount;
401 base.GetObjectData(info, context);
402 foreach (Transform a in ActionSlot.transform)
403 {
404 if (a.GetComponentInChildren<ActionObject>())
405 {
406 ActionChildrenList.Add(a.GetComponentInChildren<ActionObject>().name);
407 }
408 else
409 {
410 ActionChildrenList.Add("");
411 }
412 }
413 foreach (Transform a in GameObjectSlot.transform)
414 {
415 if (a.GetComponentInChildren<ActionObject>())
416 {
417 GameObjectChildrenList.Add(a.GetComponentInChildren<ActionObject>().name);
418 }
419 else
420 {
422 }
423 }
424 info.AddValue("childCount", ActionChildCount, typeof(int));
425 info.AddValue("size", isSmall, typeof(bool));
426 info.AddValue("actionchildren", ActionChildrenList, typeof(List<string>));
427 info.AddValue("gameobjectchildren", GameObjectChildrenList, typeof(List<string>));
428 info.AddValue("sizedelta", OriginalSize, typeof(Vector2));
429 info.AddValue("inorder", inOrder, typeof(bool));
430 info.AddValue("welding", Welding, typeof(bool));
431 }
432}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
System.Drawing.Image Image
Definition: TestScript.cs:37
void TriggerOutput(string id)
string action
Definition: ActionObject.cs:32
virtual void Triggered(string id)
List< GameObject > inPuts
Definition: ActionObject.cs:18
List< GameObject > outPuts
Definition: ActionObject.cs:19
GameObject _AddButton()
Definition: AddItems.cs:74
Text textfield
Definition: AddItems.cs:34
Vector2 OriginalSize
Definition: AddItems.cs:28
GameObject Count
Definition: AddItems.cs:35
GameObject SlotHolder
override void Triggered(string id)
override void InputAdded(string id)
List< string > ActionChildrenList
override void OutputAdded(string id)
new void GetObjectData(SerializationInfo info, StreamingContext context)
void Order(bool newValue)
void FullCircle(DropArea dropArea)
GameObject ActionSlot
override void Reset()
GameObject GameObjectSlot
static CollectorAction _Instance
void Weld(bool newWeldValue)
List< string > GameObjectChildrenList
CollectorAction(SerializationInfo info, StreamingContext context)
List< string > GetOutputConnectionsToObject(string id)
Definition: Controller.cs:899
void DirektTrigger(string id)
Definition: Controller.cs:915
ActionObject GetActionById(string id)
Definition: Controller.cs:950
static Controller Instance
Definition: Controller.cs:16
void Drop(MouseDragBehaviour draggable)
Definition: DropArea.cs:15
GameObject Reference
Credit Erdener Gonenc - @PixelEnvision.