コード例 #1
0
        public void SetState(Entity entity, string stateName)
        {
            List <string> newState = this.States[stateName];

            if (this.CurrentState == newState)
            {
                return;
            }

            foreach (string componentName in this.CurrentState)
            {
                if (newState.IndexOf(componentName) == -1)
                {
                    entity.RemoveComponent(ComponentTypeManager.GetTypeFor(this.Components[componentName].GetType()));
                }
            }

            foreach (string componentName in newState)
            {
                if (this.CurrentState.IndexOf(componentName) == -1)
                {
                    entity.AddComponent(this.Components[componentName]);
                }
            }

            this.CurrentState = newState;
        }
コード例 #2
0
 /// <summary>Initializes a new instance of the <see cref="HybridQueueSystemProcessing" /> class.</summary>
 /// <param name="requiredType">Type of the required.</param>
 /// <param name="otherTypes">The other types.</param>
 protected HybridQueueSystemProcessing(Type requiredType, params Type[] otherTypes)
     : base(requiredType, otherTypes)
 {
     this.queue     = new Queue <Entity>();
     this.compTypes = new List <ComponentType>();
     foreach (Type type in this.Types)
     {
         this.compTypes.Add(ComponentTypeManager.GetTypeFor(type));
     }
 }
コード例 #3
0
        /// <summary>
        /// Creates a new EntitySystem instance associated with the provided types.
        /// </summary>
        /// <param name="types">Types to associate with the EntitySystem.</param>
        public EntitySystem(params Type[] types)
            : this()
        {
            int typeCount = types.Length;

            for (int i = 0; i < typeCount; ++i)
            {
                Type          type          = types[i];
                ComponentType componentType = ComponentTypeManager.GetTypeFor(type);
                _typeFlags |= componentType.Bit;
            }
        }
コード例 #4
0
 /// <summary>
 /// Creates a new ComponentMapper instance associated with the specified entity world.
 /// </summary>
 /// <param name="world">Entity world instance to associate with.</param>
 public ComponentMapper(IEntityWorld world)
 {
     _world         = world;
     _componentType = ComponentTypeManager.GetTypeFor <T>();
 }
コード例 #5
0
 /// <summary>
 /// Gets a component of type T associated with the Entity.
 /// </summary>
 /// <typeparam name="T"><see cref="IComponent"/> type to get for the Entity.</typeparam>
 /// <returns>>An <see cref="IComponent"/> instance of the specified type if one is associated with the Entity, or null if not.</returns>
 public T GetComponent <T>() where T : IComponent
 {
     return((T)GetComponent(ComponentTypeManager.GetTypeFor <T>()));
 }