/* * @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); }
/// <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); }