コード例 #1
0
        protected override void OnBeforeCreateManagerInternal(World world, int capacity)
        {
            m_World              = world;
            m_EntityManager      = world.GetOrCreateManager <EntityManager>();
            m_SafetyManager      = m_EntityManager.ComponentJobSafetyManager;
            m_AlwaysUpdateSystem = GetType().GetCustomAttributes(typeof(AlwaysUpdateSystemAttribute), true).Length != 0;

            m_ComponentGroups                 = new ComponentGroup[0];
            m_CachedComponentGroupArrays      = new ComponentGroupArrayStaticCache[0];
            m_JobDependencyForReadingManagers = new NativeList <int>(10, Allocator.Persistent);
            m_JobDependencyForWritingManagers = new NativeList <int>(10, Allocator.Persistent);

            ComponentSystemInjection.Inject(this, world, m_EntityManager, out m_InjectedComponentGroups, out m_InjectFromEntityData);
            m_InjectFromEntityData.ExtractJobDependencyTypes(this);

            InjectNestedIJobProcessComponentDataJobs();

            UpdateInjectedComponentGroups();
        }
コード例 #2
0
 public ComponentReplicator(EntityManager entityManager, Unity.Entities.World world) : base(entityManager)
 {
     var bookkeepingSystem = world.GetOrCreateManager <CommandRequestTrackerSystem>();
 }
コード例 #3
0
        public static void Initialize(string worldName, bool editorWorld)
        {
            // Register hybrid injection hooks
            #pragma warning disable 0618
            InjectionHookSupport.RegisterHook(new GameObjectArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new TransformAccessArrayInjectionHook());
            InjectionHookSupport.RegisterHook(new ComponentArrayInjectionHook());
            #pragma warning restore 0618

            PlayerLoopManager.RegisterDomainUnload(DomainUnloadShutdown, 10000);

            var world = new World(worldName);
            World.Active = world;
            var systems = GetAllSystems(WorldSystemFilterFlags.Default);
            if (systems == null)
            {
                world.Dispose();
                if (World.Active == world)
                {
                    World.Active = null;
                }
                return;
            }

            // create presentation system and simulation system
            InitializationSystemGroup initializationSystemGroup = world.GetOrCreateManager <InitializationSystemGroup>();
            SimulationSystemGroup     simulationSystemGroup     = world.GetOrCreateManager <SimulationSystemGroup>();
            PresentationSystemGroup   presentationSystemGroup   = world.GetOrCreateManager <PresentationSystemGroup>();
            // Add systems to their groups, based on the [UpdateInGroup] attribute.
            foreach (var type in systems)
            {
                // Skip the built-in root-level systems
                if (type == typeof(InitializationSystemGroup) ||
                    type == typeof(SimulationSystemGroup) ||
                    type == typeof(PresentationSystemGroup))
                {
                    continue;
                }
                if (editorWorld)
                {
                    if (Attribute.IsDefined(type, typeof(ExecuteInEditMode)))
                    {
                        Debug.LogError(
                            $"{type} is decorated with {typeof(ExecuteInEditMode)}. Support for this attribute will be deprecated. Please use {typeof(ExecuteAlways)} instead.");
                    }
                    if (!Attribute.IsDefined(type, typeof(ExecuteAlways)))
                    {
                        continue;
                    }
                }

                var groups = type.GetCustomAttributes(typeof(UpdateInGroupAttribute), true);
                if (groups.Length == 0)
                {
                    simulationSystemGroup.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
                }

                foreach (var g in groups)
                {
                    var group = g as UpdateInGroupAttribute;
                    if (group == null)
                    {
                        continue;
                    }

                    if (!(typeof(ComponentSystemGroup)).IsAssignableFrom(group.GroupType))
                    {
                        Debug.LogError($"Invalid [UpdateInGroup] attribute for {type}: {group.GroupType} must be derived from ComponentSystemGroup.");
                        continue;
                    }

                    var groupMgr = GetOrCreateManagerAndLogException(world, group.GroupType);
                    if (groupMgr == null)
                    {
                        Debug.LogWarning(
                            $"Skipping creation of {type} due to errors creating the group {group.GroupType}. Fix these errors before continuing.");
                        continue;
                    }
                    var groupSys = groupMgr as ComponentSystemGroup;
                    if (groupSys != null)
                    {
                        groupSys.AddSystemToUpdateList(GetOrCreateManagerAndLogException(world, type) as ComponentSystemBase);
                    }
                }
            }

            // Update player loop
            initializationSystemGroup.SortSystemUpdateList();
            simulationSystemGroup.SortSystemUpdateList();
            presentationSystemGroup.SortSystemUpdateList();
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);
        }