Пример #1
0
        // ReSharper disable once ParameterTypeCanBeEnumerable.Local
        private void CreateSystems(List <TypeInfo> systemTypeInfos, int componentCount)
        {
            var systemAttributeType = typeof(EntitySystemAttribute);
            var aspectAttributeType = typeof(AspectAttribute);

            var andMask = new BitVector(componentCount);
            var orMask  = new BitVector(componentCount);
            var norMask = new BitVector(componentCount);

            foreach (var typeInfo in systemTypeInfos)
            {
                EntitySystemAttribute systemAttribute = null;

                andMask.SetAll(false);
                orMask.SetAll(false);
                norMask.SetAll(false);

                var attributes = typeInfo.GetCustomAttributes(false);
                foreach (var attribute in attributes)
                {
                    var attributeType = attribute.GetType();

                    if (attributeType == systemAttributeType)
                    {
                        systemAttribute = (EntitySystemAttribute)attribute;
                    }

                    if (attributeType != aspectAttributeType)
                    {
                        continue;
                    }

                    var aspectAttribute = (AspectAttribute)attribute;
                    switch (aspectAttribute.Type)
                    {
                    case AspectType.All:
                        EntityManager.FillComponentBits(andMask, aspectAttribute.Components);
                        break;

                    case AspectType.Any:
                        EntityManager.FillComponentBits(orMask, aspectAttribute.Components);
                        break;

                    case AspectType.None:
                        EntityManager.FillComponentBits(norMask, aspectAttribute.Components);
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }

                if (systemAttribute == null)
                {
                    return;
                }

                var system           = _dependencyResolver.Resolve <EntitySystem>(typeInfo.AsType());
                var processingSystem = system as EntityProcessingSystem;
                if (processingSystem != null)
                {
                    processingSystem.Aspect = new Aspect(andMask, orMask, norMask);
                }

                _systemManager.AddSystem(system, systemAttribute.GameLoopType,
                                         systemAttribute.Layer, SystemExecutionType.Synchronous);
            }
        }