feat: IBehaviourController.GetBehaviours(List)

This commit is contained in:
Syntriax 2024-01-30 12:31:51 +03:00
parent 1438b19e35
commit 514e5b5762
2 changed files with 16 additions and 0 deletions

View File

@ -65,6 +65,10 @@ public interface IBehaviourController : IAssignableGameObject
/// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
IList<T> GetBehaviours<T>();
/// <typeparam name="T">An implemented class or <see cref="interface"/>.</typeparam>
/// <returns>Fills the provided list parameter all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
void GetBehaviours<T>(List<T> behaviours);
/// <summary>
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
/// </summary>

View File

@ -70,6 +70,18 @@ public class BehaviourController : IBehaviourController
return behaviours ?? Enumerable.Empty<T>().ToList();
}
public void GetBehaviours<T>(List<T> behaviors)
{
behaviors.Clear();
foreach (var behaviourItem in behaviours)
{
if (behaviourItem is not T _)
continue;
behaviours.Add(behaviourItem);
}
}
public void RemoveBehaviour<T>(bool removeAll = false) where T : class, IBehaviour
{
for (int i = behaviours.Count; i >= 0; i--)