-
Notifications
You must be signed in to change notification settings - Fork 20
/
CustomCursor.cs
36 lines (30 loc) · 1.25 KB
/
CustomCursor.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
using Godot;
namespace Tutorial36_CustomCursors {
public partial class CustomCursor : Node {
Texture2D _defaultCursor;
Texture2D _grabCursor;
public override void _Ready() {
_defaultCursor = ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/default.png");
_grabCursor = ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/grab.png");
Input.SetCustomMouseCursor(_defaultCursor);
Input.SetCustomMouseCursor(
ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/wait.png"),
Input.CursorShape.Wait);
Input.SetCustomMouseCursor(
ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/drag.png"),
Input.CursorShape.Drag);
Input.SetCustomMouseCursor(
ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/forbidden.png"),
Input.CursorShape.Forbidden);
Input.SetCustomMouseCursor(
ResourceLoader.Load<Texture2D>("res://36-CustomCursors/art/cursors/i-beam.png"),
Input.CursorShape.Ibeam);
}
public override void _Input(InputEvent @event) {
if (@event is InputEventMouseButton e && e.ButtonIndex == MouseButton.Right) {
if (e.Pressed) Input.SetCustomMouseCursor(_grabCursor);
else Input.SetCustomMouseCursor(_defaultCursor);
}
}
}
}