Tanoda
GroundItemResetter.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4#if !UNITY_WEBGL
5using Valve.VR.InteractionSystem;
6#endif
7
8public class GroundItemResetter : MonoBehaviour
9{
10 private List<ThrowableCanDisable> tcds = new List<ThrowableCanDisable>();
11
12 private void Start()
13 {
14 StartCoroutine(SlowUpdate());
15 }
16
17 private void OnDisable()
18 {
19 StopAllCoroutines();
20 }
21 IEnumerator SlowUpdate()
22 {
23 while (true)
24 {
25 yield return new WaitForSeconds(0.5f);
26#if !UNITY_WEBGL
27 if (SavedUser.instance.isEditor)
28 continue;
29 foreach (var item in tcds)
30 {
31 var interactable = item.interactable;
32
33 if (interactable.attachedToHand != null)
34 continue;
35 if (item)
36 item.ResetPosition();
37 }
38 tcds.Clear();
39#endif
40 }
41 }
42
43 private void OnTriggerEnter(Collider other)
44 {
45 //Debug.Log("GIR: " + other.gameObject.name);
46#if !UNITY_WEBGL
47 if (SavedUser.instance.isEditor)
48 return;
49
50 var interactable = other.GetComponentInParent<Interactable>();
51 var tcd = other.GetComponentInParent<ThrowableCanDisable>();
52 if (interactable && tcd)
53 {
54 if (interactable.attachedToHand != null)
55 return;
56
57 if (!tcds.Contains(tcd)) tcds.Add(tcd);
58 }
59#endif
60 }
61
62 private void OnTriggerExit(Collider other)
63 {
64#if !UNITY_WEBGL
65 if (SavedUser.instance.isEditor)
66 return;
67
68 var interactable = other.GetComponentInParent<Interactable>();
69 var tcd = other.GetComponentInParent<ThrowableCanDisable>();
70 if (interactable && tcd)
71 {
72 if (interactable.attachedToHand != null)
73 return;
74
75 if (!tcds.Contains(tcd)) tcds.Add(tcd);
76 }
77#endif
78 }
79
80 private void OnTriggerStay(Collider other)
81 {
82#if !UNITY_WEBGL
83 if (SavedUser.instance.isEditor)
84 return;
85
86 var interactable = other.GetComponentInParent<Interactable>();
87 var tcd = other.GetComponentInParent<ThrowableCanDisable>();
88 if (interactable && tcd)
89 {
90 if (interactable.attachedToHand != null)
91 return;
92
93 if (!tcds.Contains(tcd)) tcds.Add(tcd);
94 }
95#endif
96 }
97}