Method IfMatchesExecute
- Namespace
- Gamelogic.Extensions
- Assembly
- Gamelogic.Extensions.dll
IfMatchesExecute(LifeCycleEvent, LifeCycleEvent, Action)
Executes an action if the current event matches a given event.
public static void IfMatchesExecute(this LifeCycleEvent eventToMatch, LifeCycleEvent currentEvent, Action action)
Parameters
eventToMatch
LifeCycleEventThe event to match.
currentEvent
LifeCycleEventThe current event.
action
ActionThe action to execute.
Examples
In this example, the designer can configure in the inspector when to restart the game.
public class LifeCycleExample : MonoBehaviour
{
[SerializeField] private LifeCycleEvent whenToRestart = LifeCycleEvent.None;
public void Awake() => whenToRestart.IfMatchesExecute(LifeCycleEvent.Awake, RestartGame);
public void OnEnable() => whenToRestart.IfMatchesExecute(LifeCycleEvent.OnEnable, RestartGame);
public void Start() => whenToRestart.IfMatchesExecute(LifeCycleEvent.Start, RestartGame);
public void RestartGame() => Debug.Log("Game restarted!");
}