-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTeleportGrabSwitch.cs
More file actions
84 lines (70 loc) · 2.37 KB
/
TeleportGrabSwitch.cs
File metadata and controls
84 lines (70 loc) · 2.37 KB
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
78
79
80
81
82
83
84
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR.Interaction.Toolkit;
using UnityEngine.InputSystem;
public class TeleportGrabSwitch : MonoBehaviour
{
public enum LeftOrRight
{
None,
Left,
Right
};
public LeftOrRight Controller;
public bool Teleport = true;
private XRIDefaultInputActions controls;
private XRRayInteractor Ray;
private LayerMask originalLayers;
private LayerMask grabLayer;
//private InputActionProperty switchButton;
private void Awake()
{
if (Controller == LeftOrRight.None)
throw new System.ArgumentException("Specify Left or Right Controller");
controls = new XRIDefaultInputActions();
// Default button to switch between teleport and grab is Trigger
//ActionBasedController controller = GetComponent<ActionBasedController>();
//switchButton = controller.activateAction;
//switchButton.action.performed += SwitchAction;
if (Controller == LeftOrRight.Left)
controls.XRILeftHand.TeleportModeActivate.performed += ctx => SwitchAction();
else
controls.XRIRightHand.TeleportModeActivate.performed += ctx => SwitchAction();
}
// Start is called before the first frame update
void Start()
{
Ray = GetComponent<XRRayInteractor>();
originalLayers = Ray.raycastMask.value;
grabLayer = LayerMask.NameToLayer("Grab");
Debug.Log("Grab layer: " + grabLayer.value);
if (Teleport)
Ray.lineType = XRRayInteractor.LineType.ProjectileCurve;
}
public void SwitchAction()
{
Debug.Log("Switched action");
Teleport = !Teleport;
if (Teleport)
{
Ray.raycastMask = originalLayers;
Debug.Log("Layer: " + Ray.raycastMask.value);
Ray.lineType = XRRayInteractor.LineType.ProjectileCurve;
}
else
{
Ray.raycastMask = 1 << grabLayer;
Debug.Log("Layer: " + Ray.raycastMask.value);
Ray.lineType = XRRayInteractor.LineType.StraightLine;
}
}
private void OnEnable()
{
controls.Enable();
}
private void OnDisable()
{
controls.Disable();
}
}