Skip to content

Commit af972c8

Browse files
committed
1.1.4.1
Fixes and rewrites.
1 parent c2149bf commit af972c8

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

Controllers/CustomZoneController.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public void SetNodes(IEnumerable<Vector3> nodes)
2828
if (state) colliders.Add(other);
2929
else colliders.Remove(other);
3030
}
31-
return UpdateEnterState(other);
31+
state = IsPositionInside(other);
32+
return base.SetEnterState(other, state);
3233
}
3334
protected override void OnTriggerEnter(Collider other) => SetEnterState(other, true);
3435
protected override void OnTriggerExit(Collider other) => SetEnterState(other, false);

Controllers/ZoneController.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,23 @@ protected virtual bool UpdateEnterState(Collider other)
5050
var state = IsPositionInside(other) && TryCheck(other);
5151
return SetEnterState(other, state);
5252
}
53+
protected virtual bool UpdateEnterState(UnityComponent component) => UpdateEnterState(component?.GetComponent<Collider>());
5354
protected virtual void OnTriggerEnter(Collider other) => SetEnterState(other, true);
5455
protected virtual void OnTriggerExit(Collider other) => SetEnterState(other, false);
5556

5657
protected readonly List<CSteamID> enteredPlayers = new();
5758
public virtual IReadOnlyCollection<CSteamID> EnteredPlayers => enteredPlayers;
5859

60+
protected bool SetEnterState(SPlayer target, bool state) => SetEnterState(target?.player, state);
5961
protected bool SetEnterState(Player target, bool state)
6062
{
6163
if (!target) return state;
62-
if (!SetEnterState(target.channel.owner.playerID.steamID, state)) return state;
64+
if (!TrySetEnterState(target.channel.owner.playerID.steamID, state)) return state;
6365

6466
InvokeEventsSafe(target, state, OnPlayerEnter, OnPlayerExit);
6567
return state;
6668
}
67-
protected bool SetEnterState(CSteamID id, bool state)
69+
protected bool TrySetEnterState(CSteamID id, bool state)
6870
{
6971
if (IsInside(id) == state) return false;
7072

@@ -79,15 +81,14 @@ protected bool SetEnterState(Vehicle target, bool state)
7981
state = SetEnterState(target, state, OnVehicleEnter, OnVehicleExit);
8082

8183
foreach (var passanger in target.passengers)
82-
if (passanger.player is { } splayer)
83-
SetEnterState(splayer.player, state);
84+
SetEnterState(passanger.player, state);
8485

8586
return state;
8687
}
8788
protected bool SetEnterState(Animal target, bool state) => SetEnterState(target, state, OnAnimalEnter, OnAnimalExit);
8889
protected bool SetEnterState(Zombie target, bool state) => SetEnterState(target, state, OnZombieEnter, OnZombieExit);
8990

90-
protected bool SetEnterState<T>(T target, bool state, StateUpdateHandler<T> enter, StateUpdateHandler<T> exit)
91+
protected bool SetEnterState<T>(T target, bool state, StateUpdateHandler<T> enter, StateUpdateHandler<T> exit)
9192
where T : UnityComponent
9293
{
9394
if (!target) return state;
@@ -102,22 +103,38 @@ protected void InvokeEventsSafe<T>(T value, bool state, StateUpdateHandler<T> en
102103
try
103104
{
104105
(state ? enter : exit)?.Invoke(value);
105-
} catch { }
106+
}
107+
catch { }
106108
}
107109

108110
protected virtual float UpdateCollidersDelay { get; } = 0.2f;
109111
protected void UpdateEnteredColliders(IList<Collider> colliders)
110112
{
111-
for (int i = 0; i < colliders.Count;i++)
113+
List<UnityComponent> other = new();
114+
for (int i = 0; i < colliders.Count; i++)
112115
{
113116
var collider = colliders.ElementAt(i);
114117
if (!collider)
115118
{
116119
colliders.RemoveAt(i--);
117120
continue;
118121
}
122+
123+
var player = collider.GetComponent<Player>();
124+
if (player)
125+
{
126+
var vehicle = player.movement.getVehicle();
127+
if (vehicle)
128+
{
129+
other.Add(vehicle);
130+
continue;
131+
}
132+
}
133+
119134
UpdateEnterState(collider);
120135
}
136+
foreach (var component in other.Distinct())
137+
UpdateEnterState(component);
121138
}
122139
protected virtual void UpdateEnteredColliders() => UpdateEnteredColliders(enteredColliders);
123140
protected virtual IEnumerator UpdateEnteredCollidersRoutine()

SZones.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<TargetFrameworks>net472</TargetFrameworks>
66
<AssemblyName>SZones</AssemblyName>
77
<RootNamespace>SZones</RootNamespace>
8-
<Version>1.1.4.0</Version>
8+
<Version>1.1.4.1</Version>
99
<NoWarn>$(NoWarn);CS0436</NoWarn>
1010
<RunPostBuildEvent>Always</RunPostBuildEvent>
1111
<Nullable>annotations</Nullable>

0 commit comments

Comments
 (0)