Esempio n. 1
0
        /*
         * @brief 新增組件
         * @param id [in] 組件編號
         */
        public void AddComponent(int id, IComponent component)
        {
            if (IsEnabled == false)
            {
                throw new Exception($"can't add component: {GetComponentName(id)} to entity: {this}, entity doesn't enabled");
            }

            if (HasComponent(id))
            {
                throw new Exception($"can't add component: {GetComponentName(id)} to entity: {this}, component repeat");
            }

            componentsCache = null;
            toStrCache      = string.Empty;

            components[id]      = component;
            componentsFlags[id] = true;

            OnComponentAdd?.Invoke(this, id, component);
        }
Esempio n. 2
0
 /// <summary>
 /// Adds a component to the entity
 /// </summary>
 /// <param name="componentType">The type of component</param>
 /// <param name="name">The name to call the component</param>
 public void AddComponent(Type componentType, string name)
 {
     OnComponentAdd?.Invoke(componentType, name);
 }