forked from ErigoLee/HandTrackingGrab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stent.cs
77 lines (70 loc) · 3.26 KB
/
Stent.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Stent : MonoBehaviour
{
private GameObject detector;
private GrabLeft leftHand;
private GrabRight rightHand;
private GestureRecongizedLeft gestureRecongizedLeft;
private GestureRecongizedRight gestureRecongizedRight;
private bool updateActive;
void Start()
{
detector = transform.GetChild(0).gameObject;
leftHand = GameObject.FindGameObjectWithTag("LeftHand").GetComponent<GrabLeft>();
rightHand = GameObject.FindGameObjectWithTag("RightHand").GetComponent<GrabRight>();
gestureRecongizedLeft = GameObject.FindGameObjectWithTag("GR").GetComponent<GestureRecongizedLeft>();
gestureRecongizedRight = GameObject.FindGameObjectWithTag("GR").GetComponent<GestureRecongizedRight>();
updateActive = true;
}
public void SetDestroy(string handName)
{
updateActive = false;
if (handName.Equals("LeftHand"))
{
gestureRecongizedLeft.CanGrabbingTurnOff(); //grab 동작 인식X
leftHand.InsideObjectTurnOff(); //grab을 끔
OVRGrabbable grabbable = GetComponent<OVRGrabbable>() ?? GetComponentInParent<OVRGrabbable>();
detector.SetActive(false); //grabDetector를 끔
leftHand.RemoveCandidates(grabbable);
gestureRecongizedLeft.CanGrabbingTurnOn(); //grab 동작 인식이 되도록 함. -> grabDetector가 끈 상태라면, grab이 되지 않는다.
}
if (handName.Equals("RightHand"))
{
gestureRecongizedRight.CanGrabbingTurnOff(); //grab 동작 인식X
rightHand.InsideObjectTurnOff(); //grab을 끔
OVRGrabbable grabbable = GetComponent<OVRGrabbable>() ?? GetComponentInParent<OVRGrabbable>();
detector.SetActive(false); //grabDetector를 끔
rightHand.RemoveCandidates(grabbable);
gestureRecongizedRight.CanGrabbingTurnOn(); //grab 동작 인식이 되도록 함. -> grabDetector가 끈 상태라면, grab이 되지 않는다.
}
leftHand.insideObject = false;
rightHand.insideObject = false;
Destroy(gameObject);
}
void Update()
{
if (!updateActive)
return;
if (detector.activeSelf == true)
{
OVRGrabbable grabbable = GetComponent<OVRGrabbable>() ?? GetComponentInParent<OVRGrabbable>();
GrabDetector grabDetector = detector.GetComponent<GrabDetector>();
if (leftHand.insideObject && grabDetector.GetInLeft())
{
if (gestureRecongizedLeft.GetCanGrabbing() && (gestureRecongizedLeft.GetGestureLeftName().Equals("Left_rock_v1") || gestureRecongizedLeft.GetGestureLeftName().Equals("Left_rock_v2")))
{
leftHand.AddCandidates(grabbable);
}
}
if (rightHand.insideObject && grabDetector.GetInRight())
{
if (gestureRecongizedRight.GetCanGrabbing() && (gestureRecongizedRight.GetGestureRightName().Equals("Right_rock_v1") || gestureRecongizedRight.GetGestureRightName().Equals("Right_rock_v2")))
{
rightHand.AddCandidates(grabbable);
}
}
}
}
}