TriggerManager - alexneargarder/Broforce-Docs GitHub Wiki
- Unity Lifecycle & Setup
- Trigger System Core
- Scripted Events
- Trigger Actions
- Trigger Variables
- Camera Control
- Player Management
Unity Awake callback that initializes the TriggerManager singleton. Sets up the instance reference and initializes all collections including activeActions, triggers dictionary, bombardments list, and trigger variables.
Main update loop for the trigger system. Evaluates all enabled triggers, processes active actions based on their time offsets, updates camera control states, and manages repeating bombardments. Handles special timing for offscreen player destruction and blocks unit movement when needed.
Gets the singleton instance of the TriggerManager. Used to access the trigger system from anywhere in the game.
Activates a trigger by name, enabling it and resetting its state to allow it to be triggered again. Searches through all triggers in the system for a case-insensitive name match. Used by level scripts to dynamically enable triggers during gameplay.
Parameters:
- string p: The name of the trigger to activate (case-insensitive)
Checks for and executes any level completion triggers (success or failure) based on the current game state. Iterates through all enabled triggers looking for LevelFail or LevelSuccess types that match the current level result.
Returns:
-
bool
: True if a level end trigger was found and executed, false otherwise
Clears the list of triggers that have been marked as "trigger once" and already fired. This allows one-time triggers to be reset, typically used when restarting levels or resetting game state.
Deactivates a trigger by name, preventing it from being evaluated or executed. Searches through all triggers for a case-insensitive name match. Used to disable triggers that should no longer fire based on game state or player actions.
Parameters:
- string p: The name of the trigger to deactivate (case-insensitive)
Executes a trigger locally on this client, marking it as triggered and activating all its associated actions. For one-time triggers, adds them to the persistent tracking list. Only adds spawn actions if this is the host client to prevent duplicate spawns.
Parameters:
- Trigger trigger: The trigger to execute
Executes a trigger across all connected clients by sending an RPC to execute the trigger locally on each client. This ensures synchronized trigger execution in multiplayer games.
Parameters:
- Trigger trigger: The trigger to execute on all clients
Generates a unique identifier string for a trigger based on its properties. Combines the trigger's name, type, and position data to create a deterministic key used for tracking one-time trigger execution across game sessions.
Parameters:
- TriggerInfo trig: The trigger information to generate a unique name for
Returns:
-
string
: A unique string identifier combining trigger properties
Loads and initializes all triggers for the current level from trigger info data. Clears existing triggers, creates new trigger instances with deterministic IDs, and restores previously triggered states for one-time triggers. Also resets the PauseCameraMovements flag.
Parameters:
- System.Collections.Generic.List{TriggerInfo} triggerInfos: List of trigger information objects defining the triggers to create for the level
Registers a new entity-based trigger at runtime, typically used for dynamically spawned objects that need trigger functionality. Allocates a deterministic network ID and adds the trigger to the active triggers dictionary.
Parameters:
- TriggerInfo info: The trigger information defining the trigger's properties and behavior
Returns:
-
Trigger
: The newly created and registered Trigger instance, or null if TriggerManager instance doesn't exist
Resets all triggers in the current level by iterating through the triggers dictionary and calling Reset() on each trigger. This prepares triggers to be evaluated and fired again, typically used when restarting a level or checkpoint.
Static list tracking unique identifiers of one-time triggers that have already been executed. Persists across level loads to prevent one-time triggers from firing multiple times in offline mode.
The singleton instance of TriggerManager. Set in Awake() and accessed through the Instance property to provide global access to the trigger system.
public static BombardmentRepeat AddRepeatingBombardment(Vector3 pos, int seed, bool fireBallDiagonal, bool fireBallVertical)
Adds a repeating bombardment pattern that will continue firing projectiles at intervals. Used to create ongoing artillery barrages or environmental hazards in levels.
Parameters:
- Vector3 pos: Target position for the repeating bombardment
- int seed: Random seed for determining bombardment timing and spread
- bool fireBallDiagonal: True to use diagonal fireball projectiles
- bool fireBallVertical: True to use vertical fireball projectiles
Returns:
-
BombardmentRepeat
: The BombardmentRepeat instance managing this repeating attack
public static void CreateAlienSpawnAttack(GridPoint targetPoint, DirectionEnum direciton, bool faceHuggers, bool melters, bool xenomorphs, bool mosquitoes, int seed, bool spawnOffScreen)
Spawns alien enemies from a specified direction attacking a target point. Handles different alien types (facehuggers, melters, xenomorphs, mosquitoes) and spawn behaviors based on direction. Can spawn enemies offscreen and set up their initial AI behaviors.
Parameters:
- GridPoint targetPoint: The grid point that spawned aliens should move toward
- DirectionEnum direciton: Direction from which aliens spawn (Up, Down, Left, Right)
- bool faceHuggers: True to spawn facehugger aliens
- bool melters: True to spawn melter/baneling aliens
- bool xenomorphs: True to spawn xenomorph aliens
- bool mosquitoes: True to spawn mosquito aliens (default if others are false)
- int seed: Random seed for spawn patterns (currently unused in implementation)
- bool spawnOffScreen: True to spawn aliens outside the visible screen area
public static Block CreateScriptedBlock(GridPoint gridPoint, GroundType groundType, bool disturbed, NID blockNID)
Creates a new block at runtime with specified properties, useful for dynamic level modifications. Can create the block in a disturbed state (falling/moving) and handles special cases like parachuting crates or cages.
Parameters:
- GridPoint gridPoint: The grid position where the block should be placed
- GroundType groundType: The type of block to create (e.g., brick, metal, cage)
- bool disturbed: Whether the block should start in a disturbed/falling state
- NID blockNID: Network ID to assign to the block for multiplayer synchronization
Returns:
-
Block
: The created Block instance
public static void CreateScriptedBombardment(Vector3 pos, bool repeat, bool fireBallDiagonal, bool fireBallVertical, int seed)
Creates a bombardment projectile attack at the specified position. Can create diagonal fireballs, vertical fireballs, or standard artillery shells. Optionally sets up repeating bombardment.
Parameters:
- Vector3 pos: Target position for the bombardment
- bool repeat: Whether this bombardment should repeat at intervals
- bool fireBallDiagonal: True to use diagonal fireball projectiles
- bool fireBallVertical: True to use vertical fireball projectiles
- int seed: Random seed for repeating bombardment patterns
Sets a block on fire at the specified location by sending a Fire damage message to the block. Used for scripted fire spreading or burning sequences in levels.
Parameters:
- Vector3 location: World position where the fire should start
Triggers a block collapse at the specified location by sending an InstaGib damage RPC to the block at that position. Used to create scripted terrain destruction sequences.
Parameters:
- Vector3 location: World position where the block collapse should occur
Creates an explosion at the specified location with customizable damage. Instantiates a HiddenExplosives prefab and immediately triggers its explosion, useful for scripted explosive sequences in levels.
Parameters:
- Vector3 location: World position where the explosion should occur
- int damage: The damage value for the explosion
Static list of active repeating bombardment patterns. Each bombardment fires projectiles at timed intervals when visible on screen. Updated in Update() to countdown and spawn projectiles with random spread.
Adds a countdown timer action to the active actions queue. Creates a system action that will start the level countdown after the specified delay.
Parameters:
- float offset: Time in seconds to wait before starting the countdown
Creates a dramatic camera sequence that starts at the nearest checkpoint then swoops to the starting position. Used for explosion run game modes to show the level before the action begins.
Creates a player introduction sequence with camera movements and UI elements. Adds multiple timed actions including camera zoom/pan to the player, player highlighting, and hero name display. Each player gets staggered timing for multiplayer intros.
Parameters:
- Player player: The player to introduce
- float timeOffset: Additional time offset to add to the introduction sequence timing
Clears all active trigger actions and releases camera control back to normal gameplay. Called when actions need to be cancelled or when transitioning between game states.
Marks all active camera movement actions as done without clearing other action types. Used when camera control needs to be returned to the player while other actions continue.
Retrieves all currently active trigger actions of a specific type. Used to query what actions are running, particularly for camera control and UI systems.
Parameters:
- TriggerActionType type: The type of trigger actions to retrieve
Returns:
-
List<TriggerAction>
: List of active actions matching the specified type, or null if no matches found
Protected method that starts a trigger action if it's in the waiting state or set to repeat. Called via RPC to ensure synchronized action execution across clients.
Parameters:
- TriggerAction action: The trigger action to start
Stops all active trigger actions with the specified name by marking them as done. Only affects actions currently in the Busy state. Used to interrupt ongoing sequences based on game events.
Parameters:
- string action: The name of the action(s) to stop
List of all currently active or pending trigger actions. Updated each frame in Update() to process waiting actions, execute busy actions, and remove completed ones. Initialized in Awake().
Retrieves the current value of a named trigger variable used for level scripting logic. Variables can track counts, states, or other numeric values that triggers can evaluate.
Parameters:
- string variableName: The name of the variable to retrieve
Returns:
-
float
: The current value of the variable, or -1 if the variable doesn't exist
Checks whether a trigger variable exists in the system. Used by triggers and actions to verify variable existence before attempting to read or modify values.
Parameters:
- string variableName: The name of the variable to check for
Returns:
-
bool
: True if the variable exists in the trigger variables dictionary
Increments a trigger variable by the specified amount, creating it if it doesn't exist. Fires the OnTriggerVariableChanged event after modification to notify listeners of the change.
Parameters:
- string variableName: The name of the variable to increment
- float amount: The amount to add to the variable's current value (can be negative)
Sets a trigger variable to a specific value, creating it if it doesn't exist. Fires the OnTriggerVariableChanged event after modification to notify listeners of the change.
Parameters:
- string variableName: The name of the variable to set
- float amount: The new value for the variable
Event delegate fired whenever a trigger variable is modified through SetVariable or IncrementVariable. Allows systems to react to variable changes for UI updates or game logic.
Gets or sets whether camera movement actions should be paused. When true, prevents camera move trigger actions from executing, allowing manual camera control during cutscenes or special sequences.
Gets or sets whether players should be destroyed when they go offscreen. When set to true, initiates a 0.1 second delay before the setting automatically reverts to false. Used for special level sequences where offscreen players should be eliminated.
Flag that temporarily blocks all unit movement when set to true. Reset to false at the start of each Update() cycle. Used by trigger actions to freeze gameplay during scripted sequences.
Countdown timer for the destroy offscreen players feature. When DestroyOffscreenPlayers is set to true, this timer counts down from 0.1 seconds before automatically disabling the feature.
Static backing field for the DestroyOffscreenPlayers property. When true, causes offscreen players to be destroyed. Automatically reverts to false after the flip delay expires.