public int AddComponent <T>(T component) where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); AddComponent(index, component); return(index); }
// // kamran : Get an index from Entitas // public int GetIndex <T>(bool useExisted = true) where T : IComponent, new() { //T component; int index = ComponentIndex <T> .FindIn(_contextInfo); return(index); }
/// replace Component with a NEW one public T ReplaceNew <T>() where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(_contextInfo); T component = CreateComponent <T>(index); ReplaceComponent(index, component); return(component); }
/// replace Component with a NEW one public static T ReplaceNewComponent <T>(this Entity entity) where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(entity.contextInfo); T component = entity.CreateComponent <T>(index); entity.ReplaceComponent(index, component); return(component); }
public void Remove <T>(bool ignoreNotFound = true) where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); if (ignoreNotFound && !HasComponent(index)) { return; } RemoveComponent(index); }
public static void RemoveComponent <T>(this Entity entity, bool ignoreNotExists = false) where T : IComponent { int index = ComponentIndex <T> .FindIn(entity.contextInfo); if (ignoreNotExists && !entity.HasComponent(index)) { return; } entity.RemoveComponent(index); }
/// add a new Component, return the old one if exists public T Add <T>(bool useExisted = true) where T : IComponent, new() { T component; int index = ComponentIndex <T> .FindIn(_contextInfo); if (useExisted && HasComponent(index)) { component = (T)GetComponent(index); FireModifiedEvent(index, component); } else { component = CreateComponent <T>(index); AddComponent(index, component); } return(component); }
/// add a new Component, return the old one if exists public static T AddComponent <T>(this Entity entity, bool keepOldIfExists = false) where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(entity.contextInfo); T component; if (keepOldIfExists && entity.HasComponent(index)) { component = (T)entity.GetComponent(index); entity.MarkUpdated(index); } else { component = entity.CreateComponent <T>(index); entity.AddComponent(index, component); } return(component); }
/// Get Component for modification, mark automatically public T Modify <T>() where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); return((T)ModifyComponent(index)); }
public T Get <T>() where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); return((T)GetComponent(index)); }
public bool Has <T>() where T : IComponent { int index = ComponentIndex <T> .FindIn(_contextInfo); return(HasComponent(index)); }
/// Mark component modified, trigger GroupEvent and ReactiveSystem public void SetModified <T>() where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(_contextInfo); SetModified(index); }
/// Mark component-updated, trigger GroupEvent and ReactiveSystem public static void MarkUpdated <T>(this Entity entity) where T : IComponent, new() { int index = ComponentIndex <T> .FindIn(entity.contextInfo); entity.MarkUpdated(index); }
/// shorter version of GetComponent<T> public static T Get <T>(this Entity entity) where T : IComponent { int index = ComponentIndex <T> .FindIn(entity.contextInfo); return((T)entity.GetComponent(index)); }
public static bool HasComponent <T>(this Entity entity) where T : IComponent { int index = ComponentIndex <T> .FindIn(entity.contextInfo); return(entity.HasComponent(index)); }