using System; using Svelto.DataStructures; using Svelto.ECS.Internal; namespace Svelto.ECS { public interface INodeBuilder { INode BuildNodeAndAddToList(ref ITypeSafeList list, int entityID); Type GetNodeType(); } public class NodeBuilder : INodeBuilder where NodeType : NodeWithID, new() { public INode BuildNodeAndAddToList(ref ITypeSafeList list, int entityID) { if (list == null) list = new TypeSafeFasterListForECSForClasses(); var castedList = list as TypeSafeFasterListForECSForClasses; var node = NodeWithID.BuildNode(entityID); castedList.Add(node); return node; } public Type GetNodeType() { return typeof(NodeType); } } public class StructNodeBuilder : INodeBuilder where NodeType : struct, IStructNodeWithID { public INode BuildNodeAndAddToList(ref ITypeSafeList list, int entityID) { var node = default(NodeType); node.ID = entityID; if (list == null) list = new TypeSafeFasterListForECSForStructs(); var castedList = list as TypeSafeFasterListForECSForStructs; castedList.Add(node); return null; } public Type GetNodeType() { return typeof(NodeType); } } }