-
Notifications
You must be signed in to change notification settings - Fork 0
/
FootMoovAdapter.cs
108 lines (77 loc) · 2.4 KB
/
FootMoovAdapter.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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using UnityEngine;
using System.Collections;
namespace FootMoovTeam {
public delegate void OnBackTapEvent(object sender);
public delegate void OnFrontTapEvent(object sender);
public abstract class PressureButton {
// Thresholds
private const float TAP_ACTIVATION_THRESHOLD = 50f;
private const float TAP_DELTA_THRESHOLD = 100f;
private float lastPression = 0f;
protected Connector connector;
public PressureButton(Connector connector) {
this.connector = connector;
}
abstract protected float getCurrentPression();
public bool isTap() {
float currentPression = getCurrentPression ();
if ((currentPression - lastPression) > TAP_DELTA_THRESHOLD) {
return true;
}
lastPression = currentPression;
return false;
}
public bool isOverThreshold() {
return getCurrentPression() > TAP_ACTIVATION_THRESHOLD;
}
}
public class FrontPressureButton : PressureButton {
public FrontPressureButton(Connector connector) : base(connector) {
}
protected override float getCurrentPression() {
return connector.pression2;
}
}
public class BackPressureButton : PressureButton {
public BackPressureButton(Connector connector) : base(connector) {}
protected override float getCurrentPression() {
return connector.pression1;
}
}
public class FootMoovAdapter : MonoBehaviour {
private PressureButton backButton;
private PressureButton frontButton;
private bool isBackTap = false;
private bool isFrontTap = false;
public Connector connector;
public DemoFootMoovListener listener;
private event OnFrontTapEvent OnFrontTap;
private event OnBackTapEvent OnBackTap;
void Awake() {
backButton = new BackPressureButton (connector);
frontButton = new FrontPressureButton (connector);
OnBackTap += new OnBackTapEvent (listener.OnBackTap);
OnFrontTap += new OnFrontTapEvent (listener.OnFrontTap);
}
void Update () {
UpdateBackTap ();
UpdateFrontTap ();
}
private void UpdateBackTap() {
if (backButton.isTap () && backButton.isOverThreshold() && !isBackTap) {
isBackTap = true;
OnBackTap (this);
} else if(!backButton.isOverThreshold()) {
isBackTap = false;
}
}
private void UpdateFrontTap() {
if (frontButton.isTap () && frontButton.isOverThreshold() && !isFrontTap) {
isFrontTap = true;
OnFrontTap (this);
} else if(!frontButton.isOverThreshold()) {
isFrontTap = false;
}
}
}
}