1using NaughtyAttributes;
3using System.Collections;
4using System.Collections.Generic;
6using System.Runtime.Serialization;
12using Valve.VR.InteractionSystem;
16public class ActionObject : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, ISerializable
23 internal Dictionary<string, GameObject> inIDs;
24 internal Dictionary<string, GameObject> outIDs;
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;
38 private List<Vector2> origInPositions;
39 internal bool minimized =
false;
40 private bool inAnim =
false;
42 internal bool setupOk =
false;
43 private bool die =
false;
45 internal bool FailedTakt =
false;
60 minimized = !minimized;
65 for (
int i = 0; i < 10; i++)
71 yield
return new WaitForSeconds(0.1f);
82 var cg = o.GetComponent<CanvasGroup>();
83 if (!cg) cg = o.AddComponent<CanvasGroup>();
86 cg.blocksRaycasts =
false;
89 float smallHeight = 85f;
91 (transform as RectTransform).SetHeight(smallHeight);
92 for (
int k = 0; k <
outPuts.Count; k++)
95 var rt = o.transform as RectTransform;
96 rt.localScale = Vector3.one * 0.45f;
99 for (var j = 0; j <
inPuts.Count; 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);
120 var cg = o.GetComponent<CanvasGroup>();
121 if (!cg) cg = o.AddComponent<CanvasGroup>();
122 StartCoroutine(CanvasFade(cg,
true));
125 StartCoroutine(minimize());
133 var cg = o.GetComponent<CanvasGroup>();
134 if (!cg) cg = o.AddComponent<CanvasGroup>();
135 StartCoroutine(CanvasFade(cg,
false));
138 StartCoroutine(maximize());
141 private IEnumerator CanvasFade(CanvasGroup cg,
bool hide =
true)
143 for (
int i = 0; i <= 30; i++)
147 cg.alpha = 1 - i / 30f;
148 cg.blocksRaycasts =
false;
153 cg.blocksRaycasts =
true;
159 private IEnumerator minimize()
161 float smallHeight = 85f;
163 for (
int i = 0; i <= 30; i++)
165 (transform as RectTransform).SetHeight(Mathf.Lerp(
originalHeight, smallHeight, i / 30f));
166 for (
int k = 0; k <
outPuts.Count; k++)
169 var rt = o.transform as RectTransform;
173 for (var j = 0; j <
inPuts.Count; j++)
176 var rt = o.transform as RectTransform;
178 rt.anchoredPosition =
Vector2.Lerp(origInPositions[j], isThisWaiterAction ?
new Vector2(30, 0) :
Vector2.zero, i / 30f);
191 yield
return new WaitForSeconds(1.0f);
197 private IEnumerator maximize()
199 float smallHeight = 85f;
201 for (
int i = 0; i <= 30; i++)
203 (transform as RectTransform).SetHeight(Mathf.Lerp(
originalHeight, smallHeight, 1 - i / 30f));
204 for (
int k = 0; k <
outPuts.Count; k++)
210 for (var j = 0; j <
inPuts.Count; j++)
213 var rt = o.transform as RectTransform;
215 rt.anchoredPosition =
Vector2.Lerp(origInPositions[j], isThisWaiterAction ?
new Vector2(30, 0) :
Vector2.zero, 1 - i / 30f);
231 var retval =
new List<Vector2>();
233 Vector3[] v =
new Vector3[4];
234 (transform as RectTransform).GetWorldCorners(v);
236 foreach (var vector3
in v)
244 public virtual void GetObjectData(SerializationInfo info, StreamingContext context)
246 info.AddValue(
"name", name, typeof(
string));
247 info.AddValue(
"comment",
comment, typeof(
string));
248 info.AddValue(
"minimized", minimized, typeof(
bool));
250 info.AddValue(
"inIDs", inIDs);
251 info.AddValue(
"outIDs", outIDs);
252 info.AddValue(
"localPos", transform.localPosition, typeof(Vector3));
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));
274 comment = info.GetString(
"comment");
282 minimized = info.GetBoolean(
"minimized");
306 var titleTrans = transform.Find(
"Window Title Bar");
307 Transform
remove =
null;
308 Transform minimize =
null;
314 Sprite body = Resources.Load<Sprite>(
"Body");
316 Sprite exit = Resources.Load<Sprite>(
"exit2");
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"))
324 remove = titleTrans.transform.Find(
"Remove");
325 minimize = titleTrans.transform.Find(
"Minimize");
327 var inputFields = GetComponentsInChildren<InputField>();
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);
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);
349 foreach (var text
in textfields)
351 text.color =
new Color(0f, 38f/255f, 137f/255f);
355 foreach (var field
in inputFields)
357 Sprite background = Resources.Load<Sprite>(
"White Background");
358 var textsInChildren = field.GetComponentsInChildren<Text>();
359 foreach (var text
in textsInChildren)
361 text.GetComponentInChildren<Text>().color =
new Color(1f, 1f, 1f);
362 text.GetComponentInChildren<Text>().fontSize = 14;
364 field.GetComponent<
Image>().color =
new Color(0f, 38f / 255f, 137f / 255f);
365 field.GetComponent<
Image>().sprite = background;
371 bodyImg.color =
new Color(1f, 1f, 1f);
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);
380 recttrans.SetHeight(32);
383 titleTrans.GetComponentInChildren<Text>().text = name;
409 var statusLed = transform.Find(
"Image");
411 statusLed.gameObject.GetComponent<
Image>().sprite =
412 GameObject.Find(
"CircleHelper").GetComponent<
Image>().sprite;
416 var aotHelper = GameObject.Find(
"AOTHelper").GetComponent<
Image>();
417 var titleTrans = transform.Find(
"Window Title Bar");
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);
432 if (titleTrans.childCount >= 2)
433 titleTrans.GetChild(1) .gameObject.GetComponent<
Image>().enabled =
false;
435 var allInputField = gameObject.GetComponentsInChildren<InputField>();
436 var allButton = gameObject.GetComponentsInChildren<
Button>();
437 var allToggle = gameObject.GetComponentsInChildren<Toggle>();
438 var allDropdown = gameObject.GetComponentsInChildren<Dropdown>();
440 foreach (var input
in allInputField)
442 input.image.color =
new Color(57 / 255f, 190 / 255f, 187 / 255f, 0.5f);
443 input.textComponent.color =
Color.white;
446 var buttonImageReplacer = GameObject.Find(
"ButtonImageReplacer").GetComponent<
Image>();
447 foreach (var b
in allButton)
449 if (b.name ==
"Remove" || b.name ==
"SoundPreview")
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>();
472 var toggleCheckmark = GameObject.Find(
"ToggleCheckmark").GetComponent<
Image>();
473 foreach (var toggle
in allToggle)
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);
482 foreach (var dropdown
in allDropdown)
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>();
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);
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);
503 var bgImage = GetComponent<Image>();
504 bgImage.pixelsPerUnitMultiplier = 2f;
505 bgImage.sprite = aotHelper.sprite;
508 var statusLed = transform.Find(
"Image");
511 statusLed.gameObject.GetComponent<
Image>().sprite =
512 GameObject.Find(
"CircleHelper").GetComponent<
Image>().sprite;
519 inIDs =
new Dictionary<string, GameObject>();
520 outIDs =
new Dictionary<string, GameObject>();
531 StartCoroutine(saveOrigInPos());
534 private IEnumerator saveOrigInPos()
537 origInPositions =
new List<Vector2>();
541 origInPositions.Add((o.transform as RectTransform).anchoredPosition);
545 internal void OnDestroy()
552 private void Instance_OnTrigger(
string id)
560 gameObject.GetComponent<
Image>().color =
new Color(57 / 255f, 190 / 255f, 187 / 255f, 200f / 255f);
562 actionRecognized =
false;
563 spentTimeOnAction = 0;
566 if (!Blacklisted() ||
action.Contains(
"Waiter"))
568 actionStarted =
true;
579 private bool Blacklisted()
581 return action.Contains(
"Waiter") ||
action.Contains(
"GameObject") ||
action.Contains(
"Weld") ||
583 action.Contains(
"Move") ||
action.Contains(
"Belt") ||
action.Contains(
"ShowHide") ||
action.Contains(
"Deactivate") ||
action.Contains(
"Script") ||
action.Contains(
"Collector");
586 private bool CantRecognize()
588 return action.Contains(
"Waiter") ||
action.Contains(
"GameObject") ||
action.Contains(
"Weld") ||
614 System.Diagnostics.Stopwatch stopwatch =
new System.Diagnostics.Stopwatch();
616 gameObject.GetComponent<
Image>().color =
new Color(1f, 1f, 1f, 255f / 255f);
620 actionStarted =
false;
621 if (
id !=
GetInput() && !Blacklisted())
626 if (!Blacklisted() ||
action.Contains(
"Waiter"))
629 if (taktTime > 0 && spentTimeOnAction > taktTime)
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(
',',
'.') +
663 var
id = Guid.NewGuid().ToString();
666 go.tag =
"ACTION_INPUT";
672 return inIDs.Keys.ToList()[0];
683 return inIDs.Keys.ToList()[index];
697 DestroyImmediate(inIDs[
id]);
705 var
id = Guid.NewGuid().ToString();
723 return outIDs.Keys.ToList();
728 return inIDs.Keys.ToList();
738 var retval =
new List<Type>();
739 foreach (var classTypeReference
in acceptInputTypes) retval.Add(classTypeReference.Type);
744 internal void Update()
746 if (!CantRecognize())
748 if (actionStarted && !actionRecognized)
750 recognitionTimeOnAction += Time.deltaTime;
754 if (!actionStarted)
return;
755 spentTimeOnAction += Time.deltaTime;
757 var playerHands = Player.instance.hands;
758 List<bool> atph =
new List<bool>();
759 foreach (var hand
in playerHands)
762 if (hh && hh.attachedToHand) atph.Add(
true);
763 else if (hh && hh.realToolInHand) atph.Add(
true);
767 timeInUse += Time.deltaTime;
777 StartCoroutine(LateCommentApply());
780 private IEnumerator LateCommentApply()
782 yield
return new WaitForSeconds(1);
785 var nc = GetComponentInChildren<NodeComment>(
true);
802 actionStarted =
false;
803 if (!Blacklisted() ||
action.Contains(
"Waiter"))
813 internal bool isInFieldOfView(GameObject interactedGO)
815 var taggedCam = GameObject.FindWithTag(
"VRCamera");
816 if (taggedCam ==
null)
return false;
817 var VRCamera = taggedCam.GetComponent<Camera>();
818 if (interactedGO !=
null)
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;
845public static class RectTransformExtensions
847 public static void SetLeft(
this RectTransform rt,
float left)
849 rt.offsetMin =
new Vector2(left, rt.offsetMin.y);
852 public static void SetRight(
this RectTransform rt,
float right)
854 rt.offsetMax =
new Vector2(-right, rt.offsetMax.y);
857 public static void SetTop(
this RectTransform rt,
float top)
859 rt.offsetMax =
new Vector2(rt.offsetMax.x, -top);
862 public static void SetBottom(
this RectTransform rt,
float bottom)
864 rt.offsetMin =
new Vector2(rt.offsetMin.x, bottom);
866 public static void SetHeight(
this RectTransform rt,
float height)
868 rt.sizeDelta =
new Vector2(rt.sizeDelta.x, height);
870 public static void SetWidth(
this RectTransform rt,
float width)
872 rt.sizeDelta =
new Vector2(width, rt.sizeDelta.y);
UnityEngine.UI.Button Button
System.Drawing.Image Image
virtual void OnPointerEnter(PointerEventData eventData)
virtual void InputAdded(string id)
List< string > GetInputs()
virtual void Deactivate()
void RemoveInput(string id)
GameObject GetOutput(string id)
void TriggerOutput(string id)
string GetInput(int index)
void TriggerOut(string id)
void AddOutput(GameObject go)
List< Vector2 > GetSides()
List< string > GetOutputs()
virtual void Triggered(string id)
List< GameObject > inPuts
virtual void OutputAdded(string id)
List< GameObject > outPuts
GameObject GetInput(string id)
ActionObject(SerializationInfo info, StreamingContext context)
virtual void GetObjectData(SerializationInfo info, StreamingContext context)
List< GameObject > hideOnMinimize
List< Type > GetAcceptedInputTypes()
void AddInput(GameObject go)
virtual void OnPointerExit(PointerEventData eventData)
IEnumerator LateMinimize()
List< ClassTypeReference > acceptInputTypes
void RemoveConnectionByEndPointId(string id)
static Controller Instance
void RemoveAction(string id)
static HandHintSystem instance
static LineDrawer Instance
static PenaltyCounter Instance