-
Notifications
You must be signed in to change notification settings - Fork 1
/
ParsedTouchData.cs
46 lines (38 loc) · 1.11 KB
/
ParsedTouchData.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
using UnityEngine;
using System.Collections;
/**
* Dealing with raw touch input from a Cardboard device
*/
public class ParsedTouchData {
private bool wasTouched = false;
public ParsedTouchData() {
Cardboard cardboard = CardboardGameObject().GetComponent<Cardboard>();
cardboard.TapIsTrigger = false;
}
private GameObject CardboardGameObject() {
GameObject gameObject = Camera.main.gameObject;
return gameObject.transform.parent.parent.gameObject;
}
public void Update() {
wasTouched |= IsDown();
}
public bool IsDown() {
// touchCount can jump for no reason in a Cardboard
// but it's too quick to be considered "Moved"
return Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved;
}
public bool StillDown() {
return Input.touchCount > 0;
}
public bool IsUp() {
if (!StillDown() && wasTouched) {
wasTouched = false;
return true;
}
return false;
}
public void PrintDebug() {
Debug.Log("--- Touch\ncount: " + Input.touchCount +
"\ntouched: " + wasTouched);
}
}