Exemplo n.º 1
0
        /// <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);
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public void AddComponent(ComponentEcs component)
        {
            if (Application.isPlaying)
            {
                component.Initialise(engine, this);
            }

            _components.Add(component.ObjectType, component);
            if (Application.isPlaying)
            {
                engine?.AddComponent(component);
            }
        }
Exemplo n.º 5
0
 public void RemoveComponent(ComponentEcs component)
 {
     _components.Remove(component.ObjectType);
     engine.DestroyComponent(component);
 }
Exemplo n.º 6
0
 //For EntityGUICreator
 public void AddComponentFromGUI(ComponentEcs component)
 {
     _components.Add(component.ObjectType, component);
 }