BaseRespawnCondition - jimdroberts/FishMMO GitHub Wiki
BaseRespawnCondition is an abstract MonoBehaviour for FishMMO that defines the contract for respawn conditions. It is used to determine if an object spawner is allowed to respawn entities based on custom logic, enabling extensible and modular respawn rules for different gameplay scenarios.
-
public abstract bool OnCheckCondition(ObjectSpawner spawner)
Checks whether the respawn condition is met for the given object spawner. Must be implemented by derived classes. Parameters: - ObjectSpawner spawner: The object spawner requesting the condition check. Returns: bool. True if respawn is allowed, false otherwise. No exceptions are thrown by default, but implementations may throw as needed.
- Create a new class that derives from BaseRespawnCondition and implement the OnCheckCondition method.
- Attach the derived component to a GameObject with an ObjectSpawner.
- Use the custom respawn condition to control when entities are allowed to respawn.
// Example 1: Creating a custom respawn condition
public class CustomRespawnCondition : BaseRespawnCondition
{
public override bool OnCheckCondition(ObjectSpawner spawner)
{
// Custom logic for respawn condition
return true;
}
}
// Example 2: Using a respawn condition in code
bool canRespawn = customRespawnCondition.OnCheckCondition(spawner);
- Always implement the OnCheckCondition method with clear, concise logic for the intended respawn rule.
- Use derived classes to encapsulate specific respawn conditions for modularity and maintainability.
- Document the purpose and usage of each custom respawn condition for future reference.