Tanoda
PickupHelper.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using NaughtyAttributes;
4using UnityEngine;
5#if !UNITY_WEBGL
6using Valve.VR.InteractionSystem;
7#endif
8
9public class PickupHelper : MonoBehaviour
10{
11 private Transform leftHand, rightHand;
12 private HackedHand leftHackedHand, rightHackedHand;
13 public Transform planB;
14 [ReadOnly]
15 [SerializeField]
16 private List<GameObject> objectsToPickUp = new List<GameObject>();
17 private ThrowableCanDisable[] allThrowables = null;
18
19#if !UNITY_WEBGL
20 void Start()
21 {
22 planB = GameObject.Find("iris_position_helper").transform;
23 leftHand = GameObject.Find("LeftHandModelMask").transform;
24 rightHand = GameObject.Find("RightHandModelMask").transform;
25 leftHackedHand = leftHand.gameObject.GetComponent<HackedHand>();
26 rightHackedHand = rightHand.gameObject.GetComponent<HackedHand>();
27 StartCoroutine(Updater());
28 }
29
30 private IEnumerator Updater()
31 {
32 while (true)
33 {
34 yield return new WaitForSeconds(1);
35 allThrowables = FindObjectsOfType<ThrowableCanDisable>();
36 yield return new WaitForSeconds(Random.value);
37 }
38 }
39
40 void Update()
41 {
42 objectsToPickUp.Clear();
43 //allThrowables = FindObjectsOfType<ThrowableCanDisable>();
44 //allThrowables = planB.GetComponentsInChildren<ThrowableCanDisable>();
45 var helper = GetComponent<Collider>().bounds;
46 if (allThrowables == null) return;
47
48 foreach (var throwable in allThrowables)
49 {
50 if (!throwable)
51 continue;
52
53 if (!throwable.enabled)
54 continue;
56 if (throwable.name.Contains("front") && (GameObject.Find("fake_csavarozas (2)") || GameObject.Find("fake_csavarozas (3)")))
57 {
58 continue;
59 }
61 if ((throwable.GetHand() == null || (throwable.GetHand() != null && throwable.GetHand().currentAttachedObject != throwable.gameObject)))
62 {
63 if (helper.Contains(throwable.transform.position))
64 {
65 objectsToPickUp.Add(throwable.gameObject);
66 }
67 }
68 }
69
70 if (leftHackedHand.currentAttachedObject == null && helper.Contains(leftHackedHand.objectAttachmentPoint.position))
71 {
72 if (objectsToPickUp.Count > 0)
73 {
74 leftHackedHand.AttachObject(objectsToPickUp[0], GrabTypes.Grip);
75 objectsToPickUp.RemoveAt(0);
76 }
77 }
78
79 if (rightHackedHand.currentAttachedObject == null && helper.Contains(rightHackedHand.objectAttachmentPoint.position))
80 {
81 if (objectsToPickUp.Count > 0)
82 {
83 rightHackedHand.AttachObject(objectsToPickUp[0], GrabTypes.Grip);
84 objectsToPickUp.RemoveAt(0);
85 }
86 }
87 }
88#endif
89}
UnityEngine.Random Random
override void AttachObject(GameObject objectToAttach, GrabTypes grabbedWithType, AttachmentFlags flags=defaultAttachmentFlags, Transform attachmentOffset=null)
Definition: HackedHand.cs:474
Transform planB
Definition: PickupHelper.cs:13