RegionChangeFogAction - jimdroberts/FishMMO GitHub Wiki
RegionChangeFogAction is a region action ScriptableObject that triggers a change in fog settings for the client when invoked. It is used to notify client-side systems to update fog parameters (such as color, density, and mode) when a player enters or interacts with a region. This action is typically configured in the Unity Editor and is part of the FishMMO region system, enabling dynamic environmental effects based on player location.
-
public static event Action OnChangeFog
Event invoked to notify listeners to change fog settings. Typically handled by client-side systems.
-
public FogSettings FogSettings
The fog settings to apply when this region action is triggered.
-
public override void Invoke(IPlayerCharacter character, Region region, bool isReconciling)
Invokes the region action, triggering a fog change for the owning client if conditions are met. 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.
- Ensure the FishMMO region system is set up in your scene and that regions are configured to use region actions.
- Create a new RegionChangeFogAction asset via the Unity Editor (Assets > Create > FishMMO > Region > Region Change Fog).
- Assign the desired FogSettings to the RegionChangeFogAction asset.
- Attach the RegionChangeFogAction to a region in your scene.
// Example 1: Assigning and using RegionChangeFogAction in a region
// 1. Create a RegionChangeFogAction asset in the Unity Editor.
// 2. Configure the FogSettings (color, density, mode, etc.) in the asset inspector.
// 3. Assign the asset to a region's action list.
// 4. When a player enters the region, the fog settings will update for the client.
// Example 2: Listening for fog changes in a client system
// Subscribe to the OnChangeFog event to update fog settings in your rendering system.
FishMMO.Shared.RegionChangeFogAction.OnChangeFog += (settings) => {
// Apply fog settings to the Unity RenderSettings
RenderSettings.fog = settings.Enabled;
RenderSettings.fogColor = settings.Color;
RenderSettings.fogDensity = settings.Density;
RenderSettings.fogMode = settings.Mode;
RenderSettings.fogStartDistance = settings.StartDistance;
RenderSettings.fogEndDistance = settings.EndDistance;
};
- Always check for null references when handling the OnChangeFog event.
- Use smooth transitions (ChangeRate) for a better visual experience when moving between regions.
- Configure fog settings carefully to avoid abrupt visual changes that may disorient players.
- Only trigger fog changes for the owning client to prevent unnecessary updates on other clients.