/// <summary> /// Add a component to the pool /// </summary> /// <param name="component"></param> public void AddComponent(ComponentEcs component) { if (Application.isEditor && !Application.isPlaying) { return; } if (!_componentPools.ContainsKey(component.ComponentType)) { Debug.LogWarning($"Attempted to add unknown component type to Component Pools - {component.ComponentType}"); } else { _componentPools[component.ComponentType].Add(component); } if (_componentsById.ContainsKey(component.Id)) { if (!Application.isEditor || Application.isPlaying) { Debug.LogError("Attempted to add existing GUID"); } } else { _componentsById.Add(component.Id, component); } CurrentHash = Guid.NewGuid(); OnComponentAdded?.Invoke(component); }
public void DestroyComponent(ComponentEcs component) { component.OnDestroy(); OnComponentRemoved?.Invoke(component); _componentPools[component.ComponentType].Remove(component); _componentsById.Remove(component.Id); ComponentCache.Instance.Release(component); CurrentHash = Guid.NewGuid(); }
public void Clone(ComponentEcs jsonToCloneFrom = null) { //First we create an instance of this specific type. if (jsonToCloneFrom == null) { jsonToCloneFrom = JsonSerializer.LoadFromJson(this); } ReflectionMethods.Clone(this, jsonToCloneFrom); }
public void AddComponent(ComponentEcs component) { if (Application.isPlaying) { component.Initialise(engine, this); } _components.Add(component.ObjectType, component); if (Application.isPlaying) { engine?.AddComponent(component); } }
public void RemoveComponent(ComponentEcs component) { _components.Remove(component.ObjectType); engine.DestroyComponent(component); }
//For EntityGUICreator public void AddComponentFromGUI(ComponentEcs component) { _components.Add(component.ObjectType, component); }