forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputSource.cs
More file actions
132 lines (111 loc) · 3.57 KB
/
InputSource.cs
File metadata and controls
132 lines (111 loc) · 3.57 KB
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using System;
using UnityEngine;
namespace TouchScript.InputSources
{
/// <summary>
/// Base class for all touch input sources.
/// </summary>
public abstract class InputSource : MonoBehaviour, IInputSource
{
#region Public properties
/// <summary>
/// Gets or sets current remapper.
/// </summary>
/// <value>Optional remapper to use to change screen coordinates which go into the TouchManager.</value>
public ICoordinatesRemapper CoordinatesRemapper { get; set; }
#endregion
#region Private variables
#pragma warning disable 0169
[SerializeField]
private bool advancedProps; // is used to save whether advanced properties are opened or closed
#pragma warning restore 0169
private TouchManagerInstance manager;
#endregion
#region Unity methods
/// <summary>
/// Unity OnEnable callback.
/// </summary>
protected virtual void OnEnable()
{
manager = TouchManagerInstance.Instance;
if (manager == null) throw new InvalidOperationException("TouchManager instance is required!");
}
/// <summary>
/// Unity OnDestroy callback.
/// </summary>
protected virtual void OnDisable()
{
manager = null;
}
/// <summary>
/// Unity Update callback.
/// </summary>
protected virtual void Update() {}
#endregion
#region Protected methods
/// <summary>
/// Begin touch in given screen position.
/// </summary>
/// <param name="position">Screen position.</param>
/// <returns>Internal touch id.</returns>
protected virtual ITouch beginTouch(Vector2 position)
{
return beginTouch(position, null);
}
/// <summary>
/// Begin touch in given screen position.
/// </summary>
/// <param name="position">Screen position.</param>
/// <param name="tags">Initial tags.</param>
/// <returns>Internal touch id.</returns>
protected virtual ITouch beginTouch(Vector2 position, Tags tags)
{
if (CoordinatesRemapper != null)
{
position = CoordinatesRemapper.Remap(position);
}
return manager.BeginTouch(position, tags);
}
/// <summary>
/// Mark touch as updated.
/// </summary>
/// <param name="id">Touch id.</param>
protected virtual void updateTouch(int id)
{
manager.UpdateTouch(id);
}
/// <summary>
/// Mark touch as moved.
/// </summary>
/// <param name="id">Touch id.</param>
/// <param name="position">Screen position.</param>
protected virtual void moveTouch(int id, Vector2 position)
{
if (CoordinatesRemapper != null)
{
position = CoordinatesRemapper.Remap(position);
}
manager.MoveTouch(id, position);
}
/// <summary>
/// End touch with id.
/// </summary>
/// <param name="id">Touch point id.</param>
protected virtual void endTouch(int id)
{
manager.EndTouch(id);
}
/// <summary>
/// Cancel touch with id.
/// </summary>
/// <param name="id">Touch id.</param>
protected virtual void cancelTouch(int id)
{
manager.CancelTouch(id);
}
#endregion
}
}