Esempio n. 1
0
        private void deleteComponent(ECSBaseComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException("component");
            }
            ECSEntity entity               = component.Entity;
            int       entityId             = entity.Id;
            var       componentsOfSameType = this.getComponentsOfType(component.GetType());
            int       index = componentsOfSameType.LinearSearchNullSafe
                              (
                delegate(object element)
            {
                return(((ECSBaseComponent)element).Entity.Id - entityId);
            }
                              );

            // Debug.LogFormat ("DELETE {0}: {1}", component.GetType().Name, debugComponentArrayToString (componentsOfSameType));

            if (index < 0)
            {
                Debug.LogErrorFormat("Entity component of type {0} wasn't found for entity {1}", component.GetType().Name, component.Entity.Id);
                return;
            }
            if (!object.ReferenceEquals(entity, ((ECSBaseComponent)componentsOfSameType[index]).Entity))
            {
                throw new InvalidOperationException("Internal Error: component-entity pairing is messed up");
            }
            if (!object.ReferenceEquals(component, componentsOfSameType[index]))
            {
                throw new InvalidOperationException("Component found was not the component in the record; are you adding dupliates?");
            }
            componentsOfSameType[index] = null;
            _anyComponentsWereRemoved   = true;
        }
Esempio n. 2
0
        private void insertComponent(ECSBaseComponent component)
        {
            if (_anyComponentsWereRemoved)
            {
                this.removeNullsFromComponentsLists();
            }
            var componentsOfSameType = this.getComponentsOfType(component.GetType());

            componentsOfSameType.BinaryInsert(component);

            // Debug.LogFormat ("INSERT {0} #{2}: {1}", component.GetType().Name, debugComponentArrayToString (componentsOfSameType), component.Entity.Id);
        }
Esempio n. 3
0
        public void ReleaseComponent(ECSBaseComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException();
            }
            var releaseMethod = component.GetType().GetMethod("Release", Type.EmptyTypes);

            if (releaseMethod != null)
            {
                releaseMethod.Invoke(component, null);
            }
            this.deleteComponent(component);
            GameObject.Destroy(component);
            this.debugAssertInvariants();
        }
Esempio n. 4
0
 public void ReleaseComponent(ECSBaseComponent component)
 {
     this.Controller.ReleaseComponent(component);
 }