Пример #1
0
        private EntityArchetype GetOrCreateArchetype(EntityManagerWrapper wrapper, Type archetypeType)
        {
            if (m_archetypes.ContainsKey(archetypeType))
            {
                return(m_archetypes[archetypeType]);
            }

            try
            {
                var instance = Activator.CreateInstance(archetypeType) as IArchetypeDescriptor;
                if (instance == null)
                {
                    throw new NotImplementedException($"Archetype descriptor {archetypeType} should implement {typeof(IArchetypeDescriptor)} interface and have an empty constructor");
                }

                var archetype = wrapper.CreateArchetype(instance.Components);
                m_archetypes[archetypeType] = archetype;
                return(archetype);
            }
            catch (Exception e)
            {
                throw new NotImplementedException($"Failed to instantiate archetype from archetype descriptor {archetypeType}", e);
            }
        }