|
21 | 21 |
|
22 | 22 | namespace IBM.Watson.DeveloperCloud.Camera
|
23 | 23 | {
|
24 |
| - /// <summary> |
25 |
| - /// Hot corners to handle Three Tap on corners and middle points of the current device screen. |
26 |
| - /// </summary> |
27 |
| - public class HotCorner : MonoBehaviour |
| 24 | + /// <summary> |
| 25 | + /// Hot corners to handle Three Tap on corners and middle points of the current device screen. |
| 26 | + /// </summary> |
| 27 | + public class HotCorner : MonoBehaviour |
| 28 | + { |
| 29 | + #region Private Members |
| 30 | + [SerializeField] |
| 31 | + private float m_NormalizedThresholdWidth = 0.1f; |
| 32 | + [SerializeField] |
| 33 | + private float m_NormalizedThresholdHeight = 0.1f; |
| 34 | + #endregion |
| 35 | + |
| 36 | + #region TapThreeTimes Event Handles |
| 37 | + |
| 38 | + void OnEnable() |
| 39 | + { |
| 40 | + EventManager.Instance.RegisterEventReceiver("OnTripleTap", TapThreeTimes); |
| 41 | + } |
| 42 | + |
| 43 | + void OnDisable() |
28 | 44 | {
|
29 |
| - #region Private Members |
30 |
| - [SerializeField] |
31 |
| - private float m_NormalizedThresholdWidth = 0.1f; |
32 |
| - [SerializeField] |
33 |
| - private float m_NormalizedThresholdHeight = 0.1f; |
34 |
| - #endregion |
| 45 | + EventManager.Instance.UnregisterEventReceiver("OnTripleTap", TapThreeTimes); |
| 46 | + } |
35 | 47 |
|
36 |
| - #region TapThreeTimes Event Handles |
| 48 | + void TapThreeTimes(System.Object[] args = null) |
| 49 | + { |
| 50 | + if (args != null && args.Length > 0 && args[0] is TouchScript.Gestures.TapGesture) |
| 51 | + { |
| 52 | + //Got three tap gesture, now checking the corners |
| 53 | + TouchScript.Gestures.TapGesture tapGesture = args[0] as TouchScript.Gestures.TapGesture; |
37 | 54 |
|
38 |
| - void OnEnable() |
| 55 | + if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
39 | 56 | {
|
40 |
| - EventManager.Instance.RegisterEventReceiver("OnTripleTap", TapThreeTimes); |
| 57 | + EventManager.Instance.SendEvent("OnTripleTapBottomLeft"); |
41 | 58 | }
|
42 |
| - |
43 |
| - void OnDisable() |
| 59 | + else if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
44 | 60 | {
|
45 |
| - EventManager.Instance.UnregisterEventReceiver("OnTripleTap", TapThreeTimes); |
| 61 | + EventManager.Instance.SendEvent("OnTripleTapTopLeft"); |
46 | 62 | }
|
47 |
| - |
48 |
| - void TapThreeTimes(System.Object[] args = null) |
| 63 | + else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
49 | 64 | {
|
50 |
| - if (args != null && args.Length > 0 && args[0] is TouchScript.Gestures.TapGesture) |
51 |
| - { |
52 |
| - //Got three tap gesture, now checking the corners |
53 |
| - TouchScript.Gestures.TapGesture tapGesture = args[0] as TouchScript.Gestures.TapGesture; |
54 |
| - |
55 |
| - if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
56 |
| - { |
57 |
| - EventManager.Instance.SendEvent("OnTripleTapBottomLeft"); |
58 |
| - } |
59 |
| - else if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
60 |
| - { |
61 |
| - EventManager.Instance.SendEvent("OnTripleTapTopLeft"); |
62 |
| - } |
63 |
| - else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
64 |
| - { |
65 |
| - EventManager.Instance.SendEvent("OnTripleTapBottomRight"); |
66 |
| - } |
67 |
| - else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
68 |
| - { |
69 |
| - EventManager.Instance.SendEvent("OnTripleTapTopRight"); |
70 |
| - } |
71 |
| - else if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 0.5f - (m_NormalizedThresholdHeight / 2.0f) && tapGesture.NormalizedScreenPosition.y < 0.5f + (m_NormalizedThresholdHeight / 2.0f)) |
72 |
| - { |
73 |
| - EventManager.Instance.SendEvent("OnTripleTapMiddleLeft"); |
74 |
| - } |
75 |
| - else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 0.5f - (m_NormalizedThresholdHeight / 2.0f) && tapGesture.NormalizedScreenPosition.y < 0.5f + (m_NormalizedThresholdHeight / 2.0f)) |
76 |
| - { |
77 |
| - EventManager.Instance.SendEvent("OnTripleTapMiddleRight"); |
78 |
| - } |
79 |
| - else if (tapGesture.NormalizedScreenPosition.x > 0.5f - (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.x < 0.5f + (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
80 |
| - { |
81 |
| - EventManager.Instance.SendEvent("OnTripleTapMiddleBottom"); |
82 |
| - } |
83 |
| - else if (tapGesture.NormalizedScreenPosition.x > 0.5f - (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.x < 0.5f + (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
84 |
| - { |
85 |
| - EventManager.Instance.SendEvent("OnTripleTapMiddleTop"); |
86 |
| - } |
87 |
| - else |
88 |
| - { |
89 |
| - // do nothing |
90 |
| - } |
91 |
| - |
92 |
| - } |
93 |
| - else |
94 |
| - { |
95 |
| - Log.Warning("WatsonCamera", "TapThreeTimes has invalid arguments."); |
96 |
| - } |
| 65 | + EventManager.Instance.SendEvent("OnTripleTapBottomRight"); |
| 66 | + } |
| 67 | + else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
| 68 | + { |
| 69 | + EventManager.Instance.SendEvent("OnTripleTapTopRight"); |
| 70 | + } |
| 71 | + else if (tapGesture.NormalizedScreenPosition.x < m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 0.5f - (m_NormalizedThresholdHeight / 2.0f) && tapGesture.NormalizedScreenPosition.y < 0.5f + (m_NormalizedThresholdHeight / 2.0f)) |
| 72 | + { |
| 73 | + EventManager.Instance.SendEvent("OnTripleTapMiddleLeft"); |
| 74 | + } |
| 75 | + else if (tapGesture.NormalizedScreenPosition.x > 1.0f - m_NormalizedThresholdWidth && tapGesture.NormalizedScreenPosition.y > 0.5f - (m_NormalizedThresholdHeight / 2.0f) && tapGesture.NormalizedScreenPosition.y < 0.5f + (m_NormalizedThresholdHeight / 2.0f)) |
| 76 | + { |
| 77 | + EventManager.Instance.SendEvent("OnTripleTapMiddleRight"); |
| 78 | + } |
| 79 | + else if (tapGesture.NormalizedScreenPosition.x > 0.5f - (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.x < 0.5f + (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.y < m_NormalizedThresholdHeight) |
| 80 | + { |
| 81 | + EventManager.Instance.SendEvent("OnTripleTapMiddleBottom"); |
| 82 | + } |
| 83 | + else if (tapGesture.NormalizedScreenPosition.x > 0.5f - (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.x < 0.5f + (m_NormalizedThresholdWidth / 2.0f) && tapGesture.NormalizedScreenPosition.y > 1.0f - m_NormalizedThresholdHeight) |
| 84 | + { |
| 85 | + EventManager.Instance.SendEvent("OnTripleTapMiddleTop"); |
| 86 | + } |
| 87 | + else |
| 88 | + { |
| 89 | + // do nothing |
97 | 90 | }
|
98 | 91 |
|
99 |
| - #endregion |
| 92 | + } |
| 93 | + else |
| 94 | + { |
| 95 | + Log.Warning("WatsonCamera", "TapThreeTimes has invalid arguments."); |
| 96 | + } |
100 | 97 | }
|
101 | 98 |
|
| 99 | + #endregion |
| 100 | + } |
| 101 | + |
102 | 102 | }
|
0 commit comments