Skip to content

Commit e333c7e

Browse files
authored
feat: action system cleanup MTT-4244 (#701)
* Adjusted GameStateBehaviour class description * Removed ClientBossRoomState And renamed ServerBossRoomState to BossRoomState. Added lifetime scopes to all the subscenes of BossRoom scene. These autoinject gameobjects that live under the "static network objects" groupings. * Removed NetworkGameState and NetworkWinState replaced with BufferedNetworkMessageChannel (an addition in this entry) - this message channel is identical to NetworkMessageChannel, but it inherits from a buffered message channel instead. This is used as a way to pass data that syncs from server to clients between different scenes without the need for SO variables, which are hard to understand. * ClientMainMenuState renamed to MainMenuState * Removed ClientPostGameState and renamed ServerPostGameState to PostGameState also added auto-injected objects to the PostGameState-bearing game object. * moving files to different subfolders for better organization * Changelog and typo fixes * nullref fix (was disposing of a subscription handle before it was returned from the method) * Removed BufferedNetworkMessageChannel Replaced it's usage with WinState with a NetworkWinState that's preserved by BossRoomState to survive onto the next scene, PostGameState, which then destroys that preserved gameobject/NetworkWinState when we exit PostGameState to whatever next state. * actually setting win state * # * further folder adjustments * Namespace and funtion name changes for Actions Moved all Action-related code into .Actions namespace, adjusted the rest of the codebase accordingly. Renamed Start and Update methods of Actions to be OnStart and OnUpdate (to avoid confusing overlap with MonoBehavior event calls). Moved FXProjectile to GameplayObjects folder. * Start renamed to OnStart in ActionVisualization * moving new actions appropriately * Restored Client/Server names for game states these were accidentally overriden during merges
1 parent d8d116f commit e333c7e

File tree

93 files changed

+276
-209
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+276
-209
lines changed

Assets/Scripts/Gameplay/Action/ActionPlayers.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Gameplay/Action/ActionPlayer.cs renamed to Assets/Scripts/Gameplay/Action/ActionPlayers/ActionPlayer.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using System.Collections.Generic;
2+
using Unity.Multiplayer.Samples.BossRoom.Server;
23
using UnityEngine;
34
using BlockingMode = Unity.Multiplayer.Samples.BossRoom.ActionDescription.BlockingModeType;
45

5-
namespace Unity.Multiplayer.Samples.BossRoom.Server
6+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
67
{
78
/// <summary>
89
/// Class responsible for playing back action inputs from user.
@@ -158,7 +159,7 @@ private void StartAction()
158159
SynthesizeChaseIfNecessary(index);
159160

160161
m_Queue[0].TimeStarted = Time.time;
161-
bool play = m_Queue[0].Start();
162+
bool play = m_Queue[0].OnStart();
162163
if (!play)
163164
{
164165
//actions that exited out in the "Start" method will not have their End method called, by design.
@@ -314,7 +315,7 @@ public void Update()
314315
/// <returns>true if the action is still active, false if it's dead</returns>
315316
private bool UpdateAction(Action action)
316317
{
317-
bool keepGoing = action.Update();
318+
bool keepGoing = action.OnUpdate();
318319
bool expirable = action.Description.DurationSeconds > 0f; //non-positive value is a sentinel indicating the duration is indefinite.
319320
var timeElapsed = Time.time - action.TimeStarted;
320321
bool timeExpired = expirable && timeElapsed >= action.Description.DurationSeconds;

Assets/Scripts/Gameplay/Action/ActionVisualization.cs renamed to Assets/Scripts/Gameplay/Action/ActionPlayers/ActionVisualization.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
2+
using Unity.Multiplayer.Samples.BossRoom.Visual;
23

3-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
4+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
45
{
56
/// <summary>
67
/// This is a companion class to ClientCharacterVisualization that is specifically responsible for visualizing Actions. Action visualizations have lifetimes
@@ -23,13 +24,13 @@ public ActionVisualization(ClientCharacterVisualization parent)
2324
Parent = parent;
2425
}
2526

26-
public void Update()
27+
public void OnUpdate()
2728
{
2829
//do a reverse-walk so we can safely remove inside the loop.
2930
for (int i = m_PlayingActions.Count - 1; i >= 0; --i)
3031
{
3132
var action = m_PlayingActions[i];
32-
bool keepGoing = action.Anticipated || action.Update(); // only call Update() on actions that are past anticipation
33+
bool keepGoing = action.Anticipated || action.OnUpdate(); // only call OnUpdate() on actions that are past anticipation
3334
bool expirable = action.Description.DurationSeconds > 0f; //non-positive value is a sentinel indicating the duration is indefinite.
3435
bool timeExpired = expirable && action.TimeRunning >= action.Description.DurationSeconds;
3536
bool timedOut = action.Anticipated && action.TimeRunning >= k_AnticipationTimeoutSeconds;
@@ -114,7 +115,7 @@ public void PlayAction(ref ActionRequestData data)
114115
var anticipatedActionIndex = FindAction(data.ActionTypeEnum, true);
115116

116117
var actionFX = anticipatedActionIndex >= 0 ? m_PlayingActions[anticipatedActionIndex] : ActionFX.MakeActionFX(ref data, Parent);
117-
if (actionFX.Start())
118+
if (actionFX.OnStart())
118119
{
119120
m_PlayingActions.Add(actionFX);
120121
}

Assets/Scripts/Gameplay/Action/ActionUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Unity.Netcode;
33
using UnityEngine;
44

5-
namespace Unity.Multiplayer.Samples.BossRoom
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
66
{
77
public static class ActionUtils
88
{

Assets/Scripts/Gameplay/Action/BaseTypes.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Gameplay/Action/Action.cs renamed to Assets/Scripts/Gameplay/Action/BaseTypes/Action.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Server;
12
using UnityEngine;
23
using BlockingMode = Unity.Multiplayer.Samples.BossRoom.ActionDescription.BlockingModeType;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Server
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// <summary>
78
/// The abstract parent class that all Actions derive from.
@@ -40,17 +41,17 @@ public Action(ServerCharacter parent, ref ActionRequestData data) : base(ref dat
4041
/// Called when the Action starts actually playing (which may be after it is created, because of queueing).
4142
/// </summary>
4243
/// <returns>false if the action decided it doesn't want to run after all, true otherwise. </returns>
43-
public abstract bool Start();
44+
public abstract bool OnStart();
4445

4546

4647
/// <summary>
4748
/// Called each frame while the action is running.
4849
/// </summary>
4950
/// <returns>true to keep running, false to stop. The Action will stop by default when its duration expires, if it has a duration set. </returns>
50-
public abstract bool Update();
51+
public abstract bool OnUpdate();
5152

5253
/// <summary>
53-
/// Called each frame (before Update()) for the active ("blocking") Action, asking if it should become a background Action.
54+
/// Called each frame (before OnUpdate()) for the active ("blocking") Action, asking if it should become a background Action.
5455
/// </summary>
5556
/// <returns>true to become a non-blocking Action, false to remain a blocking Action</returns>
5657
public virtual bool ShouldBecomeNonBlocking()

Assets/Scripts/Gameplay/Action/ActionBase.cs renamed to Assets/Scripts/Gameplay/Action/BaseTypes/ActionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33

4-
namespace Unity.Multiplayer.Samples.BossRoom
4+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
55
{
66
/// <summary>
77
/// Abstract base class containing some common members shared by Action (server) and ActionFX (client visual)

Assets/Scripts/Gameplay/Action/ActionFX.cs renamed to Assets/Scripts/Gameplay/Action/BaseTypes/ActionFX.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
using UnityEngine;
22
using System.Collections.Generic;
3+
using Unity.Multiplayer.Samples.BossRoom.Visual;
34
using Unity.Netcode;
45

5-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
6+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
67
{
78
/// <summary>
89
/// Abstract base class for playing back the visual feedback of an Action.
@@ -30,17 +31,17 @@ public ActionFX(ref ActionRequestData data, ClientCharacterVisualization parent)
3031
/// Starts the ActionFX. Derived classes may return false if they wish to end immediately without their Update being called.
3132
/// </summary>
3233
/// <remarks>
33-
/// Derived class should be sure to call base.Start() in their implementation, but note that this resets "Anticipated" to false.
34+
/// Derived class should be sure to call base.OnStart() in their implementation, but note that this resets "Anticipated" to false.
3435
/// </remarks>
3536
/// <returns>true to play, false to be immediately cleaned up.</returns>
36-
public virtual bool Start()
37+
public virtual bool OnStart()
3738
{
3839
Anticipated = false; //once you start for real you are no longer an anticipated action.
3940
TimeStarted = UnityEngine.Time.time;
4041
return true;
4142
}
4243

43-
public abstract bool Update();
44+
public abstract bool OnUpdate();
4445

4546
/// <summary>
4647
/// End is always called when the ActionFX finishes playing. This is a good place for derived classes to put

Assets/Scripts/Gameplay/Action/ConcreteActions.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Scripts/Gameplay/Action/AOEAction.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/AOEAction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Server;
12
using Unity.Netcode;
23
using UnityEngine;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Server
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// <summary>
78
/// Area-of-effect attack Action. The attack is centered on a point provided by the client.
@@ -20,7 +21,7 @@ public class AoeAction : Action
2021
public AoeAction(ServerCharacter parent, ref ActionRequestData data)
2122
: base(parent, ref data) { }
2223

23-
public override bool Start()
24+
public override bool OnStart()
2425
{
2526
float distanceAway = Vector3.Distance(m_Parent.physicsWrapper.Transform.position, Data.Position);
2627
if (distanceAway > Description.Range + k_MaxDistanceDivergence)
@@ -38,7 +39,7 @@ public override bool Start()
3839
return ActionConclusion.Continue;
3940
}
4041

41-
public override bool Update()
42+
public override bool OnUpdate()
4243
{
4344
if (TimeRunning >= Description.ExecTimeSeconds && !m_DidAoE)
4445
{

Assets/Scripts/Gameplay/Action/AnimationOnlyActionFX.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/AnimationOnlyActionFX.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
1+
using Unity.Multiplayer.Samples.BossRoom.Visual;
2+
3+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
24
{
35
/// <summary>
46
/// Used for simple Actions that only need to play a few animations (one at startup and optionally
@@ -8,7 +10,7 @@ public class AnimationOnlyActionFX : ActionFX
810
{
911
public AnimationOnlyActionFX(ref ActionRequestData data, ClientCharacterVisualization parent) : base(ref data, parent) { }
1012

11-
public override bool Update()
13+
public override bool OnUpdate()
1214
{
1315
return ActionConclusion.Continue;
1416
}

Assets/Scripts/Gameplay/Action/AoeActionFX.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/AoeActionFX.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
using System;
2+
using Unity.Multiplayer.Samples.BossRoom.Visual;
23
using UnityEngine;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// Final step in the AoE action flow. Please see AoEActionInput for the first step and more details on overall flow
78
public class AoeActionFX : ActionFX
89
{
910
public AoeActionFX(ref ActionRequestData data, ClientCharacterVisualization parent)
1011
: base(ref data, parent) { }
1112

12-
public override bool Start()
13+
public override bool OnStart()
1314
{
14-
base.Start();
15+
base.OnStart();
1516
GameObject.Instantiate(Description.Spawns[0], m_Data.Position, Quaternion.identity);
1617
return ActionConclusion.Stop;
1718
}
1819

19-
public override bool Update()
20+
public override bool OnUpdate()
2021
{
2122
throw new Exception("This should not execute");
2223
}

Assets/Scripts/Gameplay/Action/ChargedLaunchProjectileAction.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/ChargedLaunchProjectileAction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Server;
12
using Unity.Netcode;
23
using UnityEngine;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Server
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// <summary>
78
/// A version of LaunchProjectileAction that can be "powered up" by holding down the attack key.
@@ -34,7 +35,7 @@ public class ChargedLaunchProjectileAction : LaunchProjectileAction
3435

3536
public ChargedLaunchProjectileAction(ServerCharacter parent, ref ActionRequestData data) : base(parent, ref data) { }
3637

37-
public override bool Start()
38+
public override bool OnStart()
3839
{
3940
// if we have an explicit target, make sure we're aimed at them.
4041
// (But if the player just clicked on an attack button, there won't be an explicit target, so we should stay facing however we're facing.)
@@ -64,7 +65,7 @@ public override bool Start()
6465
return true;
6566
}
6667

67-
public override bool Update()
68+
public override bool OnUpdate()
6869
{
6970
if (m_StoppedChargingUpTime == 0 && GetPercentChargedUp() >= 1)
7071
{

Assets/Scripts/Gameplay/Action/ChargedLaunchProjectileActionFX.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/ChargedLaunchProjectileActionFX.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System.Collections.Generic;
2+
using Unity.Multiplayer.Samples.BossRoom.Visual;
23

3-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
4+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
45
{
56
/// <summary>
67
/// The visual aspect of a ChargedLaunchProjectileAction.
@@ -23,15 +24,15 @@ public ChargedLaunchProjectileActionFX(ref ActionRequestData data, ClientCharact
2324

2425
private bool m_ChargeEnded;
2526

26-
public override bool Start()
27+
public override bool OnStart()
2728
{
28-
base.Start();
29+
base.OnStart();
2930

3031
m_Graphics = InstantiateSpecialFXGraphics(m_Parent.transform, true);
3132
return true;
3233
}
3334

34-
public override bool Update()
35+
public override bool OnUpdate()
3536
{
3637
return !m_ChargeEnded;
3738
}

Assets/Scripts/Gameplay/Action/ChargedShieldAction.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/ChargedShieldAction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Server;
12
using Unity.Netcode;
23
using UnityEngine;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Server
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// <summary>
78
/// A defensive action where the character becomes resistant to damage.
@@ -30,7 +31,7 @@ public class ChargedShieldAction : Action
3031
public ChargedShieldAction(ServerCharacter parent, ref ActionRequestData data)
3132
: base(parent, ref data) { }
3233

33-
public override bool Start()
34+
public override bool OnStart()
3435
{
3536
if (m_Data.TargetIds != null && m_Data.TargetIds.Length > 0)
3637
{
@@ -60,7 +61,7 @@ private bool IsChargingUp()
6061
return m_StoppedChargingUpTime == 0;
6162
}
6263

63-
public override bool Update()
64+
public override bool OnUpdate()
6465
{
6566
if (m_StoppedChargingUpTime == 0)
6667
{

Assets/Scripts/Gameplay/Action/ChargedShieldActionFX.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/ChargedShieldActionFX.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Visual;
12
using UnityEngine;
23
using UnityEngine.Assertions;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Visual
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
/// <summary>
78
/// The visual aspect of a ChargedShieldAction. Shows "charge up particles" while the power is charging up.
@@ -28,11 +29,11 @@ public class ChargedShieldActionFX : ActionFX
2829

2930
public ChargedShieldActionFX(ref ActionRequestData data, ClientCharacterVisualization parent) : base(ref data, parent) { }
3031

31-
public override bool Start()
32+
public override bool OnStart()
3233
{
3334
Assert.IsTrue(Description.Spawns.Length == 2, $"Found {Description.Spawns.Length} spawns for action {Description.ActionTypeEnum}. Should be exactly 2: a charge-up particle and a fully-charged particle");
3435

35-
base.Start();
36+
base.OnStart();
3637
m_ChargeGraphics = InstantiateSpecialFXGraphic(Description.Spawns[0], m_Parent.transform, true);
3738
return true;
3839
}
@@ -42,7 +43,7 @@ private bool IsChargingUp()
4243
return m_StoppedChargingUpTime == 0;
4344
}
4445

45-
public override bool Update()
46+
public override bool OnUpdate()
4647
{
4748
return IsChargingUp() || (Time.time - m_StoppedChargingUpTime) < Description.EffectDurationSeconds;
4849
}

Assets/Scripts/Gameplay/Action/ChaseAction.cs renamed to Assets/Scripts/Gameplay/Action/ConcreteActions/ChaseAction.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
using Unity.Multiplayer.Samples.BossRoom.Server;
12
using Unity.Netcode;
23
using UnityEngine;
34

4-
namespace Unity.Multiplayer.Samples.BossRoom.Server
5+
namespace Unity.Multiplayer.Samples.BossRoom.Actions
56
{
67
public class ChaseAction : Action
78
{
@@ -20,7 +21,7 @@ public ChaseAction(ServerCharacter parent, ref ActionRequestData data) : base(pa
2021
/// Called when the Action starts actually playing (which may be after it is created, because of queueing).
2122
/// </summary>
2223
/// <returns>false if the action decided it doesn't want to run after all, true otherwise. </returns>
23-
public override bool Start()
24+
public override bool OnStart()
2425
{
2526
if (!HasValidTarget())
2627
{
@@ -94,7 +95,7 @@ private bool StopIfDone()
9495
/// Called each frame while the action is running.
9596
/// </summary>
9697
/// <returns>true to keep running, false to stop. The Action will stop by default when its duration expires, if it has a duration set. </returns>
97-
public override bool Update()
98+
public override bool OnUpdate()
9899
{
99100
if (StopIfDone()) { return ActionConclusion.Stop; }
100101

0 commit comments

Comments
 (0)