forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTouchPoint.cs
More file actions
110 lines (90 loc) · 2.81 KB
/
Copy pathTouchPoint.cs
File metadata and controls
110 lines (90 loc) · 2.81 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.Collections.Generic;
using TouchScript.Hit;
using TouchScript.Layers;
using UnityEngine;
namespace TouchScript
{
/// <summary>
/// Class which internally represents a touch.
/// </summary>
internal sealed class TouchPoint : ITouch
{
#region Public properties
/// <inheritdoc />
public int Id { get; private set; }
/// <inheritdoc />
public Transform Target { get; internal set; }
/// <inheritdoc />
public Vector2 Position
{
get { return position; }
}
/// <inheritdoc />
public Vector2 PreviousPosition { get; private set; }
/// <inheritdoc />
public ITouchHit Hit
{
get
{
if (isDirty)
{
TouchManager.Instance.GetHitTarget(position, out hit);
isDirty = false;
}
return hit;
}
internal set
{
hit = value;
isDirty = false;
}
}
/// <inheritdoc />
public TouchLayer Layer { get; internal set; }
public Tags Tags { get; private set; }
public IDictionary<string, System.Object> Properties
{
get { return properties; }
}
#endregion
#region Private variables
private Vector2 position = Vector2.zero;
private Vector2 newPosition = Vector2.zero;
private ITouchHit hit;
private bool isDirty = false;
private Dictionary<string, System.Object> properties;
#endregion
/// <summary>
/// Initializes a new instance of the <see cref="TouchPoint"/> class.
/// </summary>
/// <param name="id">Unique id of the touch.</param>
/// <param name="position">Screen position of the touch.</param>
/// <param name="tags">Initial tags.</param>
internal TouchPoint(int id, Vector2 position, Tags tags)
{
Id = id;
this.position = PreviousPosition = newPosition = position;
Tags = tags ?? new Tags();
properties = new Dictionary<string, object>();
}
#region Internal methods
/// <summary>
/// Resets touch's position. Used internally to update <see cref="TouchPoint.PreviousPosition"/> between frames.
/// </summary>
internal void ResetPosition()
{
PreviousPosition = position;
position = newPosition;
newPosition = position;
if (PreviousPosition != position) isDirty = true;
}
internal void SetPosition(Vector2 value)
{
newPosition = value;
}
#endregion
}
}