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
110 lines (92 loc) · 2.85 KB
/
Copy pathInputSource.cs
File metadata and controls
110 lines (92 loc) · 2.85 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
/*
* @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 Private variables
/// <summary>
/// Reference to global touch manager.
/// </summary>
protected TouchManager manager;
#endregion
#region Public properties
/// <summary>
/// Optional remapper to use to change screen coordinates which go into the TouchManager.
/// </summary>
public ICoordinatesRemapper CoordinatesRemapper { get; set; }
#endregion
#region Unity
/// <summary>
/// Unity Start callback.
/// </summary>
protected virtual void Start()
{
manager = TouchManager.Instance;
if (manager == null) throw new InvalidOperationException("TouchManager instance is required!");
}
/// <summary>
/// Unity OnDestroy callback.
/// </summary>
protected virtual void OnDestroy()
{
manager = null;
}
/// <summary>
/// Unity Update callback.
/// </summary>
protected virtual void Update()
{}
#endregion
#region Callbacks
/// <summary>
/// Start touch in given screen position.
/// </summary>
/// <param name="position">Screen position.</param>
/// <returns>Internal touch id.</returns>
protected int beginTouch(Vector2 position)
{
if (CoordinatesRemapper != null)
{
position = CoordinatesRemapper.Remap(position);
}
return manager.BeginTouch(position);
}
/// <summary>
/// End touch with id.
/// </summary>
/// <param name="id">Touch point id.</param>
protected 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 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 void cancelTouch(int id)
{
manager.CancelTouch(id);
}
#endregion
}
}