/// <summary>
        /// Initializes the default world or runs ICustomBootstrap if one is available.
        /// </summary>
        /// <param name="defaultWorldName">The name of the world that will be created. Unless there is a custom bootstrap.</param>
        /// <param name="editorWorld">Editor worlds by default only include systems with [ExecuteAlways]. If editorWorld is true, ICustomBootstrap will not be used.</param>
        public static World Initialize(string defaultWorldName, bool editorWorld = false)
        {
            RegisterUnloadOrPlayModeChangeShutdown();

            if (!editorWorld)
            {
                var bootStrap = CreateBootStrap();
                if (bootStrap != null && bootStrap.Initialize(defaultWorldName))
                {
                    Assert.IsTrue(World.DefaultGameObjectInjectionWorld != null,
                                  $"ICustomBootstrap.Initialize() implementation failed to set " +
                                  $"World.DefaultGameObjectInjectionWorld, despite returning true " +
                                  $"(indicating the World has been properly initialized)");
                    return(World.DefaultGameObjectInjectionWorld);
                }
            }

            var world = new World(defaultWorldName, editorWorld ? WorldFlags.Editor : WorldFlags.Game);

            World.DefaultGameObjectInjectionWorld = world;

            var systemList = GetAllSystems(WorldSystemFilterFlags.Default, editorWorld);

            AddSystemToRootLevelSystemGroupsInternal(world, systemList, systemList.Count);

#if !UNITY_DOTSRUNTIME
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
#endif

            DefaultWorldInitialized?.Invoke(world);
            return(world);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the default world or runs ICustomBootstrap if one is available.
        /// </summary>
        /// <param name="defaultWorldName">The name of the world that will be created. Unless there is a custom bootstrap.</param>
        /// <param name="editorWorld">Editor worlds by default only include systems with [ExecuteAlways]. If editorWorld is true, ICustomBootstrap will not be used.</param>
        public static void Initialize(string defaultWorldName, bool editorWorld)
        {
            RegisterUnloadOrPlayModeChangeShutdown();

            if (!editorWorld)
            {
                var bootStrap = CreateBootStrap();
                if (bootStrap != null && bootStrap.Initialize(defaultWorldName))
                {
                    return;
                }
            }

            var world = new World(defaultWorldName, editorWorld ? WorldFlags.Editor : WorldFlags.Game);

            World.DefaultGameObjectInjectionWorld = world;

            var systems = GetAllSystems(WorldSystemFilterFlags.Default, editorWorld);

            AddSystemsToRootLevelSystemGroups(world, systems);
            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(world);

            DefaultWorldInitialized?.Invoke(world);
        }