Ejemplo n.º 1
0
        public string GetComponentName(JSONNode componentData)
        {
            string componentName = componentData["ComponentName"];

            ECSDebug.Assert(componentName != null, "Validate JSON file, might have misspelt 'ComponentName'");
            return(componentName);
        }
        public Bag <ECSComponent> ParseComponentData(JSONNode archetypeData)
        {
            Bag <ECSComponent> components         = new Bag <ECSComponent>();
            JSONNode           data               = null;
            JSONNode           componentDataArray = m_dataLocator.GetComponentData(archetypeData);
            Type componentType = null;

            for (int i = 0; i < componentDataArray.Count; i++)
            {
                data = componentDataArray[i];

                componentType = GetComponentTypeByName(m_dataLocator.GetComponentName(data));

                if (componentType == null)
                {
                    continue;
                }

                ECSComponent component = JsonUtility.FromJson(data.ToString(), componentType) as ECSComponent;
                ECSDebug.Assert(component != null, "Failed to create Component " + m_dataLocator.GetComponentName(data));

                components.Add(component);
            }

            components.ResizeToFit();

            return(components);
        }
        private Dictionary <string, Type> CacheComponentTypesFromJSON(string[] componentNames)
        {
            Dictionary <string, Type> returnedTypes = new Dictionary <string, Type>();

            foreach (string componentName in componentNames)
            {
                foreach (var pair in m_assemblyTypes)
                {
                    Type[] allTypes = pair.Value;

                    foreach (Type type in allTypes)
                    {
                        if (type.Name == componentName)
                        {
                            m_componentClasses.Add(componentName, type);
                            continue;
                        }
                    }
                }

                ECSDebug.Assert(m_componentClasses.ContainsKey(componentName), "Tried to cache type " + componentName + " but could not find it. Does it exist?");
            }

            return(returnedTypes);
        }
        public JSONNode GetArchetypeData(string v)
        {
            JSONNode data = m_dataLocator.GetEntityContainer(m_parsedJSON)[v];

            ECSDebug.Assert(data != null, "Archetype not found " + v);

            return(data);
        }
        public void Provide(string json)
        {
            m_parsedJSON = JSONNode.Parse(json);
            ECSDebug.Assert(json != "" && json != null && m_parsedJSON != null, "JSON is not Valid");

            Bag <string> componentsChecked = GetAllComponentNames(m_parsedJSON);

            CacheComponentTypesFromJSON(componentsChecked.GetAll());
        }
Ejemplo n.º 6
0
        public void InitializePendingComponents(int entityID)
        {
            Bag <ECSComponent> bag = SafeGetPendingComponentBag(entityID).Clone();

            bag.ResizeToFit();

            ECSComponent component = null;

            List <ECSComponent> toInit = new List <ECSComponent>(bag.GetAll());

            int attemptThreshold = -1;
            int START_THRESHOLD  = 1;

            if (toInit.Count > 0)
            {
                START_THRESHOLD = 10;
            }

            attemptThreshold = START_THRESHOLD;

            while (toInit.Count > 0 && attemptThreshold > 0)
            {
                for (int i = toInit.Count - 1; i >= 0; i--)
                {
                    component = toInit[i];
                    RemovePendingComponent(entityID, component);

                    if (m_componentFactory.InitializeComponent(entityID, component) == 0)
                    {
                        SafeGetComponentBag(entityID).Set(SafeGetComponentID(component.GetType()), component);
                        OnComponentAdded(entityID, component);
                        toInit.RemoveAt(i);
                        attemptThreshold = START_THRESHOLD;
                        continue;
                    }
                    else
                    {
                        AddPendingComponent(entityID, component);
                        attemptThreshold--;
                    }
                }
            }

            ECSDebug.Assert(attemptThreshold > 0, " Reached attempt threshold, maybe two components are dependent on eachother?");
        }
Ejemplo n.º 7
0
        public ECSEntity SetupEntity(ECSEntity e, string archetype)
        {
            ECSDebug.Assert(m_parser != null, "Cannot create Entity from Archetype > JSON not provided!");

            JSONNode archetypeData = m_parser.GetArchetypeData(archetype);

            string baseArchetype = m_dataLocator.GetBaseArchetype(archetypeData);

            if (baseArchetype != null)
            {
                archetypeData = m_parser.OverwriteBaseArchetypeData(m_parser.GetArchetypeData(baseArchetype).AsObject, archetypeData.AsObject);
            }

            Bag <ECSComponent> components = m_parser.ParseComponentData(archetypeData);

            ComponentPreProcessing(archetype, components);
            m_componentManager.AddComponents(e.EntityID, components);

            return(e);
        }
Ejemplo n.º 8
0
 private Bag <ECSComponent> GetComponentBag(int entityID)
 {
     ECSDebug.Assert(m_entityComponents.ContainsKey(entityID) == true, "Entity does not have a component bag! > " + entityID);
     return(m_entityComponents[entityID]);
 }
Ejemplo n.º 9
0
 public void Assert(bool condition, object v)
 {
     ECSDebug.Assert(condition, v);
 }
Ejemplo n.º 10
0
 protected void Assert(bool condition, object v)
 {
     ECSDebug.Assert(condition, SYSTEM_LOG_PREFIX + v);
 }