31 lines
734 B
C#
31 lines
734 B
C#
using System;
|
|
|
|
using Syntriax.Engine.Core.Abstract;
|
|
|
|
namespace Syntriax.Engine.Core;
|
|
|
|
public class BehaviourCollectorSorted<T> : BehaviourCollector<T> where T : class
|
|
{
|
|
private Comparison<T>? _sortBy = null;
|
|
public Comparison<T>? SortBy
|
|
{
|
|
get => _sortBy;
|
|
set
|
|
{
|
|
_sortBy = value;
|
|
|
|
if (value is not null)
|
|
behaviours.Sort(value);
|
|
}
|
|
}
|
|
|
|
protected override void OnBehaviourAdd(IBehaviour behaviour)
|
|
{
|
|
if (SortBy is not null)
|
|
behaviours.Sort(SortBy);
|
|
}
|
|
|
|
public BehaviourCollectorSorted() { }
|
|
public BehaviourCollectorSorted(IGameManager gameManager, Comparison<T> sortBy) : base(gameManager) => SortBy = sortBy;
|
|
}
|