-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventFinder.cs
99 lines (81 loc) · 2.2 KB
/
EventFinder.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
using Godot;
using Godot.Collections;
using tmfos.stage;
using tmfos.trigger;
namespace tmfos.mob;
/// <summary>
/// イベント処理との接触判定を行う。
/// </summary>
public partial class EventFinder : Area2D
{
public Node2D EventNode2D;
private readonly Array<ulong> _target = [];
public override void _Ready()
{
_ = Connect(Area2D.SignalName.AreaEntered, new Callable(this, MethodName.Area2DEntered));
_ = Connect(Area2D.SignalName.AreaExited, new Callable(this, MethodName.Area2DExited));
AddToGroup(StageRoot.PhysicsProcessGroup);
if (GetParent() is ActionMob amob)
{
EventNode2D = amob;
}
}
public override void _PhysicsProcess(double delta)
{
if (EventNode2D is null)
{
return;
}
Array<ulong> remove = [];
foreach (ulong id in _target)
{
if (!IsInstanceIdValid(id))
{
remove.Add(id);
continue;
}
GodotObject gobj = InstanceFromId(id);
if (!IsInstanceValid(gobj))
{
remove.Add(id);
continue;
}
if (gobj is TriggerArea2D node && OverlapsArea(node) && (!node.Search || (node.Search && EventNode2D is ActionMob amob && amob.Search)))
{
node.Exec(EventNode2D);
}
}
foreach (ulong id in remove)
{
_ = _target.Remove(id);
}
}
public void Area2DEntered(Area2D area)
{
_ = CallDeferred(MethodName.DeferredNodeEntered, area);
}
public void Area2DExited(Area2D area)
{
_ = CallDeferred(MethodName.DeferredNodeExited, area);
}
public void DeferredNodeEntered(Area2D node)
{
ulong id = node.GetInstanceId();
if (!_target.Contains(id))
{
_target.Add(id);
}
}
public void DeferredNodeExited(Area2D node)
{
ulong id = node.GetInstanceId();
if (_target.Contains(id))
{
_ = _target.Remove(id);
}
}
public void Exec()
{
//Lib.ExecCommands(node, EventNode2D, true);
}
}