public EntityArchetype CreateArchetype(params Type[] types) { List <ComponentType> componentTypes = new List <ComponentType>(); foreach (var t in types) { if (!t.GetInterfaces().Contains(typeof(IComponent))) { throw new ArgumentException("Type does not implement IComponent."); } var idx = -1; if (_componentTypes.Contains(t)) { idx = _componentTypes.IndexOf(t); } else { _componentTypes.Add(t); idx = _componentTypes.Count - 1; } componentTypes.Add(idx); } componentTypes.Sort(); var componentTypeList = new ComponentTypeList { TypeList = componentTypes.Distinct().ToList() }; if (_entityArchetypes.Contains(componentTypeList)) { return(_entityArchetypes.IndexOf(componentTypeList)); } else { _entityArchetypes.Add(componentTypeList); return(_entityArchetypes.Count - 1); } }
public bool HasArchetype(ComponentTypeList t) { return(_entityArchetypes.Contains(t)); }
public int GetArchetypeIndex(ComponentTypeList t) { return(_entityArchetypes.IndexOf(t)); }