1using System.Collections;
2using System.Collections.Generic;
7using Valve.VR.InteractionSystem;
8using static Valve.VR.InteractionSystem.Hand;
14 internal bool isCollision =
false;
15 internal List<bool> collisionList =
new List<bool>();
16 internal GameObject falseHighlightObject;
21 bool isRunning =
false;
22 internal bool isPOI =
false;
24 private Vector3 lastHandPos = Vector3.zero;
25 System.Diagnostics.Stopwatch stopwatch =
new System.Diagnostics.Stopwatch();
28 bool crRuning =
false;
29 internal Coroutine clear;
31 private void OnTriggerStay(Collider other)
33 if (SceneManager.GetActiveScene().buildIndex == 0)
return;
34 if (!other.name.Contains(
"Bone") && !other.name.Contains(
"Glove") && !isCollision)
36 var hancCopyAvg = GetComponentInChildren<HandCopyAvg>(
true);
37 var hackedHand = hancCopyAvg.GetComponentInParent<
HackedHand>();
42 if (other.gameObject.GetComponentInParent<Canvas>() &&
hand.activeInHierarchy)
46 if ((TurnThePage(other.gameObject).x *100) > 10 && !crRuning)
48 if (
finish.activeInHierarchy ||
result.activeInHierarchy)
50 if (
finish.activeInHierarchy)
52 StartCoroutine(ChangeTheAlpha(
finish, 1, 0));
55 StartCoroutine(ChangeTheAlpha(
result, 0, 1));
59 StartCoroutine(ChangeTheAlpha(
result, 1, 0));
62 StartCoroutine(ChangeTheAlpha(
finish, 0, 1));
85 var colliders = hancCopyAvg.GetComponents<Collider>();
86 foreach (var collider
in colliders)
88 collider.enabled =
false;
91 Debug.Log($
"7 th foreach: {stopwatch.ElapsedMilliseconds}ms");
94 if (other.GetComponentInParent<InteractableHoverEvents>())
99 if (other.gameObject.name.Contains(
"einhell"))
101 hancCopyAvg.GetComponentInChildren<SkinnedMeshRenderer>(
true).enabled =
false;
102 hackedHand.realToolInHand =
true;
105 if (!isRunning && !isCollision &&
ConveyorBeltManager.
instance.started && GetComponentInChildren<HandCopySkelet>() && tcd && !tcd.enabled && tcd.isActiveAndEnabled ==
false && other.gameObject.activeSelf && !GetComponentInParent<HackedHand>().attachedToHand)
108 if (!GetComponentInChildren<TwoHandGrab>())
115 StartCoroutine(ShowToolHighLight(tcd.gameObject));
125 collisionList.Add(
true);
129 if (other.name.Contains(
"Bone") && other.name.Contains(
"Glove"))
133 if (other.name.Contains(
"handprint"))
145 private void Update()
147 time += Time.deltaTime;
148 penalty += Time.deltaTime;
151 private Vector3 TurnThePage(GameObject other)
153 if (lastHandPos ==
Vector3.zero)
155 lastHandPos = gameObject.transform.position;
158 var localHandPos = other.transform.InverseTransformPoint(gameObject.transform.position);
159 var localLastHandPos = other.transform.InverseTransformPoint(lastHandPos);
161 var handDelta = lastHandPos - gameObject.transform.position;
162 var localDelta = other.transform.InverseTransformDirection(handDelta);
164 Debug.Log(localDelta*100);
167 private IEnumerator setCrRunning()
169 yield
return new WaitForSeconds(1);
172 private IEnumerator ChangeTheAlpha(GameObject go,
float start,
float finish)
175 float duration = 0.5f;
177 var cggo = go.GetComponent<CanvasGroup>();
178 while (time <= duration)
180 time += Time.deltaTime;
181 cggo.alpha = Mathf.Lerp(0, 1, time / duration);
189 private IEnumerator Scroll(GameObject go,
float value2)
192 float duration = 0.5f;
194 var sb = go.GetComponentInChildren<ScrollRect>();
195 var scrollValue = sb.verticalScrollbar.value;
196 while (time <= duration)
198 time += Time.deltaTime;
199 sb.verticalScrollbar.value = Mathf.Lerp(sb.verticalScrollbar.value, scrollValue + value2, time / duration);
207 private void OnTriggerExit(Collider other)
209 var hackedHand = GetComponentInParent<HackedHand>();
211 if (!isCollision) clear = StartCoroutine(clearVector());
212 if (crRuning) StartCoroutine(setCrRunning());
216 if (falseHighlightObject) Destroy(falseHighlightObject);
228 var colliders = GetComponentInChildren<HandCopyAvg>(
true).GetComponentsInChildren<Collider>();
229 foreach (var collider
in colliders)
231 collider.enabled =
true;
236 GetComponentInChildren<HandCopyAvg>().GetComponentInChildren<SkinnedMeshRenderer>(
true).enabled =
true;
237 if (other.gameObject.name.Contains(
"einhell")) hackedHand.realToolInHand =
false;
238 collisionList.Remove(
true);
239 if (other.name.Contains(
"handprint"))
241 colliders = GetComponentInChildren<HandCopyAvg>(
true).GetComponents<Collider>();
242 foreach (var collider
in colliders)
251 private IEnumerator clearVector()
253 yield
return new WaitForSeconds(0.5f);
256 private void OnDisable()
258 if (falseHighlightObject) Destroy(falseHighlightObject);
269 private IEnumerator ShowToolHighLight(GameObject other)
272 if (falseHighlightObject) Destroy(falseHighlightObject);
276 yield
return new WaitForEndOfFrame();
280 falseHighlightObject = Instantiate(other, other.transform.position, other.transform.rotation,
null);
282 Destroy(falseHighlightObject.GetComponent<
TorqueWrench>());
283 Destroy(falseHighlightObject.GetComponent<
SeegerHelper>());
286 Destroy(falseHighlightObject.GetComponent<Interactable>());
289 var allCollider = falseHighlightObject.GetComponentsInChildren<Collider>();
290 var allRb = falseHighlightObject.GetComponentsInChildren<Rigidbody>();
292 foreach (var c
in allCollider)
295 foreach (var c
in allRb)
298 Destroy(falseHighlightObject.GetComponent<
HashHolder>());
300 yield
return new WaitForEndOfFrame();
305 falseHighlightObject.transform.localScale *= 1.001f;
307 falseHighlightObject.SetActive(
true);
309 MatChange(falseHighlightObject,
true);
312 private void MatChange(GameObject go,
bool tool =
false)
314 var mrs = go.GetComponentsInChildren<MeshRenderer>();
315 foreach (var meshRenderer
in mrs)
317 var list =
new List<Material>();
318 for (var i = 0; i < meshRenderer.materials.Length; i++)
321 meshRenderer.materials = list.ToArray();
Material highlightMaterial
static PenaltyCounter Instance