feat: IBehaviourController.GetBehaviour
This commit is contained in:
@@ -41,19 +41,19 @@ public class BehaviourController : IBehaviourController
|
||||
public T AddBehaviour<T>(params object?[]? args) where T : class, IBehaviour
|
||||
=> AddBehaviour(new Factory.BehaviourFactory().Instantiate<T>(_gameObject, args));
|
||||
|
||||
public bool TryGetBehaviour<T>([NotNullWhen(returnValue: true)] out T? behaviour)
|
||||
public T? GetBehaviour<T>()
|
||||
{
|
||||
foreach (var behaviourItem in behaviours)
|
||||
{
|
||||
if (behaviourItem is not T result)
|
||||
continue;
|
||||
if (behaviourItem is T result)
|
||||
return result;
|
||||
|
||||
behaviour = result;
|
||||
return true;
|
||||
}
|
||||
return default;
|
||||
}
|
||||
|
||||
behaviour = default;
|
||||
return false;
|
||||
public bool TryGetBehaviour<T>([NotNullWhen(returnValue: true)] out T? behaviour)
|
||||
{
|
||||
behaviour = GetBehaviour<T>();
|
||||
return behaviour is not null;
|
||||
}
|
||||
|
||||
public IList<T> GetBehaviours<T>()
|
||||
|
Reference in New Issue
Block a user