From 981db0190fa2aa2e712513c0e6bcac969a19d23e Mon Sep 17 00:00:00 2001 From: Syntriax Date: Sat, 23 Nov 2024 22:25:45 +0300 Subject: [PATCH] feat: GetOrAddBehaviour Extension for IBehaviourController --- Engine.Core/Extensions/BehaviourControllerExtensions.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Engine.Core/Extensions/BehaviourControllerExtensions.cs b/Engine.Core/Extensions/BehaviourControllerExtensions.cs index 01a0c5d..5665307 100644 --- a/Engine.Core/Extensions/BehaviourControllerExtensions.cs +++ b/Engine.Core/Extensions/BehaviourControllerExtensions.cs @@ -6,6 +6,9 @@ namespace Syntriax.Engine.Core; public static class BehaviourControllerExtensions { + public static T GetOrAddBehaviour(this IBehaviourController behaviourController, params object?[]? args) where T : class, IBehaviour + => behaviourController.GetBehaviour() ?? behaviourController.AddBehaviour(args); + public static bool TryGetBehaviourInParent(this IBehaviourController behaviourController, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class { behaviour = GetBehaviourInParent(behaviourController);