Spelunx Cavern SDK
 
Loading...
Searching...
No Matches
SampleDebugKeys.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine;
4using UnityEngine.Events;
5using UnityEngine.InputSystem;
6using Spelunx;
7using Spelunx.Vive;
8
9[DisallowMultipleComponent]
10public class SampleDebugKeys : MonoBehaviour, IDebugKeys
11{
12 [Header("Input Actions")]
13 [SerializeField, Tooltip("Toggle head tracking")]
14 private InputAction headTracking = new("Toggle Head Tracking", InputActionType.Value, "<Keyboard>/o");
15
16 private Vector3 cameraStartPos;
17 private bool doHeadTracking = false;
18
19 public List<(string Key, string Description)> KeyDescriptions()
20 {
21 return new(){
22 (headTracking.GetBindingDisplayString(), "Toggle head tracking")
23 };
24 }
25
26 // enable the input actions on play mode start
27 void OnEnable()
28 {
29 headTracking.Enable();
30 }
31
32
33 // disable the input actions on play mode stop
34 void OnDisable()
35 {
36 headTracking.Disable();
37 }
38
39 // bind the proper callbacks to each action.performed
40 // using the saved key managers
41 // This must happen in play mode, not in edit mode, or it won't work.
42 void Awake()
43 {
44 headTracking.performed += ToggleHeadTrackAction;
45 }
46
47 void Start()
48 {
49 cameraStartPos = GetComponentInChildren<FollowMotion>().transform.position;
50 GetComponentInChildren<FollowMotion>().enabled = false;
51 }
52
53 public void ToggleHeadTrackAction(InputAction.CallbackContext ctx)
54 {
55 doHeadTracking = !doHeadTracking;
56 if (doHeadTracking)
57 {
58 GetComponentInChildren<FollowMotion>().enabled = true;
59 }
60 else
61 {
62 GetComponentInChildren<FollowMotion>().enabled = false;
63 GetComponentInChildren<FollowMotion>().transform.position = cameraStartPos;
64
65 }
66 }
67 public void DoExtraGUI()
68 {
69 }
70}
void ToggleHeadTrackAction(InputAction.CallbackContext ctx)
List<(string Key, string Description)> KeyDescriptions()