forked from TouchScript/TouchScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMouseInput.cs
More file actions
87 lines (68 loc) · 2.43 KB
/
Copy pathMouseInput.cs
File metadata and controls
87 lines (68 loc) · 2.43 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
/*
* @author Valentin Simonov / http://va.lent.in/
*/
using TouchScript.Utils.Editor.Attributes;
using UnityEngine;
namespace TouchScript.InputSources
{
/// <summary>
/// Input source which transfers mouse clicks to touches.
/// </summary>
[AddComponentMenu("TouchScript/Input Sources/Mouse Input")]
public sealed class MouseInput : InputSource
{
#region Public properties
/// <summary>
/// Indicates if this input source should be disabled on mobile platforms.
/// </summary>
/// <remarks>
/// Operation Systems which support touch input send first touches as mouse clicks which may result in duplicated touch points in exactly the same coordinates. This affects clusters and multitouch gestures.
/// </remarks>
[ToggleLeft]
public bool DisableOnMobilePlatforms = true;
/// <summary>
/// Tags added to touches coming from this input.
/// </summary>
public Tags Tags = new Tags(Tags.INPUT_MOUSE);
#endregion
#region Private variables
private MouseHandler mouseHandler;
#endregion
#region Unity methods
/// <inheritdoc />
protected override void OnEnable()
{
base.OnEnable();
if (DisableOnMobilePlatforms)
{
switch (Application.platform)
{
case RuntimePlatform.Android:
case RuntimePlatform.IPhonePlayer:
case RuntimePlatform.WP8Player:
case RuntimePlatform.MetroPlayerARM:
case RuntimePlatform.MetroPlayerX64:
case RuntimePlatform.MetroPlayerX86:
// don't need mouse here
enabled = false;
return;
}
}
mouseHandler = new MouseHandler((p) => beginTouch(p, new Tags(Tags)), moveTouch, endTouch, cancelTouch);
}
/// <inheritdoc />
protected override void OnDisable()
{
mouseHandler.Destroy();
mouseHandler = null;
base.OnDisable();
}
/// <inheritdoc />
protected override void Update()
{
base.Update();
mouseHandler.Update();
}
#endregion
}
}