feat: IBehaviourController.GetBehaviours(List)
This commit is contained in:
parent
1438b19e35
commit
514e5b5762
|
@ -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>
|
/// <returns>Returns a list of all the matching <see cref="IBehaviour"/>s found in the <see cref="IBehaviourController"/>.</returns>
|
||||||
IList<T> GetBehaviours<T>();
|
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>
|
/// <summary>
|
||||||
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
|
/// Removes the <see cref="IBehaviour"/> found in the <see cref="IBehaviourController"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -70,6 +70,18 @@ public class BehaviourController : IBehaviourController
|
||||||
return behaviours ?? Enumerable.Empty<T>().ToList();
|
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
|
public void RemoveBehaviour<T>(bool removeAll = false) where T : class, IBehaviour
|
||||||
{
|
{
|
||||||
for (int i = behaviours.Count; i >= 0; i--)
|
for (int i = behaviours.Count; i >= 0; i--)
|
||||||
|
|
Loading…
Reference in New Issue