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
140 lines (119 loc) · 4.12 KB
/
Copy pathInputSource.cs
File metadata and controls
140 lines (119 loc) · 4.12 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
133
134
135
136
137
138
139
140
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using System;
using System.Collections.Generic;
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 if advanced properties are opened or closed
#pragma warning restore 0169
/// <summary>
/// Reference to global touch manager.
/// </summary>
protected ITouchManager manager;
#endregion
#region Unity methods
/// <summary>
/// Unity OnEnable callback.
/// </summary>
protected virtual void OnEnable()
{
manager = TouchManager.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 Callbacks
/// <summary>
/// Begin touch in given screen position.
/// </summary>
/// <param name="position">Screen position.</param>
/// <returns>Internal touch id.</returns>
protected virtual int beginTouch(Vector2 position)
{
return beginTouch(position, null, 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 int beginTouch(Vector2 position, Tags tags)
{
return beginTouch(position, tags, null);
}
/// <summary>
/// Begin touch in given screen position.
/// </summary>
/// <param name="position">Screen position.</param>
/// <param name="tags">Initial tags.</param>
/// <param name="properties">Initial properties.</param>
/// <returns>Internal touch id.</returns>
protected virtual int beginTouch(Vector2 position, Tags tags, IDictionary<string, System.Object> properties)
{
if (CoordinatesRemapper != null)
{
position = CoordinatesRemapper.Remap(position);
}
return manager.BeginTouch(position, tags, properties);
}
/// <summary>
/// End touch with id.
/// </summary>
/// <param name="id">Touch point id.</param>
protected virtual void endTouch(int id)
{
manager.EndTouch(id);
}
/// <summary>
/// Move touch with id.
/// </summary>
/// <param name="id">Touch id.</param>
/// <param name="position">New screen position.</param>
protected virtual void moveTouch(int id, Vector2 position)
{
if (CoordinatesRemapper != null)
{
position = CoordinatesRemapper.Remap(position);
}
manager.MoveTouch(id, position);
}
/// <summary>
/// Cancel touch with id.
/// </summary>
/// <param name="id">Touch id.</param>
protected virtual void cancelTouch(int id)
{
manager.CancelTouch(id);
}
#endregion
}
}