Esempio n. 1
0
        public T AddUnique <T>(bool useExisted = true) where T : IComponent, IUnique, new()
        {
            int componentIndex = ComponentIndex <T> .FindIn(this.contextInfo);

            Entity entity = GetSingleEntity(componentIndex);

            if (entity != null)
            {
                if (!useExisted)
                {
                    throw new EntityAlreadyHasComponentException(
                              componentIndex, "Cannot add component '" +
                              _contextInfo.componentNames[componentIndex] + "' to " + entity + "!",
                              "You should check if an entity already has the component."
                              );
                }
                return((T)ModifyUniqueComponent(componentIndex));
            }

            entity = CreateEntity(typeof(T).Name);
            T component = entity.CreateComponent <T>(componentIndex);

            entity.AddComponent(componentIndex, component);

            return(component);
        }
Esempio n. 2
0
        public T ModifyUnique <T>() where T : IComponent, IUnique
        {
            int componentIndex = ComponentIndex <T> .FindIn(this.contextInfo);

            IComponent component = ModifyUniqueComponent(componentIndex);

            if (component == null)
            {
                return(default(T));
            }

            return((T)component);
        }
Esempio n. 3
0
 /// return unique entity with specified component
 public Entity GetSingleEntity <T>() where T : IComponent, IUnique
 {
     return(GetSingleEntity(ComponentIndex <T> .FindIn(this.contextInfo)));
 }