Пример #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LudumEngine.Entity"/> class from a
        /// entity blueprint and assigns it to a scene.
        /// </summary>
        /// <param name="blueprint">A blueprint to instantiate from.</param>
        /// <param name="scene">A scene to add the entity to.</param>
        internal Entity(EntityBlueprint blueprint, Scene scene)
        {
            this.Scene = scene;

            _componentCollection = new ComponentCollection(blueprint.ComponentCollection);

            foreach (Component component in _componentCollection.GetAllComponents())
            {
                component.Entity = this;
                component.Reset();
                component.Initialize();
            }
        }
Пример #2
0
        /// <summary>
        /// Delete all components in this entity.
        /// </summary>
        public void Delete()
        {
            // Get all current components
            var allComponents = _componentCollection.GetAllComponents();

            // Remove all component references
            _componentCollection = new ComponentCollection();

            // Make sure all components destroy themselfs
            foreach (Component component in allComponents)
            {
                component.Delete();
            }
        }