Tanoda
ActionObject.cs
Go to the documentation of this file.
1using NaughtyAttributes;
2using System;
3using System.Collections;
4using System.Collections.Generic;
5using System.Linq;
6using System.Runtime.Serialization;
8using UnityEngine;
10using UnityEngine.UI;
11#if DANA
12using Valve.VR.InteractionSystem;
13#endif
14
15[Serializable]
16public class ActionObject : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISerializable
17{
18 public List<GameObject> inPuts;
19 public List<GameObject> outPuts;
20 [ClassExtends(typeof(ActionObject))] public List<ClassTypeReference> acceptInputTypes;
22
23 internal Dictionary<string, GameObject> inIDs;
24 internal Dictionary<string, GameObject> outIDs;
25
26 internal bool actionStarted, actionRecognized;
27 internal float spentTimeOnAction, recognitionTimeOnAction;
28 internal float penaltyTime = 0.0f;
29 internal float timeInUse = 0.0f;
30 internal float taktTime = 0.0f;
31
32 public string action, ID;
33
34 public string comment;
35
36 public List<GameObject> hideOnMinimize = new List<GameObject>();
37 protected float originalHeight = 0.0f;
38 private List<Vector2> origInPositions;
39 internal bool minimized = false;
40 private bool inAnim = false;
41
42 internal bool setupOk = false;
43 private bool die = false;
44 public bool IsCounting;
45 internal bool FailedTakt = false;
46
47
48 public void ToggleWindowSize()
49 {
50 if (inAnim) return;
51 inAnim = true;
52 if (minimized)
53 {
54 Maximize();
55 }
56 else
57 {
58 Minimize();
59 }
60 minimized = !minimized;
61 }
62
63 public IEnumerator LateMinimize()
64 {
65 for (int i = 0; i < 10; i++)
66 {
67 while (LoadingManager.instance.isLoading || LoadingManager.instance.MainLoading)
68 {
69 yield return null;
70 }
71 yield return new WaitForSeconds(0.1f);
72 }
73
75 }
76
77
78 public void InstaMinimize()
79 {
80 foreach (var o in hideOnMinimize)
81 {
82 var cg = o.GetComponent<CanvasGroup>();
83 if (!cg) cg = o.AddComponent<CanvasGroup>();
84
85 cg.alpha = 0f;
86 cg.blocksRaycasts = false;
87 }
88
89 float smallHeight = 85f;
90 var isThisWaiterAction = this is WaiterAction;
91 (transform as RectTransform).SetHeight(smallHeight);
92 for (int k = 0; k < outPuts.Count; k++)
93 {
94 GameObject o = outPuts[k];
95 var rt = o.transform as RectTransform;
96 rt.localScale = Vector3.one * 0.45f;
97 }
98
99 for (var j = 0; j < inPuts.Count; j++)
100 {
101 var o = inPuts[j];
102 var rt = o.transform as RectTransform;
103 rt.localScale = Vector3.one * 0.45f;
104 rt.anchoredPosition = (isThisWaiterAction ? new Vector2(30, 0) : Vector2.zero);
105 }
106 try
107 {
109 }
110 catch (Exception)
111 {
112 }
113 }
114
115 [Button]
116 public void Minimize()
117 {
118 foreach (var o in hideOnMinimize)
119 {
120 var cg = o.GetComponent<CanvasGroup>();
121 if (!cg) cg = o.AddComponent<CanvasGroup>();
122 StartCoroutine(CanvasFade(cg, true));
123 }
124
125 StartCoroutine(minimize());
126 }
127
128 [Button]
129 public void Maximize()
130 {
131 foreach (var o in hideOnMinimize)
132 {
133 var cg = o.GetComponent<CanvasGroup>();
134 if (!cg) cg = o.AddComponent<CanvasGroup>();
135 StartCoroutine(CanvasFade(cg, false));
136 }
137
138 StartCoroutine(maximize());
139 }
140
141 private IEnumerator CanvasFade(CanvasGroup cg, bool hide = true)
142 {
143 for (int i = 0; i <= 30; i++)
144 {
145 if (hide)
146 {
147 cg.alpha = 1 - i / 30f;
148 cg.blocksRaycasts = false;
149 }
150 else
151 {
152 cg.alpha = i / 30f;
153 cg.blocksRaycasts = true;
154 }
155 yield return null;
156 }
157 }
158
159 private IEnumerator minimize()
160 {
161 float smallHeight = 85f;
162 var isThisWaiterAction = this is WaiterAction;
163 for (int i = 0; i <= 30; i++)
164 {
165 (transform as RectTransform).SetHeight(Mathf.Lerp(originalHeight, smallHeight, i / 30f));
166 for (int k = 0; k < outPuts.Count; k++)
167 {
168 GameObject o = outPuts[k];
169 var rt = o.transform as RectTransform;
170 rt.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.45f, i / 30f);
171 }
172
173 for (var j = 0; j < inPuts.Count; j++)
174 {
175 var o = inPuts[j];
176 var rt = o.transform as RectTransform;
177 rt.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.45f, i / 30f);
178 rt.anchoredPosition = Vector2.Lerp(origInPositions[j], isThisWaiterAction ? new Vector2(30, 0) : Vector2.zero, i / 30f);
179
180 }
181 bool fail = false;
182 try
183 {
185 }
186 catch (Exception)
187 {
188 fail = true;
189 }
190 if (fail)
191 yield return new WaitForSeconds(1.0f);
192
193 yield return null;
194 }
195 inAnim = false;
196 }
197 private IEnumerator maximize()
198 {
199 float smallHeight = 85f;
200 var isThisWaiterAction = this is WaiterAction;
201 for (int i = 0; i <= 30; i++)
202 {
203 (transform as RectTransform).SetHeight(Mathf.Lerp(originalHeight, smallHeight, 1 - i / 30f));
204 for (int k = 0; k < outPuts.Count; k++)
205 {
206 GameObject o = outPuts[k];
207 o.transform.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.45f, 1 - i / 30f);
208 }
209
210 for (var j = 0; j < inPuts.Count; j++)
211 {
212 var o = inPuts[j];
213 var rt = o.transform as RectTransform;
214 rt.localScale = Vector3.Lerp(Vector3.one, Vector3.one * 0.45f, 1 - i / 30f);
215 rt.anchoredPosition = Vector2.Lerp(origInPositions[j], isThisWaiterAction ? new Vector2(30, 0) : Vector2.zero, 1 - i / 30f);
216 }
217
219 yield return null;
220 }
221 inAnim = false;
222 }
223
224 public void GetOriginalHeight()
225 {
226 originalHeight = (transform as RectTransform).sizeDelta.y;
227 }
228
229 public List<Vector2> GetSides()
230 {
231 var retval = new List<Vector2>();
232
233 Vector3[] v = new Vector3[4];
234 (transform as RectTransform).GetWorldCorners(v);
235
236 foreach (var vector3 in v)
237 {
238 retval.Add(vector3);
239 }
240
241 return retval;
242 }
243
244 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
245 {
246 info.AddValue("name", name, typeof(string));
247 info.AddValue("comment", comment, typeof(string));
248 info.AddValue("minimized", minimized, typeof(bool));
249 info.AddValue("acceptInputTypes", acceptInputTypes);
250 info.AddValue("inIDs", inIDs);
251 info.AddValue("outIDs", outIDs);
252 info.AddValue("localPos", transform.localPosition, typeof(Vector3));
253 }
254
256 {
257 }
258
259 public ActionObject(SerializationInfo info, StreamingContext context)
260 {
261 Transform abortion = GameObject.Find("abortion")?.transform;
262 if (abortion == null) abortion = new GameObject("abortion").transform;
263 var dontcrashhack = new GameObject((string)info.GetValue("name", typeof(string)));
264 ID =(string)info.GetValue("name", typeof(string));
265 dontcrashhack.transform.SetParent(abortion);
266 inIDs = (Dictionary<string, GameObject>)info.GetValue("inIDs", typeof(Dictionary<string, GameObject>));
267 outIDs = (Dictionary<string, GameObject>)info.GetValue("outIDs", typeof(Dictionary<string, GameObject>));
269 (List<ClassTypeReference>)info.GetValue("acceptInputTypes", typeof(List<ClassTypeReference>));
270 dontcrashhack.transform.localPosition = (Vector3)info.GetValue("localPos", typeof(Vector3));
271
272 try
273 {
274 comment = info.GetString("comment");
275 }
276 catch (Exception)
277 {
278 // backward compatible
279 }
280 try
281 {
282 minimized = info.GetBoolean("minimized");
283 }
284 catch (Exception)
285 {
286 // backward compatible
287 }
288 }
289
290 // Start is called before the first frame update
291 public virtual void Start()
292 {
293 //if (inPuts == null && outPuts == null) //only temp object after load, can destroy
294 //{
295 // Destroy(gameObject);
296 // return;
297 //}
298
299#if UNITY_WEBGL
300 Destroy(statusImg.gameObject);
301#endif
302 //originalHeight = (transform as RectTransform).sizeDelta.y;
304
305#if DANA
306 var titleTrans = transform.Find("Window Title Bar");
307 Transform remove = null;
308 Transform minimize = null;
309
310
311 if (titleTrans)
312 {
313 //Sprite header = (Sprite)AssetDatabase2956.LoadAssetAtPath("Assets/Textures/UI/Actions/Header.png", typeof(Sprite));
314 Sprite body = Resources.Load<Sprite>("Body");//(Sprite)AssetDatabase.LoadAssetAtPath("Assets/Textures/UI/Actions/Body.png", typeof(Sprite));
315
316 Sprite exit = Resources.Load<Sprite>("exit2");//(Sprite)AssetDatabase.LoadAssetAtPath("Assets/Textures/newdesign/exit.png", typeof(Sprite));
317 var title = titleTrans.gameObject;
318 var titleText = title.GetComponentInChildren<Text>();
319 var img = title.GetComponent<Image>();
320 var bodyImg = GetComponent<Image>();
321 var textfields = GetComponentsInChildren<Text>();
322 if (titleTrans.transform.Find("Remove"))
323 {
324 remove = titleTrans.transform.Find("Remove");
325 minimize = titleTrans.transform.Find("Minimize");
326 }
327 var inputFields = GetComponentsInChildren<InputField>();
328 if (remove)
329 {
330 remove.GetComponent<Image>().enabled = false;
331 remove.GetChild(0).GetComponent<Image>().sprite = exit;
332 remove.GetChild(0).GetComponent<Image>().color = new Color(0, 38f / 255f, 137f / 255f);
333 remove.GetComponent<RectTransform>().sizeDelta = new Vector2(15, 0);
334 var pos = remove.GetComponent<RectTransform>().localPosition;
335 remove.GetComponent<RectTransform>().localPosition = new Vector3(pos.x - 15f, pos.y, pos.z);
336 }
337 if (minimize)
338 {
339 minimize.GetComponent<Image>().enabled = false;
340 minimize.GetComponent<RectTransform>().sizeDelta = new Vector2(15, 0);
341 minimize.GetChild(0).GetComponent<Image>().color = new Color(0, 38f / 255f, 137f / 255f);
342 var posMin = remove.GetComponent<RectTransform>().localPosition;
343 minimize.GetComponent<RectTransform>().localPosition = new Vector3(posMin.x - 30f, posMin.y, posMin.z);
344 }
345
346
347
348
349 foreach (var text in textfields)
350 {
351 text.color = new Color(0f, 38f/255f, 137f/255f);
352 //text.text = text.text.ToUpper();
353 text.fontSize = 16;
354 }
355 foreach (var field in inputFields)
356 {
357 Sprite background = Resources.Load<Sprite>("White Background");//(Sprite)AssetDatabase.LoadAssetAtPath("Assets/GILES/Resources/Required/Image/White Background.png", typeof(Sprite));
358 var textsInChildren = field.GetComponentsInChildren<Text>();
359 foreach (var text in textsInChildren)
360 {
361 text.GetComponentInChildren<Text>().color = new Color(1f, 1f, 1f);
362 text.GetComponentInChildren<Text>().fontSize = 14;
363 }
364 field.GetComponent<Image>().color = new Color(0f, 38f / 255f, 137f / 255f);
365 field.GetComponent<Image>().sprite = background;
366 }
367 //titleText.fontStyle = FontStyle.Bold;
368 //img.color = new Color(150f / 255f, 150f / 255f, 150f / 255f);
369 //img.color = new Color(1f, 1f, 1f);
370 img.enabled = false;
371 bodyImg.color = new Color(1f, 1f, 1f);
372 //img.sprite = GameObject.Find("AOTHelper").GetComponent<Image>().sprite;
373 //img.sprite = header;
374 bodyImg.sprite = body;
375 var recttrans = title.GetComponent<RectTransform>();
376 recttrans.sizeDelta.Set(recttrans.sizeDelta.x, 36f);
377 recttrans.SetLeft(0);
378 recttrans.SetRight(0);
379 recttrans.SetTop(0);
380 recttrans.SetHeight(32);
381
382#if DEVELOPMENT_BUILD
383 titleTrans.GetComponentInChildren<Text>().text = name;
384#endif
385 }
386 //if (!titleTrans)
387 //{
388 // Sprite body = (Sprite)AssetDatabase.LoadAssetAtPath("Assets/Textures/UI/Actions/Body.png", typeof(Sprite));
389 // var bodyImg = GetComponent<Image>();
390 // bodyImg.sprite = body;
391 // bodyImg.color = new Color(1f, 1f, 1f);
392 // var texts = GetComponentsInChildren<Text>();
393 // foreach (var item in texts)
394 // {
395 // item.color = new Color(0f, 38f / 255f, 137f / 255f);
396 // }
397 // if (GetComponentInChildren<Button>())
398 // {
399 // var button = GetComponentInChildren<Button>();
400 // button.transition = Selectable.Transition.None;
401 // var images = GetComponentInChildren<Button>().GetComponentsInChildren<Image>();
402 // foreach (var image in images)
403 // {
404 // image.color = new Color(0f, 38f / 255f, 137f / 255f);
405 // }
406 // }
407 //}
408
409 var statusLed = transform.Find("Image");
410 if (statusLed)
411 statusLed.gameObject.GetComponent<Image>().sprite =
412 GameObject.Find("CircleHelper").GetComponent<Image>().sprite;
413#endif
414
415#if UNITY_WEBGL
416 var aotHelper = GameObject.Find("AOTHelper").GetComponent<Image>();
417 var titleTrans = transform.Find("Window Title Bar");
418 if (titleTrans)
419 {
420 var title = titleTrans.gameObject;
421 var img = title.GetComponent<Image>();
422 img.color = new Color(150f / 255f, 150f / 255f, 150f / 255f);
423 img.sprite = aotHelper.sprite;
424 img.pixelsPerUnitMultiplier = 2f;
425 img.material = aotHelper.material;
426 var recttrans = title.GetComponent<RectTransform>();
427 recttrans.sizeDelta.Set(recttrans.sizeDelta.x, 35f);
428 recttrans.SetLeft(0);
429 recttrans.SetRight(0);
430 recttrans.SetTop(0);
431
432 if (titleTrans.childCount >= 2)
433 titleTrans.GetChild(1) /*Remove*/.gameObject.GetComponent<Image>().enabled = false;
434
435 var allInputField = gameObject.GetComponentsInChildren<InputField>();
436 var allButton = gameObject.GetComponentsInChildren<Button>();
437 var allToggle = gameObject.GetComponentsInChildren<Toggle>();
438 var allDropdown = gameObject.GetComponentsInChildren<Dropdown>();
439
440 foreach (var input in allInputField)
441 {
442 input.image.color = new Color(57 / 255f, 190 / 255f, 187 / 255f, 0.5f);
443 input.textComponent.color = Color.white;
444 }
445
446 var buttonImageReplacer = GameObject.Find("ButtonImageReplacer").GetComponent<Image>();
447 foreach (var b in allButton)
448 {
449 if (b.name == "Remove" || b.name == "SoundPreview")
450 continue;
451
452 try
453 {
454 b.image.sprite = buttonImageReplacer.sprite;
455 b.image.color = buttonImageReplacer.color;
456 b.image.material = buttonImageReplacer.material;
457 b.image.pixelsPerUnitMultiplier = 4f;
458 var text = b.transform.GetComponentInChildren<Text>();
459 if (text)
460 text.color =
461 //new Color(57 / 255f, 190 / 255f, 187 / 255f, 1f);
462 Color.white;
463 }
464 catch (Exception)
465 {
466 // ignored
467 }
468 }
469
470 if (!(this is ShowHideAction) && !(this is PositionAction))
471 {
472 var toggleCheckmark = GameObject.Find("ToggleCheckmark").GetComponent<Image>();
473 foreach (var toggle in allToggle)
474 {
475 (toggle.graphic as Image).sprite = toggleCheckmark.sprite;
476 toggle.graphic.color = Color.white;
477 toggle.image.color = new Color(57 / 255f, 190 / 255f, 187 / 255f, 1f);
478 }
479
480 }
481
482 foreach (var dropdown in allDropdown)
483 {
484 dropdown.image.color = new Color(57 / 255f, 190 / 255f, 187 / 255f, 1f);
485 dropdown.captionText.color = Color.white;
486 dropdown.itemText.color = Color.white;
487 var image = dropdown.template.GetComponentInChildren<Image>();
488 if (image)
489 image.color =
490 new Color(57 / 255f, 190 / 255f, 187 / 255f, 1f);
491 dropdown.template.GetChild(0).GetChild(0).GetChild(0).GetChild(0).GetComponent<Image>().color =
492 new Color(57 / 255f, 190 / 255f, 187 / 255f, 1f);
493 var sb = dropdown.GetComponentInChildren<Scrollbar>(true);
494 if (sb)
495 {
496 var sbrect = (sb.transform as RectTransform);
497 sbrect?.sizeDelta.Set(10f, sbrect.sizeDelta.y);
498 sb.image.color = new Color(51f / 255, 121f / 255, 120f / 255);
499 }
500 }
501 }
502
503 var bgImage = GetComponent<Image>();
504 bgImage.pixelsPerUnitMultiplier = 2f;
505 bgImage.sprite = aotHelper.sprite;
506
507
508 var statusLed = transform.Find("Image");
509 if (statusLed)
510 {
511 statusLed.gameObject.GetComponent<Image>().sprite =
512 GameObject.Find("CircleHelper").GetComponent<Image>().sprite;
513 }
514#endif
515
516 if (inIDs != null) //already initialized from loading
517 return;
518
519 inIDs = new Dictionary<string, GameObject>();
520 outIDs = new Dictionary<string, GameObject>();
521
522 foreach (var item in inPuts) AddInput(item);
523
524 foreach (var item in outPuts) AddOutput(item);
525
526 Controller.Instance.OnTrigger += Instance_OnTrigger;
527 }
528
529 protected void SaveOrigInPos()
530 {
531 StartCoroutine(saveOrigInPos());
532 }
533
534 private IEnumerator saveOrigInPos()
535 {
536 yield return null;
537 origInPositions = new List<Vector2>();
538 if (inPuts != null)
539 foreach (var o in inPuts)
540 {
541 origInPositions.Add((o.transform as RectTransform).anchoredPosition);
542 }
543 }
544
545 internal void OnDestroy()
546 {
547 if (Controller.Instance != null)
548 Controller.Instance.OnTrigger -= Instance_OnTrigger;
549 Destroy(gameObject);
550 }
551
552 private void Instance_OnTrigger(string id)
553 {
554 if (GetInputs().Contains(id)) Triggered(id);
555 }
556
557 public virtual void Triggered(string id)
558 {
559#if !UNITY_WEBGL
560 gameObject.GetComponent<Image>().color = new Color(57 / 255f, 190 / 255f, 187 / 255f, 200f / 255f);
561 statusImg.color = Color.green;
562 actionRecognized = false;
563 spentTimeOnAction = 0;
564 timeInUse = 0;
565#endif
566 if (!Blacklisted() || action.Contains("Waiter"))
567 {
568 actionStarted = true;
569#if DANA
570 HandHintSystem.instance.ActionStarted(this);
571#endif
572 }
573 }
574
575 public virtual void Deactivate()
576 {
577 }
578
579 private bool Blacklisted()
580 {
581 return action.Contains("Waiter") || action.Contains("GameObject") || action.Contains("Weld") ||
582 action.Contains("Led") || action.Contains("Start") || action.Contains("Sound") ||
583 action.Contains("Move") || action.Contains("Belt") || action.Contains("ShowHide") || action.Contains("Deactivate") || action.Contains("Script") || action.Contains("Collector");
584 }
585
586 private bool CantRecognize()
587 {
588 return action.Contains("Waiter") || action.Contains("GameObject") || action.Contains("Weld") ||
589 action.Contains("Led") || action.Contains("Start") || action.Contains("Sound") ||
590 action.Contains("Move") || action.Contains("Belt") || action.Contains("ShowHide") || action.Contains("Deactivate") || action.Contains("Script") || action.Contains("Collector") || action.Contains("Voice");
591 }
592 public virtual void Reset()
593 {
594 }
595
596 public virtual void OutputAdded(string id)
597 {
598 }
599
600 public virtual void InputAdded(string id)
601 {
602 }
603
604 public virtual void Remove()
605 {
606 Deactivate();
607 Controller.Instance.RemoveAction(gameObject.name);
608 }
609
610 public void TriggerOutput(string id)
611 {
612
613#if !UNITY_WEBGL
614 System.Diagnostics.Stopwatch stopwatch = new System.Diagnostics.Stopwatch();
615 stopwatch.Start();
616 gameObject.GetComponent<Image>().color = new Color(1f, 1f, 1f, 255f / 255f);
617 statusImg.color = Color.red;
618#endif
620 actionStarted = false;
621 if (id != GetInput() && !Blacklisted())
622 {
624 }
625
626 if (!Blacklisted() || action.Contains("Waiter"))
627 {
628 SavedUser.instance.ActionCompleted(action, spentTimeOnAction, recognitionTimeOnAction, penaltyTime, this.name, comment, taktTime);
629 if (taktTime > 0 && spentTimeOnAction > taktTime)
630 {
632 {
633 FailedTakt = true;
634 }
635 UserStatManager.instance.PenaltyList.Add(spentTimeOnAction - taktTime);
636
637 }
638 if (!Blacklisted())
639 {
640 UserStatManager.instance.RecognitionList.Add(recognitionTimeOnAction);
641 UserStatManager.instance.TimeSpendList.Add(spentTimeOnAction);
642 UserStatManager.instance.PenaltyList.Add(penaltyTime);
643#if DANA
644 Debug.Log("Action: " + action + "\n" + " Recognition: " + Mathf.FloorToInt(recognitionTimeOnAction / 60).ToString("D2") + ":" + (recognitionTimeOnAction % 60).ToString("00.00").Replace(',', '.') +
645 "\n" + "TimeOnAction: " + Mathf.FloorToInt(spentTimeOnAction / 60).ToString("D2") + ":" + (spentTimeOnAction % 60).ToString("00.00").Replace(',', '.') +
646 "\n" + " Penalty: " + Mathf.FloorToInt(PenaltyCounter.Instance.penaltyTime / 60).ToString("D2") + ":" + (PenaltyCounter.Instance.penaltyTime % 60).ToString("00.00").Replace(',', '.'));
647#endif
648 }
649
650
651
652 //CreateText("Action: " + action + " ,time: " +
653 // Mathf.FloorToInt(spentTimeOnAction / 60).ToString("D2") + ":" + (spentTimeOnAction % 60).ToString("00.00").Replace(',', '.') + " ,recognition Time: " +
654 // Mathf.FloorToInt(recognitionTimeOnAction / 60).ToString("D2") + ":" + (recognitionTimeOnAction % 60).ToString("00.00").Replace(',', '.'));
655#if DANA
656 HandHintSystem.instance.ActionFinished(this);
657#endif
658 }
659 }
660
661 public void AddInput(GameObject go)
662 {
663 var id = Guid.NewGuid().ToString();
664 inIDs.Add(id, go);
665 go.name = id;
666 go.tag = "ACTION_INPUT";
667 }
668 public string GetInput()
669 {
670 try
671 {
672 return inIDs.Keys.ToList()[0];
673 }
674 catch (Exception)
675 {
676 return null;
677 }
678 }
679 public string GetInput(int index)
680 {
681 try
682 {
683 return inIDs.Keys.ToList()[index];
684 }
685 catch (Exception)
686 {
687 return null;
688 }
689 }
690 public void RemoveInput(string id)
691 {
692 //Remove Connections
694
695 //Remove GameObject
696 inPuts.Remove(inIDs[id]);
697 DestroyImmediate(inIDs[id]);
698
699 //Remove Input
700 inIDs.Remove(id);
701 }
702
703 public void AddOutput(GameObject go)
704 {
705 var id = Guid.NewGuid().ToString();
706 outIDs.Add(id, go);
707 go.name = id;
708 go.AddComponent<DrawLine>();
709 }
710
711 public GameObject GetOutput(string id)
712 {
713 return outIDs[id];
714 }
715
716 public GameObject GetInput(string id)
717 {
718 return inIDs[id];
719 }
720
721 public List<string> GetOutputs()
722 {
723 return outIDs.Keys.ToList();
724 }
725
726 public List<string> GetInputs()
727 {
728 return inIDs.Keys.ToList();
729 }
730
731 public bool LimitInputTypes()
732 {
733 return acceptInputTypes != null && acceptInputTypes.Count > 0;
734 }
735
736 public List<Type> GetAcceptedInputTypes()
737 {
738 var retval = new List<Type>();
739 foreach (var classTypeReference in acceptInputTypes) retval.Add(classTypeReference.Type);
740
741 return retval;
742 }
743
744 internal void Update()
745 {
746 if (!CantRecognize())
747 {
748 if (actionStarted && !actionRecognized)
749 {
750 recognitionTimeOnAction += Time.deltaTime;
751 }
752
753
754 if (!actionStarted) return;
755 spentTimeOnAction += Time.deltaTime;
756#if DANA
757 var playerHands = Player.instance.hands;
758 List<bool> atph = new List<bool>();
759 foreach (var hand in playerHands)
760 {
761 var hh = hand.GetComponent<HackedHand>();
762 if (hh && hh.attachedToHand) atph.Add(true);
763 else if (hh && hh.realToolInHand) atph.Add(true);
764 }
765 if (atph.Count > 0)
766 {
767 timeInUse += Time.deltaTime;
768 }
769#endif
770
771 }
772
773 }
774
775 public void ApplyComment()
776 {
777 StartCoroutine(LateCommentApply());
778 }
779
780 private IEnumerator LateCommentApply()
781 {
782 yield return new WaitForSeconds(1);
783 try
784 {
785 var nc = GetComponentInChildren<NodeComment>(true);
786 if (nc)
787 {
788 nc.displayText.text = comment;
789 nc.inputField.text = comment;
790 //nc.RecalculateSize();
791 }
792 }
793 catch (Exception)
794 {
795 // ignored
796 }
797 }
798
799 public void TriggerOut(string id)
800 {
802 actionStarted = false;
803 if (!Blacklisted() || action.Contains("Waiter"))
804 {
805
806#if DANA
807 SavedUser.instance.ActionCompleted(action, spentTimeOnAction, recognitionTimeOnAction, penaltyTime, this.name, comment, taktTime);
808 HandHintSystem.instance.ActionFinished(this);
809#endif
810 }
811 }
812
813 internal bool isInFieldOfView(GameObject interactedGO)
814 {
815 var taggedCam = GameObject.FindWithTag("VRCamera");
816 if (taggedCam == null) return false; // ha nincs headset/steamvr
817 var VRCamera = taggedCam.GetComponent<Camera>();
818 if (interactedGO != null)
819 {
820 Vector3 screenPoint = VRCamera.WorldToViewportPoint(interactedGO.transform.position);
821 bool onScreen = screenPoint.z > 0 && screenPoint.x > 0 && screenPoint.x < 1 && screenPoint.y > 0 && screenPoint.y < 1;
822 return onScreen;
823 }
824 else
825 {
826 return false;
827 }
828
829
830 }
831
832
833
834 public virtual void OnPointerEnter(PointerEventData eventData)
835 {
836
837 }
838
839 public virtual void OnPointerExit(PointerEventData eventData)
840 {
841
842 }
843}
844
845public static class RectTransformExtensions
846{
847 public static void SetLeft(this RectTransform rt, float left)
848 {
849 rt.offsetMin = new Vector2(left, rt.offsetMin.y);
850 }
851
852 public static void SetRight(this RectTransform rt, float right)
853 {
854 rt.offsetMax = new Vector2(-right, rt.offsetMax.y);
855 }
856
857 public static void SetTop(this RectTransform rt, float top)
858 {
859 rt.offsetMax = new Vector2(rt.offsetMax.x, -top);
860 }
861
862 public static void SetBottom(this RectTransform rt, float bottom)
863 {
864 rt.offsetMin = new Vector2(rt.offsetMin.x, bottom);
865 }
866 public static void SetHeight(this RectTransform rt, float height)
867 {
868 rt.sizeDelta = new Vector2(rt.sizeDelta.x, height);
869 }
870 public static void SetWidth(this RectTransform rt, float width)
871 {
872 rt.sizeDelta = new Vector2(width, rt.sizeDelta.y);
873 }
874
875
876}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
virtual void OnPointerEnter(PointerEventData eventData)
Image statusImg
Definition: ActionObject.cs:21
virtual void InputAdded(string id)
List< string > GetInputs()
virtual void Deactivate()
virtual void Reset()
void RemoveInput(string id)
GameObject GetOutput(string id)
float originalHeight
Definition: ActionObject.cs:37
void TriggerOutput(string id)
void ToggleWindowSize()
Definition: ActionObject.cs:48
virtual void Start()
string GetInput(int index)
bool LimitInputTypes()
void GetOriginalHeight()
void InstaMinimize()
Definition: ActionObject.cs:78
void TriggerOut(string id)
void AddOutput(GameObject go)
void Minimize()
string action
Definition: ActionObject.cs:32
List< Vector2 > GetSides()
List< string > GetOutputs()
virtual void Triggered(string id)
List< GameObject > inPuts
Definition: ActionObject.cs:18
string comment
Definition: ActionObject.cs:34
virtual void OutputAdded(string id)
List< GameObject > outPuts
Definition: ActionObject.cs:19
void Maximize()
void SaveOrigInPos()
void ApplyComment()
GameObject GetInput(string id)
ActionObject(SerializationInfo info, StreamingContext context)
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
List< GameObject > hideOnMinimize
Definition: ActionObject.cs:36
List< Type > GetAcceptedInputTypes()
string GetInput()
virtual void Remove()
void AddInput(GameObject go)
virtual void OnPointerExit(PointerEventData eventData)
IEnumerator LateMinimize()
Definition: ActionObject.cs:63
List< ClassTypeReference > acceptInputTypes
Definition: ActionObject.cs:20
void RemoveConnectionByEndPointId(string id)
Definition: Controller.cs:842
static Controller Instance
Definition: Controller.cs:16
void Trigger(string id)
Definition: Controller.cs:910
void RemoveAction(string id)
Definition: Controller.cs:727
TriggerHandler OnTrigger
Definition: Controller.cs:20
void StopFollowing()
Definition: FollowMe.cs:28
static FollowMe Instance
Definition: FollowMe.cs:19
static HandHintSystem instance
static LineDrawer Instance
Definition: LineDrawer.cs:16
void ReDraw(string id)
Definition: LineDrawer.cs:235
static PenaltyCounter Instance