RegionAction - jimdroberts/FishMMO GitHub Wiki
RegionAction is an abstract base ScriptableObject for FishMMO that defines the contract for region actions. Region actions specify behaviors that are triggered when a player interacts with a region, enabling extensible and modular gameplay logic for different region-based events.
-
public abstract void Invoke(IPlayerCharacter character, Region region, bool isReconciling)
Invokes the region action for the specified player character and region. Must be implemented by derived classes. Parameters: - IPlayerCharacter character: The player character triggering the action. - Region region: The region in which the action is triggered. - bool isReconciling: Indicates if the action is part of a reconciliation process (e.g., network state sync). Returns: void. No exceptions are thrown by default, but implementations may throw as needed.
- Create a new class that derives from RegionAction and implement the Invoke method.
- Create a ScriptableObject asset for your derived RegionAction class via the Unity Editor.
- Attach the RegionAction asset to a region definition or trigger as appropriate.
// Example 1: Creating a custom region action
public class CustomRegionAction : RegionAction
{
public override void Invoke(IPlayerCharacter character, Region region, bool isReconciling)
{
// Custom logic for the region action
}
}
// Example 2: Using a region action in code
regionAction.Invoke(playerCharacter, region, false);
- Always implement the Invoke method with clear, concise logic for the intended region behavior.
- Use derived classes to encapsulate specific region actions for modularity and maintainability.
- Document the purpose and usage of each custom region action for future reference.