예제 #1
0
        /// <summary>
        /// Creates empty entity with default transform Component
        /// </summary>
        /// <returns></returns>
        public Entity CreateEntity()
        {
            if (IsDrawing)
            {
                throw new EcsWorkflowException("Cannot create entity during Draw phase");
            }

            Entity entity = new Entity(this);

            if (_freeIds.Count != 0)
            {
                entity.Id = _freeIds.Dequeue();
            }
            else
            {
                entity.Id = ++_maxId;
            }

            Transform2DComponent transform = (Transform2DComponent)AddComponent(entity, typeof(Transform2DComponent));

            entity.Transform = transform;

            Tree.AddEntity(entity);

            _entitiesForAdding.Enqueue(entity);

            return(entity);
        }
예제 #2
0
        internal Component GetComponentInParent(Entity entity, Type componentType)
        {
            Transform2DComponent transform = entity.Transform;

            while (transform != null)
            {
                var component = GetComponent(transform.Entity, componentType);

                if (component != null)
                {
                    return(component);
                }

                transform = transform.Parent;
            }

            return(null);
        }
예제 #3
0
        internal IEnumerable <Component> GetComponentsInParent(Entity entity, Type componentType)
        {
            Transform2DComponent transform = entity.Transform;
            List <Component>     result    = new List <Component>();

            while (transform != null)
            {
                var component = GetComponent(transform.Entity, componentType);

                if (component != null)
                {
                    result.Add(component);
                }

                transform = transform.Parent;
            }

            return(result);
        }