-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSharedSpaceInputManager.cs
47 lines (43 loc) · 1.64 KB
/
SharedSpaceInputManager.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
using UnityEngine;
using UnityEngine.InputSystem.EnhancedTouch;
using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
using Unity.PolySpatial.InputDevices;
public class SharedSpaceInputManager : MonoBehaviour
{
private GameObject m_SelectedObject;
private void Start()
{
EnhancedTouchSupport.Enable();
}
private void Update()
{
var activeTouches = Touch.activeTouches;
if (activeTouches.Count > 0)
{
var primaryTouchData = EnhancedSpatialPointerSupport.GetPointerState(activeTouches[0]);
var touchPhase = activeTouches[0].phase;
if (touchPhase == UnityEngine.InputSystem.TouchPhase.Began &&
(primaryTouchData.Kind == UnityEngine.InputSystem.LowLevel.SpatialPointerKind.IndirectPinch || primaryTouchData.Kind == UnityEngine.InputSystem.LowLevel.SpatialPointerKind.DirectPinch))
{
if (primaryTouchData.targetObject != null)
{
m_SelectedObject = primaryTouchData.targetObject;
}
}
else if (touchPhase == UnityEngine.InputSystem.TouchPhase.Moved)
{
if (m_SelectedObject != null)
{
m_SelectedObject.transform.position = primaryTouchData.interactionPosition;
}
}
else if (touchPhase == UnityEngine.InputSystem.TouchPhase.Ended || touchPhase == UnityEngine.InputSystem.TouchPhase.Canceled)
{
if (m_SelectedObject != null)
{
m_SelectedObject = null;
}
}
}
}
}