BlueGit

blue-star ggj-2020

Files

ggj-2020 / Assets / Oculus / LipSync / Scripts / Helpers / OVRTouchpad.cs

OVRTouchpad.cs

Project Import
timfa Tim Falken · pushed by timfa · 6 years ago
b77834a1 History
OVRTouchpad.cs 6.1 KiB Download Raw
1/************************************************************************************
2Filename : OVRTouchpad.cs
3Content : Interface to touchpad
4Created : November 13, 2013
5Copyright : Copyright Facebook Technologies, LLC and its affiliates.
6 All rights reserved.
7
8Licensed under the Oculus Audio SDK License Version 3.3 (the "License");
9you may not use the Oculus Audio SDK except in compliance with the License,
10which is provided at the time of installation or download, or which
11otherwise accompanies this software in either electronic or hard copy form.
12
13You may obtain a copy of the License at
14
15https://developer.oculus.com/licenses/audio-3.3/
16
17Unless required by applicable law or agreed to in writing, the Oculus Audio SDK
18distributed under the License is distributed on an "AS IS" BASIS,
19WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20See the License for the specific language governing permissions and
21limitations under the License.
22************************************************************************************/
23using UnityEngine;
24using System;
25
26//-------------------------------------------------------------------------------------
27// ***** OVRTouchpad
28//
29// OVRTouchpad is an interface class to a touchpad.
30//
31public static class OVRTouchpad
32{
33 //-------------------------
34 // Input enums
35 public enum TouchEvent { SingleTap, DoubleTap, Left, Right, Up, Down };
36
37 // mouse
38 static Vector3 moveAmountMouse;
39 static float minMovMagnitudeMouse = 25.0f;
40
41 public delegate void OVRTouchpadCallback<TouchEvent>(TouchEvent arg);
42 static public Delegate touchPadCallbacks = null;
43
44 //Disable the unused variable warning
45#pragma warning disable 0414
46
47 //Ensures that the TouchpadHelper will be created automatically upon start of the game.
48 static private OVRTouchpadHelper touchpadHelper =
49 ( new GameObject("OVRTouchpadHelper") ).AddComponent< OVRTouchpadHelper >();
50
51#pragma warning restore 0414
52
53 // We will call this to create the TouchpadHelper class. This will
54 // add the Touchpad game object into the world and we can call into
55 // TouchEvent static functions to hook delegates into for touch capture
56 static public void Create()
57 {
58 // Does nothing but call constructor to add game object into scene
59 }
60
61 // Update
62 static public void Update()
63 {
64 // MOUSE INPUT
65
66 if(Input.GetMouseButtonDown(0))
67 {
68 moveAmountMouse = Input.mousePosition;
69 }
70 else if(Input.GetMouseButtonUp(0))
71 {
72 moveAmountMouse -= Input.mousePosition;
73 HandleInputMouse(ref moveAmountMouse);
74 }
75 }
76
77 // OnDisable
78 static public void OnDisable()
79 {
80 }
81
82 // HandleInputMouse
83 static void HandleInputMouse(ref Vector3 move)
84 {
85 if (touchPadCallbacks == null)
86 {
87 return;
88 }
89 OVRTouchpadCallback<TouchEvent> callback = touchPadCallbacks as OVRTouchpadCallback<TouchEvent>;
90
91 if ( move.magnitude < minMovMagnitudeMouse)
92 {
93 callback(TouchEvent.SingleTap);
94 }
95 else
96 {
97 move.Normalize();
98
99 // Left/Right
100 if (Mathf.Abs(move.x) > Mathf.Abs(move.y))
101 {
102 if (move.x > 0.0f)
103 callback(TouchEvent.Left);
104 else
105 callback(TouchEvent.Right);
106 }
107 // Up/Down
108 else
109 {
110 if (move.y > 0.0f)
111 callback(TouchEvent.Down);
112 else
113 callback(TouchEvent.Up);
114 }
115 }
116 }
117
118 static public void AddListener(OVRTouchpadCallback<TouchEvent> handler)
119 {
120 touchPadCallbacks = (OVRTouchpadCallback<TouchEvent>)touchPadCallbacks + handler;
121 }
122}
123
124//-------------------------------------------------------------------------------------
125// ***** OVRTouchpadHelper
126//
127// This singleton class gets created and stays resident in the application. It is used to
128// trap the touchpad values, which get broadcast to any listener on the "Touchpad" channel.
129//
130// This class also demontrates how to make calls from any class that needs these events by
131// setting up a listener to "Touchpad" channel.
132public sealed class OVRTouchpadHelper : MonoBehaviour
133{
134 void Awake ()
135 {
136 DontDestroyOnLoad(gameObject);
137 }
138
139 void Start ()
140 {
141 // Add a listener to the OVRTouchpad for testing
142 OVRTouchpad.AddListener(LocalTouchEventCallback);
143 }
144
145
146 void Update ()
147 {
148 OVRTouchpad.Update();
149 }
150
151
152 public void OnDisable()
153 {
154 OVRTouchpad.OnDisable();
155 }
156
157 // LocalTouchEventCallback
158 void LocalTouchEventCallback(OVRTouchpad.TouchEvent touchEvent)
159 {
160 switch(touchEvent)
161 {
162 case(OVRTouchpad.TouchEvent.SingleTap):
163// OVRLipSyncDebugConsole.Clear();
164// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
165// OVRLipSyncDebugConsole.Log("TP-SINGLE TAP");
166 break;
167
168 case(OVRTouchpad.TouchEvent.DoubleTap):
169// OVRLipSyncDebugConsole.Clear();
170// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
171// OVRLipSyncDebugConsole.Log("TP-DOUBLE TAP");
172 break;
173
174 case(OVRTouchpad.TouchEvent.Left):
175// OVRLipSyncDebugConsole.Clear();
176// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
177// OVRLipSyncDebugConsole.Log("TP-SWIPE LEFT");
178 break;
179
180 case(OVRTouchpad.TouchEvent.Right):
181// OVRLipSyncDebugConsole.Clear();
182// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
183// OVRLipSyncDebugConsole.Log("TP-SWIPE RIGHT");
184 break;
185
186 case(OVRTouchpad.TouchEvent.Up):
187// OVRLipSyncDebugConsole.Clear();
188// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
189// OVRLipSyncDebugConsole.Log("TP-SWIPE UP");
190 break;
191
192 case(OVRTouchpad.TouchEvent.Down):
193// OVRLipSyncDebugConsole.Clear();
194// OVRLipSyncDebugConsole.ClearTimeout(1.5f);
195// OVRLipSyncDebugConsole.Log("TP-SWIPE DOWN");
196 break;
197 }
198 }
199
200}
201