-
Notifications
You must be signed in to change notification settings - Fork 1
/
SetMouseCursor2.cs
134 lines (107 loc) · 4.23 KB
/
SetMouseCursor2.cs
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
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using System.Collections;
namespace Fungus
{
/// <summary>
/// Sets the mouse cursor sprite.
/// </summary>
[CommandInfo("Sprite",
"Set Mouse Cursor 2",
"Sets the mouse cursor sprite.")]
[AddComponentMenu("")]
public class SetMouseCursor2 : Command
{
[Tooltip("Texture to use for cursor. Will use default mouse cursor if no sprite is specified")]
[SerializeField] protected Texture2D cursorTexture;
[Tooltip("The offset from the top left of the texture to use as the target point")]
[SerializeField] protected Vector2 hotSpot;
[Tooltip("Texture to use for cursor. Will use default mouse cursor if no sprite is specified")]
[SerializeField] protected Texture2D cursorTexture2;
[Tooltip("The offset from the top left of the texture to use as the target point")]
[SerializeField] protected Vector2 hotSpot2;
[Tooltip("This for safety reasons, in case user spam clicks. Set the number higher. Can't be lower than 0.3, if it's lower, then 0.3 will be used")]
[SerializeField] protected float clickSpamPrevention = 0.3f;
private static bool onCustomCursorEnable = false;
// Cached static cursor settings
protected static Texture2D activeCursorTexture;
protected static Vector2 activeHotspot;
protected static Texture2D activeCursorTexture2;
protected static Vector2 activeHotspot2;
protected bool clicked = false;
#region Public members
public static void ResetMouseCursor()
{
// Change mouse cursor back to most recent settings
Cursor.SetCursor(activeCursorTexture, activeHotspot, CursorMode.Auto);
Cursor.SetCursor(activeCursorTexture2, activeHotspot2, CursorMode.Auto);
}
void Update()
{
if (Input.GetMouseButtonDown(0))
{
if(!clicked)
{
StartCoroutine(clicking());
}
}
}
public IEnumerator clicking()
{
if(clicked == false)
{
clicked = true;
Cursor.SetCursor(activeCursorTexture2, activeHotspot2, CursorMode.Auto);
if(clickSpamPrevention <= 0.3)
{
yield return new WaitForSeconds(0.3f);
}
else
{
yield return new WaitForSeconds(clickSpamPrevention);
}
BeforeClicking();
}
}
public void BeforeClicking()
{
if(clicked == true)
{
clicked = false;
Cursor.SetCursor(activeCursorTexture, activeHotspot, CursorMode.Auto);
StopCoroutine(clicking());
}
}
public override void OnEnter()
{
if (cursorTexture && cursorTexture2 != null)
{
Cursor.SetCursor(cursorTexture, hotSpot, CursorMode.Auto);
Cursor.SetCursor(cursorTexture2, hotSpot2, CursorMode.Auto);
activeCursorTexture = cursorTexture;
activeCursorTexture2 = cursorTexture2;
activeHotspot = hotSpot;
activeHotspot2 = hotSpot2;
}
Continue();
}
public override string GetSummary()
{
if (cursorTexture == null)
{
return "Error: No cursor sprite selected";
}
if (cursorTexture2 == null)
{
return "Error: No cursor sprite selected";
}
return cursorTexture.name + " : " + cursorTexture2.name;
}
public override Color GetButtonColor()
{
return new Color32(235, 191, 217, 255);
}
#endregion
}
}