Exemple #1
0
        public void SetOrAddComponent <TComponent>(Entity entity, TComponent component) where TComponent : struct
        {
            Debug.Assert(IsValid(entity));
            ComponentSet <TComponent> componentSet = GetComponentSet <TComponent>();

            componentSet.AddOrReplace(component, entity.Index);
        }
Exemple #2
0
            public EntitySliceConfiguration Exclude <TComponent>() where TComponent : struct
            {
                ComponentSet <TComponent> componentSet = mRegistry.GetComponentSet <TComponent>();

                mExclusions.Add(componentSet);
                return(this);
            }
Exemple #3
0
            public EntitySliceConfiguration Require <TComponent>() where TComponent : struct
            {
                ComponentSet <TComponent> componentSet = mRegistry.GetComponentSet <TComponent>();

                mLooseRequirements.Add(componentSet);
                return(this);
            }
Exemple #4
0
        public TComponent GetComponent <TComponent>(Entity entity) where TComponent : struct
        {
            Debug.Assert(IsValid(entity));
            ComponentSet <TComponent> componentSet = GetComponentSet <TComponent>();

            return(componentSet.GetValue(entity.Index));
        }
Exemple #5
0
        private void ValidateOrRegisterComponentType <TComponent>() where TComponent : struct
        {
            Type componentType = typeof(TComponent);

            if (!mComponentSetLookup.ContainsKey(componentType))
            {
                ComponentSet <TComponent> componentSet = new ComponentSet <TComponent>(mEntities.Length);
                ushort lookup = (ushort)mComponentSets.Count;
                mComponentSets.Add(componentSet);
                mComponentSetLookup.Add(componentType, lookup);
            }
        }
Exemple #6
0
            public EntitySliceConfiguration Require <TComponent>(SliceRequirementOutput <TComponent> targetOutput) where TComponent : struct
            {
                Debug.Assert(targetOutput != null, "Target output cannot be null before calling this method!");

                ComponentSet <TComponent>    componentSet = mRegistry.GetComponentSet <TComponent>();
                RestrictedArray <TComponent> writeArray   = new RestrictedArray <TComponent>(mRegistry.Capacity);
                ValueInjector <TComponent>   injector     = new ValueInjector <TComponent>(componentSet, writeArray);

                componentSet.ValueModified += injector.InjectExistingValue;

                Tuple <IPublishingIndexSet, ValueInjectorBase> matchPair = new Tuple <IPublishingIndexSet, ValueInjectorBase>(componentSet, injector);

                mMatchedInjectorRequirements.Add(matchPair);

                //Set the write array to be accessed by the component output passed
                Type      outputType = typeof(SliceRequirementOutput <TComponent>);
                FieldInfo arrayField = outputType.GetField("mArray", BindingFlags.NonPublic | BindingFlags.Instance);

                arrayField.SetValue(targetOutput, writeArray);

                return(this);
            }