예제 #1
0
        /// <summary>
        /// Adds a component to the entity.
        /// </summary>
        /// <param name="component">Component which is to be added to the entity.</param>
        public void AddComponent(IEntityComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("Entity.AddComponent(): null component.");
            }

            if (mComponents.Find(c => c == component) != null)
            {
                throw new ArgumentException("Entity.AddComponent(): duplicate component.");
            }

            component.Owner = this;
            mComponents.Add(component);

            component.OnAdd();
            ResetComponents();

            if (ComponentAdded != null)
            {
                ComponentAdded(this, component);
            }
        }