コード例 #1
0
ファイル: Entity.cs プロジェクト: zh880517/FantasyStriker
        private void replaceComponent(int index, IComponent replacement)
        {
            // TODO VD PERFORMANCE
            // _toStringCache = null;

            var previousComponent = _components[index];

            if (replacement != previousComponent)
            {
                _components[index] = replacement;
                _componentsCache   = null;
                if (replacement != null)
                {
                    OnComponentReplaced?.Invoke(this, index, previousComponent, replacement);
                }
                else
                {
                    _componentIndicesCache = null;

                    // TODO VD PERFORMANCE
                    _toStringCache = null;

                    OnComponentRemoved?.Invoke(this, index, previousComponent);
                }

                GetComponentPool(index).Push(previousComponent);
            }
            else
            {
                OnComponentReplaced?.Invoke(this, index, previousComponent, replacement);
            }
        }
コード例 #2
0
ファイル: EcsWorld.cs プロジェクト: alexsaye/EcsCore
        public TComponent RemoveComponent <TComponent>(int entity, TComponent component) where TComponent : IEcsComponent
        {
            Type          type             = component.GetType();
            var           componentsOfType = components[type];
            IEcsComponent existingComponent;

            if (componentsOfType.TryGetValue(entity, out existingComponent))
            {
                if (existingComponent.Equals(component))
                {
                    componentsOfType.Remove(entity);
                    Console.WriteLine("Removed " + type + " from " + entity);
                    OnComponentRemoved?.Invoke(entity, component);
                    return(component);
                }
                else
                {
                    throw new ExistingComponentException(entity + " has a different " + component.GetType() + " component");
                }
            }
            else
            {
                throw new MissingComponentException(entity + " does not have a " + component.GetType() + " component");
            }
        }
コード例 #3
0
 public void RemoveComponent <TComponent>(TComponent component) where TComponent : class, IComponent, new()
 {
     if (componentsMap.Remove(component.GetType()))
     {
         context.RecycleComponent(component);
         OnComponentRemoved?.Invoke(this, component);
     }
 }
コード例 #4
0
ファイル: ParcelScene.cs プロジェクト: useit015/explorer
 public void SharedComponentDispose(string id)
 {
     if (disposableComponents.TryGetValue(id, out ISharedComponent sharedComponent))
     {
         sharedComponent?.Dispose();
         disposableComponents.Remove(id);
         OnComponentRemoved?.Invoke(sharedComponent);
     }
 }
コード例 #5
0
 internal void RemoveAllComponents()
 {
     foreach (var comp in componentsMap)
     {
         context.RecycleComponent(comp.Value);
         OnComponentRemoved?.Invoke(this, comp.Value);
     }
     componentsMap.Clear();
 }
コード例 #6
0
        public void RemoveComponent(ECSComponent component)
        {
            bool removed = components.Remove(component);

            if (removed)
            {
                OnComponentRemoved?.Invoke(component);
            }
        }
コード例 #7
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();
        }
コード例 #8
0
        public void Remove <T>() where T : class
        {
            for (int i = list.Count - 1; i >= 0; --i)
            {
                if (i >= list.Count)
                {
                    continue;
                }

                Component component = list[i];
                if (component is T)
                {
                    list.RemoveAt(i);
                    OnComponentRemoved?.Invoke(gameObject, component);
                }
            }
        }
コード例 #9
0
ファイル: EcsWorld.cs プロジェクト: alexsaye/EcsCore
        public TComponent RemoveComponent <TComponent>(int entity) where TComponent : IEcsComponent
        {
            var           type             = typeof(TComponent);
            var           componentsOfType = components[type];
            IEcsComponent component;

            if (componentsOfType.TryGetValue(entity, out component))
            {
                componentsOfType.Remove(entity);
                Console.WriteLine("Removed " + type + " from " + entity);
                OnComponentRemoved?.Invoke(entity, component);
                return((TComponent)component);
            }
            else
            {
                throw new MissingComponentException(entity + " does not have a " + typeof(TComponent) + " component");
            }
        }
コード例 #10
0
        private Entity <T> ReplaceInstance(Type type, T component)
        {
            if (!_isEnabled)
            {
                throw new EntityIsNotEnabledException <T>("Cannot replace component '" + component + "' on " + this + "!");
            }

            if (Has(type))
            {
                var previousComponent = _components[type];
                if (component != previousComponent)
                {
                    _components[type] = component;
                    _componentsCache  = null;
                    if (component != null)
                    {
                        OnComponentReplaced?.Invoke(this, type, previousComponent, component);
                    }
                    else
                    {
                        _componentTypesCache = null;
                        OnComponentRemoved?.Invoke(this, type, previousComponent);
                    }

                    GetComponentPool(type).Push(previousComponent);
                }
                else
                {
                    OnComponentReplaced?.Invoke(this, type, previousComponent, component);
                }
            }
            else if (component != null)
            {
                AddInstance(component);
            }

            return(this);
        }
コード例 #11
0
ファイル: Manager.cs プロジェクト: tstavrianos/TS.ECS
        /// <summary>
        /// Unlink the entity and component
        /// </summary>
        /// <typeparam name="E">type extending Entity</typeparam>
        /// <typeparam name="C">type implementing IComponent</typeparam>
        /// <param name="entity">The entity that the component will be removed from</param>
        /// <param name="component">The component being removed</param>
        public void RemoveComponent <E, C>(E entity, C component) where E : Entity where C : IComponent
        {
            if (entity.Parent.Id != Id)
            {
                throw new ArgumentException(nameof(entity));
            }
            if (entity == null)
            {
                throw new ArgumentNullException(nameof(entity));
            }
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }

            if (entityComponentMap.ContainsKey(entity.Id))
            {
                if (entityComponentMap[entity.Id].Item2.Contains(component))
                {
                    entityComponentMap[entity.Id].Item2.Remove(component);
                    OnComponentRemoved?.Invoke(this, new ComponentRemovedEventArgs(entity, component));
                }
            }
        }
コード例 #12
0
 internal void OnComponentRemovedInternal(BaseComponent component)
 {
     ComponentRemoved(component.SourceEntity, component);
     OnComponentRemoved?.Invoke(component.SourceEntity, component);
 }
コード例 #13
0
ファイル: Manager.cs プロジェクト: Rahil627/Rise
 internal void ComponentRemoved(Component component)
 {
     OnComponentRemoved?.Invoke(component);
 }
コード例 #14
0
 public void RemoveComponent(IPlayerComponent i_ComponentToRemove)
 {
     m_PlayListComponents.Remove(i_ComponentToRemove);
     OnComponentRemoved.Invoke(i_ComponentToRemove);
 }
コード例 #15
0
 private void RemoveRecycleComponent(IComponent component)
 {
     _components.Remove(component.GetType());
     OnComponentRemoved?.Invoke(this, component);
     _componentFactory.Recycle(component);
 }