feat: GetOrAddBehaviour Extension for IBehaviourController

This commit is contained in:
Syntriax 2024-11-23 22:25:45 +03:00
parent c0c48c7d51
commit 981db0190f
1 changed files with 3 additions and 0 deletions

View File

@ -6,6 +6,9 @@ namespace Syntriax.Engine.Core;
public static class BehaviourControllerExtensions
{
public static T GetOrAddBehaviour<T>(this IBehaviourController behaviourController, params object?[]? args) where T : class, IBehaviour
=> behaviourController.GetBehaviour<T>() ?? behaviourController.AddBehaviour<T>(args);
public static bool TryGetBehaviourInParent<T>(this IBehaviourController behaviourController, [NotNullWhen(returnValue: true)] out T? behaviour) where T : class
{
behaviour = GetBehaviourInParent<T>(behaviourController);