2using System.Collections;
3using System.Collections.Generic;
4using JetBrains.Annotations;
5using NaughtyAttributes;
10using Valve.VR.InteractionSystem;
11using static Valve.VR.InteractionSystem.Hand;
21 private Transform backupAttachmentOffset;
24 private Vector3 startPos;
25 private Quaternion startRot;
28 internal Hand savedHand;
38 internal bool hoveringRN =
false;
39 bool isInDelayedAction =
false;
40 private bool savedIsSmall =
false;
41 private bool savedIsThin =
false;
42 private bool isSmall =
false;
43 private bool isThin =
false;
44 internal Transform originalParent;
45 internal bool actionOver =
false;
46 internal bool wrong =
false;
47 internal Action onItemReseted;
51 startPos = transform.position;
52 startRot = transform.rotation;
57 backupAttachmentOffset = attachmentOffset;
58 startPos = transform.position;
59 startRot = transform.rotation;
60 if (onPickUp ==
null) onPickUp =
new UnityEvent();
61 onPickUp.AddListener(DelayedPickup);
63 if (GetComponentInChildren<MeshRenderer>())
65 var size = GetComponentInChildren<MeshRenderer>().bounds.size;
66 volume = size.x * size.y * size.z;
70 attachmentFlags |= AttachmentFlags.SnapOnAttach;
72 originalParent = transform.parent;
76 return interactable.attachedToHand;
81 if (transform.position.y < -10)
91 private void SmallPickupHelper()
94 var playerHands = Player.instance.hands;
95 foreach (var hand
in playerHands)
99 if (!hh.objectAttachmentPoint)
continue;
101 if (hh.currentAttachedObject)
continue;
103 if (
Vector3.Distance(hh.objectAttachmentPoint.position, transform.position) < 0.05f)
106 hh.AttachObject(gameObject, GrabTypes.Grip);
107 Debug.Log($
"SmallPickupHelper: Helped picking up: {name}");
144 var rb = GetComponent<Rigidbody>();
145 var wasSleeping = rb.isKinematic;
146 rb.isKinematic =
true;
147 rb.isKinematic =
false;
148 transform.position = startPos;
149 transform.rotation = startRot;
151 var cti = FindObjectOfType<ControllerToIris>();
152 rb.isKinematic = wasSleeping;
153 transform.position -= cti.lateRepositionOffset;
156 rb.useGravity =
false;
157 rb.isKinematic =
true;
161 onItemReseted?.Invoke();
163 onItemReseted =
null;
166 private void DelayedPickup()
168 StartCoroutine(DelayedPickupEvent());
171 private IEnumerator DelayedPickupEvent()
173 isInDelayedAction =
true;
176 isInDelayedAction =
false;
179 private void OnDisable()
181 if (isInDelayedAction)
191 if (enabled && name.Contains(
"front") && (GameObject.Find(
"fake_csavarozas (2)") || GameObject.Find(
"fake_csavarozas (3)")))
198 if(enabled) base.OnAttachedToHand(hand);
231 interactable.SendMessage(
"OnHandHoverBegin",
GazePickupHelper.
instance.htRight, SendMessageOptions.DontRequireReceiver);
236 base.OnHandHoverBegin(hand);
245 interactable.SendMessage(
"OnHandHoverEnd",
GazePickupHelper.
instance.htRight, SendMessageOptions.DontRequireReceiver);
250 base.OnHandHoverEnd(hand);
258 var go = oh.gameObject;
259 if (hand.handType == SteamVR_Input_Sources.RightHand)
263 return Vector3.Distance(rootPos,
Macro.
FindDeepChild(hand.transform,
"Root").position) <= 0.05f;
265 if (hand.handType == SteamVR_Input_Sources.LeftHand)
271 return Vector3.Distance(rootPos,
Macro.
FindDeepChild(hand.transform,
"Root").position) <= 0.05f;
281 var thg = GetComponent<TwoHandGrab>();
284 var oh = GetComponent<OffsetHolder>();
285 if (!IsInPos(hand, oh) || !IsInPos(hand.otherHand, oh))
297 base.HandHoverUpdate(hand);
328 savedHand.DetachObject(gameObject);
332 StartCoroutine(DelayedEnable());
336 StartCoroutine(Lerp());
352 attachmentOffset = savedHand.name.Contains(
"Left") ?
attachmentOffsetLeft : backupAttachmentOffset;
353 savedHand.AttachObject(gameObject, GrabTypes.Grip, attachmentOffset: attachmentOffset);
364 private void ForcePickupEditor()
366 FindObjectOfType<HackedHand>().AttachObject(gameObject, GrabTypes.Grip, attachmentOffset: attachmentOffset);
372 (savedHand ? savedHand : FindObjectOfType<HackedHand>()).AttachObject(gameObject, GrabTypes.Grip, attachmentOffset: attachmentOffset);
376 foreach (var hand
in FindObjectsOfType<HackedHand>())
378 if (hand.handType == SteamVR_Input_Sources.LeftHand)
380 hand.AttachObject(gameObject, GrabTypes.Grip, attachmentOffset: attachmentOffset);
386 private IEnumerator Lerp()
389 var devOffset = Vector3.zero;
392 var cti = FindObjectOfType<ControllerToIris>();
393 devOffset -= cti.lateRepositionOffset;
397 time += Time.deltaTime;
398 transform.position = Vector3.Lerp(transform.position, startPos + devOffset, time / 0.5f);
399 transform.rotation = Quaternion.Lerp(transform.rotation, startRot, time / 0.5f);
400 yield
return new WaitForEndOfFrame();
404 private IEnumerator DelayedEnable()
406 yield
return new WaitForSeconds(0.6f);
UnityEngine.UI.Button Button
static GazePickupHelper instance
static Bounds GetBounds(GameObject go)
static float SmallestAxis(Vector3 v)
static float LargestAxis(Vector3 v)
static Transform FindDeepChild(Transform aParent, string aName)
Vector3 GetHandRootPos(OffsetHolder oh, bool left=false)
static PreviewHand Instance
void ForceDrop(bool returnToStart=false)
override void OnAttachedToHand(Hand hand)
override void HandHoverUpdate(Hand hand)
UnityEvent DelayedOnPickUp
SteamVR_Action_Boolean forceDropWithController
override void OnHandHoverBegin(Hand hand)
bool autoDisableEnableOnDrop
void ResetPosition(bool silent=false)
Transform attachmentOffsetLeft
override void OnHandHoverEnd(Hand hand)