-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLightSource.cs
70 lines (64 loc) · 1.67 KB
/
LightSource.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
using Godot;
using System;
namespace FauxLight;
[Tool, GlobalClass]
public partial class LightSource : Node2D
{
public LightSource()
{
SetNotifyTransform(true);
}
[Export]
public int MaxSize
{
get => _maxSize;
set
{
_maxSize = value;
GlobalPositionChanged?.Invoke(this);
}
}
[Export(PropertyHint.Range, "0.0, 5.0")]
public float Speed
{
get => _speed;
set
{
_speed = value;
GlobalPositionChanged?.Invoke(this);
}
}
public event Action<LightSource>? GlobalPositionChanged;
public event Action<LightSource>? Parented;
public event Action<LightSource>? Unparented;
public event Action<LightSource>? Deleted;
public event Action<LightSource>? VisibilityUpdated;
private int _maxSize = 100;
private float _speed = 0.25f;
public override void _Notification(int what)
{
switch ((long)what)
{
case NotificationParented:
Parented?.Invoke(this);
CallDeferred(MethodName.ResetPosition);
break;
case NotificationTransformChanged:
GlobalPositionChanged?.Invoke(this);
break;
case NotificationUnparented:
Unparented?.Invoke(this);
break;
case NotificationPredelete:
Deleted?.Invoke(this);
break;
case NotificationVisibilityChanged:
VisibilityUpdated?.Invoke(this);
break;
}
}
private void ResetPosition()
{
Position = Vector2.Zero;
}
}