diff --git a/Engine.Core/Extensions/BehaviourControllerExtensions.cs b/Engine.Core/Extensions/BehaviourControllerExtensions.cs index 6778065..3f71685 100644 --- a/Engine.Core/Extensions/BehaviourControllerExtensions.cs +++ b/Engine.Core/Extensions/BehaviourControllerExtensions.cs @@ -39,6 +39,19 @@ public static class BehaviourControllerExtensions public static T GetOrAddBehaviour(this IBehaviourController behaviourController, params object?[]? args) where T : class, IBehaviour => behaviourController.GetBehaviour() ?? behaviourController.AddBehaviour(args); + /// + /// Gets an existing of the specified type, or adds and returns the fallback type if it doesn't exist. + /// + /// The type of to get. + /// The type of to add. It must be assignable from + /// The to search in. + /// Optional arguments to pass to the constructor of the if a new one is added. + /// The existing or newly added of the specified type. + public static TOriginal GetOrAddBehaviour(this IBehaviourController behaviourController, params object?[]? args) + where TOriginal : class + where TFallback : class, IBehaviour, TOriginal + => behaviourController.GetBehaviour() ?? behaviourController.AddBehaviour(args); + /// /// Tries to get a of the specified type in it's 's parents recursively. ///