1
This commit is contained in:
@@ -53,8 +53,13 @@ namespace BITKit.Entities
|
||||
public int HealthPoint
|
||||
{
|
||||
get => healthPoint;
|
||||
set => OnHealthPointChangedInternal(healthPoint, value);
|
||||
set
|
||||
{
|
||||
if(value == healthPoint)return;
|
||||
OnHealthPointChangedInternal(healthPoint, value);
|
||||
}
|
||||
}
|
||||
|
||||
public int MaxHealthPoint
|
||||
{
|
||||
get => maxHealthPoint;
|
||||
|
@@ -26,6 +26,18 @@ namespace BITKit.Entities
|
||||
}
|
||||
public CancellationToken CancellationToken { get; private set; }
|
||||
public IEntityBehavior[] Behaviors { get;private set; }
|
||||
public bool TryGetComponent(Type type, out IEntityComponent component)
|
||||
{
|
||||
var value = genericEvent.Get(type.FullName);
|
||||
if (value is not null)
|
||||
{
|
||||
component = (IEntityComponent)value;
|
||||
return true;
|
||||
}
|
||||
component = default!;
|
||||
return false;
|
||||
}
|
||||
|
||||
public IEntityComponent[] Components => Behaviors.Cast<IEntityComponent>().ToArray();
|
||||
private bool _initialized;
|
||||
bool Entities.IEntity.RegisterComponent<T>(T component)
|
||||
|
@@ -63,6 +63,31 @@ public class UnityEntitiesServiceSingleton:IEntitiesService
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2>();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3)[] QueryComponents<T, T1, T2, T3>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2, T3>();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4)[] QueryComponents<T, T1, T2, T3, T4>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2, T3, T4>();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4, T5)[] QueryComponents<T, T1, T2, T3, T4, T5>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2, T3, T4, T5>();
|
||||
}
|
||||
|
||||
public (T, T1, T2, T3, T4, T5, T6)[] QueryComponents<T, T1, T2, T3, T4, T5, T6>()
|
||||
{
|
||||
return UnityEntitiesService.QueryComponents<T, T1, T2, T3, T4, T5, T6>();
|
||||
}
|
||||
|
||||
public ValueTuple<T, T1, T2, T3, T4, T5, T6, TRest>[] QueryComponents<T, T1, T2, T3, T4, T5, T6, TRest>() where TRest : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
|
||||
public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
@@ -198,4 +223,81 @@ public class UnityEntitiesService : MonoBehaviour,IEntitiesService
|
||||
ListPool<(T t, T1 t1, T2 t2)>.Release(list);
|
||||
return value;
|
||||
}
|
||||
(T, T1, T2, T3)[] IEntitiesService.QueryComponents<T, T1, T2, T3>() => QueryComponents<T, T1, T2, T3>();
|
||||
public static (T, T1, T2, T3)[] QueryComponents<T, T1, T2, T3>()
|
||||
{
|
||||
var list = ListPool<(T, T1, T2, T3)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
{
|
||||
switch (iEntity as Entity)
|
||||
{
|
||||
case var x when x != null && x.TryGetComponentAny<T>(out var t) && x.TryGetComponentAny<T1>(out var t1) && x.TryGetComponentAny<T2>(out var t2) && x.TryGetComponentAny<T3>(out var t3):
|
||||
list.Add((t, t1, t2, t3));
|
||||
break;
|
||||
}
|
||||
}
|
||||
var value = list.ToArray();
|
||||
list.Clear();
|
||||
ListPool<(T, T1, T2, T3)>.Release(list);
|
||||
return value;
|
||||
}
|
||||
(T, T1, T2, T3, T4)[] IEntitiesService.QueryComponents<T, T1, T2, T3, T4>() => QueryComponents<T, T1, T2, T3, T4>();
|
||||
public static (T, T1, T2, T3, T4)[] QueryComponents<T, T1, T2, T3, T4>()
|
||||
{
|
||||
var list = ListPool<(T, T1, T2, T3, T4)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
{
|
||||
switch (iEntity as Entity)
|
||||
{
|
||||
case var x when x != null && x.TryGetComponentAny<T>(out var t) && x.TryGetComponentAny<T1>(out var t1) && x.TryGetComponentAny<T2>(out var t2) && x.TryGetComponentAny<T3>(out var t3) && x.TryGetComponentAny<T4>(out var t4):
|
||||
list.Add((t, t1, t2, t3, t4));
|
||||
break;
|
||||
}
|
||||
}
|
||||
var value = list.ToArray();
|
||||
list.Clear();
|
||||
ListPool<(T, T1, T2, T3, T4)>.Release(list);
|
||||
return value;
|
||||
}
|
||||
(T, T1, T2, T3, T4, T5)[] IEntitiesService.QueryComponents<T, T1, T2, T3, T4, T5>() => QueryComponents<T, T1, T2, T3, T4, T5>();
|
||||
public static (T, T1, T2, T3, T4, T5)[] QueryComponents<T, T1, T2, T3, T4, T5>()
|
||||
{
|
||||
var list = ListPool<(T, T1, T2, T3, T4, T5)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
{
|
||||
switch (iEntity as Entity)
|
||||
{
|
||||
case var x when x != null && x.TryGetComponentAny<T>(out var t) && x.TryGetComponentAny<T1>(out var t1) && x.TryGetComponentAny<T2>(out var t2) && x.TryGetComponentAny<T3>(out var t3) && x.TryGetComponentAny<T4>(out var t4) && x.TryGetComponentAny<T5>(out var t5):
|
||||
list.Add((t, t1, t2, t3, t4, t5));
|
||||
break;
|
||||
}
|
||||
}
|
||||
var value = list.ToArray();
|
||||
list.Clear();
|
||||
ListPool<(T, T1, T2, T3, T4, T5)>.Release(list);
|
||||
return value;
|
||||
}
|
||||
(T, T1, T2, T3, T4, T5, T6)[] IEntitiesService.QueryComponents<T, T1, T2, T3, T4, T5, T6>() => QueryComponents<T, T1, T2, T3, T4, T5, T6>();
|
||||
public ValueTuple<T, T1, T2, T3, T4, T5, T6, TRest>[] QueryComponents<T, T1, T2, T3, T4, T5, T6, TRest>() where TRest : struct
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public static (T, T1, T2, T3, T4, T5, T6)[] QueryComponents<T, T1, T2, T3, T4, T5, T6>()
|
||||
{
|
||||
var list = ListPool<(T, T1, T2, T3, T4, T5, T6)>.Get();
|
||||
foreach (var iEntity in Entities)
|
||||
{
|
||||
switch (iEntity as Entity)
|
||||
{
|
||||
case var x when x != null && x.TryGetComponentAny<T>(out var t) && x.TryGetComponentAny<T1>(out var t1) && x.TryGetComponentAny<T2>(out var t2) && x.TryGetComponentAny<T3>(out var t3) && x.TryGetComponentAny<T4>(out var t4) && x.TryGetComponentAny<T5>(out var t5) && x.TryGetComponentAny<T6>(out var t6):
|
||||
list.Add((t, t1, t2, t3, t4, t5, t6));
|
||||
break;
|
||||
}
|
||||
}
|
||||
var value = list.ToArray();
|
||||
list.Clear();
|
||||
ListPool<(T, T1, T2, T3, T4, T5, T6)>.Release(list);
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user