/// <summary>
        /// 创建服务端世界
        /// </summary>
        public World CreateServerWorld(string ServerWorldName, params string[] EnableMods)
        {
            //创建世界
            World         ServerWorld = new World(ServerWorldName);
            EntityManager manager     = ServerWorld.EntityManager;
            //添加世界信息组件
            Entity e = manager.CreateEntity(ComponentType.ReadWrite <WorldTypeInfo>());

            manager.SetComponentData(e, new WorldTypeInfo()
            {
                type = WorldTypes.ServerWorld
            });
            manager.SetName(e, "WorldTypeInfo");
            //为接下来将在ServerWorld中禁用的Presentation组的系统做缓存,节省查找开销
            List <Type>[] types = new List <Type> [EnableMods.Length];
            //轮询添加系统
            for (int i = 0; i < EnableMods.Length; i++)
            {
                NativeModSystems mod = ModSystems[EnableMods[i]];
                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ServerWorld, mod.DefaultWorldSystem);
                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ServerWorld, mod.ServerSystems);
                //缓存
                types[i] = mod.DefaultPresentationSystems;
            }
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(ServerWorld);
            //获取ServerWorld中的PresentationSystemGroup并禁止其运行
            for (int i = 0; i < types.Length; i++)
            {
                for (int j = 0; j < types[i].Count; j++)
                {
                    ServerWorld.GetExistingSystem(types[i][j]).Enabled = false;
                }
            }
            return(ServerWorld);
        }
Ejemplo n.º 2
0
        public static World CreateNewDedicatedRenderingWorld(string name)
        {
            var world = new World(name);

            {
                var systems = new System.Type[] {
                                        #if ENABLE_HYBRID_RENDERER_V2
                    typeof(HybridRendererSystem)
                                        #else
                    typeof(RenderMeshSystemV2)
                                        #endif

                    // fixes: warning from RenderMeshSystemV2
                    , typeof(UpdatePresentationSystemGroup)
                    , typeof(PresentationSystemGroup)
                    , typeof(StructuralChangePresentationSystemGroup)

                    // fixes: "Internal: deleting an allocation that is older than its permitted lifetime of 4 frames (age = 15)"
                    , typeof(EndSimulationEntityCommandBufferSystem)

                    , typeof(SegmentInitializationSystem)
                    , typeof(SegmentTransformSystem)
                    , typeof(SegmentWorldBoundsSystem)
                    , typeof(CreateSegmentsSystem)
                };
                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, systems);
                ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);

                // var defaultSystems = DefaultWorldInitialization.GetAllSystems( WorldSystemFilterFlags.Default );
                // DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups( world , defaultSystems );
                // // EntitySceneOptimization.Optimize( world );// what's this for?
                // ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop( world );
            }
            return(world);
        }
Ejemplo n.º 3
0
    public override bool Initialize(string defaultWorldName)
    {
        var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;

        if (sceneName == "Asteroids" ||
            sceneName == "NetCube" ||
            sceneName == "LagCompensation" ||
            sceneName.StartsWith("BasicPrespawnTest") ||
            sceneName.StartsWith("Test"))
        {
            return(base.Initialize(defaultWorldName));
        }

        var world = new World(defaultWorldName);

        World.DefaultGameObjectInjectionWorld = world;

        var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

        GenerateSystemLists(systems);

        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, DefaultWorldSystems);
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
        return(true);
    }
Ejemplo n.º 4
0
        public virtual bool Initialize(string defaultWorldName)
        {
            World defaultWorld = new World(defaultWorldName);

            World.DefaultGameObjectInjectionWorld = defaultWorld;

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            GenerateSystemList(systems);

            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(defaultWorld,
                                                                         SystemStates.ExplicitDefaultWorldSystems);
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(defaultWorld);

            Config = GetBootstrapConfig();

#if !UNITY_SERVER || UNITY_EDITOR
            if (Config.StartupWorld.HasFlag(TargetWorld.Client))
            {
                for (int i = 0; i < Config.ClientNum; i++)
                {
                    CreateClientWorld(defaultWorld, "ClientWorld" + i);
                }
            }
#endif


#if UNITY_SERVER || UNITY_EDITOR
            if (Config.StartupWorld.HasFlag(TargetWorld.Server))
            {
                CreateServerWorld(defaultWorld, "ServerWorld");
            }
#endif
            return(true);
        }
Ejemplo n.º 5
0
    public bool Initialize(string defaultWorldName)
    {
        var world = new LatiosWorld(defaultWorldName);

        World.DefaultGameObjectInjectionWorld = world;

        var initializationSystemGroup = world.GetExistingSystem <InitializationSystemGroup>();
        var simulationSystemGroup     = world.GetExistingSystem <SimulationSystemGroup>();
        var presentationSystemGroup   = world.GetExistingSystem <PresentationSystemGroup>();
        var systems = new List <Type>(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default));

        systems.RemoveSwapBack(typeof(InitializationSystemGroup));
        systems.RemoveSwapBack(typeof(SimulationSystemGroup));
        systems.RemoveSwapBack(typeof(PresentationSystemGroup));

        BootstrapTools.InjectUnitySystems(systems, world, simulationSystemGroup);
        BootstrapTools.InjectRootSuperSystems(systems, world, simulationSystemGroup);

        initializationSystemGroup.SortSystems();
        simulationSystemGroup.SortSystems();
        presentationSystemGroup.SortSystems();

        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
        return(true);
    }
Ejemplo n.º 6
0
    public override bool Initialize(string defaultWorldName)
    {
        var  sceneName     = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
        bool isSampleScene = (sceneName == "Asteroids" || sceneName == "NetCube" || sceneName == "LagCompensation");
        bool isTestScene   = (sceneName.StartsWith("BasicPrespawnTest") || sceneName.StartsWith("Test"));

        if (isSampleScene || isTestScene)
        {
            // For the sample scenes we use a dynamic assembly list so we can build a server with a subset of the assemblies
            // (only including one of the samples instead of all)
            RpcSystem.DynamicAssemblyList = isSampleScene;
            var success = base.Initialize(defaultWorldName);
            RpcSystem.DynamicAssemblyList = false;
            return(success);
        }

        var world = new World(defaultWorldName, WorldFlags.Game);

        World.DefaultGameObjectInjectionWorld = world;

        var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

        GenerateSystemLists(systems);

        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, DefaultWorldSystems);
#if !UNITY_DOTSRUNTIME
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
#endif
        return(true);
    }
        public override void Setup()
        {
            base.Setup();

            KeyDomainUtility.Initialize(World);
            m_StateManager = World.GetOrCreateSystem <StateManager>();

            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(World);
        }
Ejemplo n.º 8
0
    public static World CreateDefaultWorld(string name)
    {
        var defaultWorld = new World(name);

        World.DefaultGameObjectInjectionWorld = defaultWorld;
        GenerateSystemLists(DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default));
        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(defaultWorld, ExplicitDefaultWorldSystems);
    #if !UNITY_DOTSRUNTIME
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(defaultWorld);
    #endif
        return(defaultWorld);
    }
Ejemplo n.º 9
0
        public override void Setup()
        {
            base.Setup();

            World2 = new World("Test World 2");
            var emptySys = World2.GetOrCreateSystem <EmptySystem>();
            var simGroup = World.GetOrCreateSystem <SimulationSystemGroup>();

            simGroup.AddSystemToUpdateList(emptySys);
            simGroup.SortSystems();

            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(World.DefaultGameObjectInjectionWorld);
        }
        public void CurrentPlayerLoopWrappers_Work()
        {
            using (var world = new World("Test World"))
            {
                // world must have at least one of the default top-level groups to add
                var initSysGroup = world.CreateSystem <InitializationSystemGroup>();

                Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(world));
                ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
                Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(world));
                ScriptBehaviourUpdateOrder.RemoveWorldFromCurrentPlayerLoop(world);
                Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(world));
            }
        }
Ejemplo n.º 11
0
    public override bool Initialize(string defaultWorldName)
    {
        var world = new World(defaultWorldName);

        World.DefaultGameObjectInjectionWorld = world;

        var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

        GenerateSystemLists(systems);

        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems);
#if !UNITY_DOTSRUNTIME
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
#endif
        return(true);
    }
Ejemplo n.º 12
0
        protected virtual World CreateDefaultWorld(string defaultWorldName)
        {
            World world = new World(defaultWorldName);

            World.DefaultGameObjectInjectionWorld = world;

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            GenerateSystemList(systems);

            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world,
                                                                         SystemStates.ExplicitDefaultWorldSystems.Concat(SystemStates.DefaultWorldSystems));

            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);

            return(world);
        }
Ejemplo n.º 13
0
 public void TearDown()
 {
     if (World.DefaultGameObjectInjectionWorld != null)
     {
         World.DefaultGameObjectInjectionWorld.Dispose();
     }
     if (PreviousGameObjectInjectionWorld != null && !PreviousGameObjectInjectionWorld.IsCreated)
     {
         PreviousGameObjectInjectionWorld = null;
     }
     World.DefaultGameObjectInjectionWorld = PreviousGameObjectInjectionWorld;
     if (_wasInPlayerLoop)
     {
         ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(PreviousGameObjectInjectionWorld);
         _wasInPlayerLoop = false;
     }
 }
Ejemplo n.º 14
0
        public virtual bool Initialize(string defaultWorldName)
        {
            // The default world must be created before generating the system list in order to have a valid TypeManager instance.
            // The TypeManage is initialised the first time we create a world.
            var world = new World(defaultWorldName);

            World.DefaultGameObjectInjectionWorld = world;

            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            GenerateSystemLists(systems);

            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems);
#if !UNITY_DOTSRUNTIME
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
#endif

            PlayType playModeType    = RequestedPlayType;
            int      numClientWorlds = 1;

            int totalNumClients = numClientWorlds;
            if (playModeType != PlayType.Server)
            {
#if UNITY_EDITOR
                int numThinClients = RequestedNumThinClients;
                totalNumClients += numThinClients;
#endif
                for (int i = 0; i < numClientWorlds; ++i)
                {
                    CreateClientWorld(world, "ClientWorld" + i);
                }
#if UNITY_EDITOR
                for (int i = numClientWorlds; i < totalNumClients; ++i)
                {
                    var clientWorld = CreateClientWorld(world, "ClientWorld" + i);
                    clientWorld.EntityManager.CreateEntity(typeof(ThinClientComponent));
                }
#endif
            }

            if (playModeType != PlayType.Client)
            {
                CreateServerWorld(world, "ServerWorld");
            }
            return(true);
        }
Ejemplo n.º 15
0
    // 默认引导实现内容 进入客户端 和 服务器 世界
    private void DefaultInitialize(string defaultWorldName)
    {
        // 为了拥有一个有效的TypeManager实例,必须在生成系统列表之前创建默认的世界。
        // 当我们第一次创建一个世界时,TypeManage被初始化。
        var world = new World(defaultWorldName, WorldFlags.Game);

        World.DefaultGameObjectInjectionWorld = world;

        var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

        GenerateSystemLists(systems);

        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, ExplicitDefaultWorldSystems);
#if !UNITY_DOTSRUNTIME
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(world);
#endif

        PlayType playModeType    = RequestedPlayType;
        int      numClientWorlds = 1;

        int totalNumClients = numClientWorlds;
        if (playModeType != PlayType.Server)
        {
#if UNITY_EDITOR
            int numThinClients = RequestedNumThinClients;
            totalNumClients += numThinClients;
#endif
            for (int i = 0; i < numClientWorlds; ++i)
            {
                CreateClientWorld(world, "ClientWorld" + i);
            }
#if UNITY_EDITOR
            for (int i = numClientWorlds; i < totalNumClients; ++i)
            {
                var clientWorld = CreateClientWorld(world, "ClientWorld" + i);
                clientWorld.EntityManager.CreateEntity(typeof(ThinClientComponent));
            }
#endif
        }

        if (playModeType != PlayType.Client)
        {
            CreateServerWorld(world, "ServerWorld");
        }
    }
Ejemplo n.º 16
0
    public static World CreateClientApplicationWorld(World clientWorld, string name)
    {
        var applicationWorld           = new World("Client Application World");
        var clientMenuSystemGroup      = applicationWorld.CreateSystem <ClientMenuSystemGroup>();
        var clientMenuSystem           = applicationWorld.CreateSystem <ClientMenuSystem>();
        var rootApplicationSystemTypes = new Type[1] {
            typeof(SimulationSystemGroup)
        };

        clientWorld.EntityManager.CreateEntity(typeof(ClientConnection));
        clientMenuSystem.ClientWorld = clientWorld;
        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(applicationWorld, rootApplicationSystemTypes);
        applicationWorld.GetExistingSystem <SimulationSystemGroup>().AddSystemToUpdateList(clientMenuSystemGroup);
        clientMenuSystemGroup.AddSystemToUpdateList(clientMenuSystem);
    #if !UNITY_DOTSRUNTIME
        ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(applicationWorld);
    #endif
        return(applicationWorld);
    }
        /// <summary>
        /// 被unity调用的初始化函数
        /// </summary>
        public bool Initialize(string DefaultWorldName)
        {
            //创建默认世界
            World defaultWorld = new World(DefaultWorldName);

            //将World里得默认世界设置为defaultWorld
            World.DefaultGameObjectInjectionWorld = defaultWorld;
            //获取所有原生的系统
            var systems = DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default);

            //对系统进行分类
            SortSystems(systems);
            //添加系统
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(defaultWorld, ExplicitDefaultWorldSystems);
            //将系统添加到Update列表中
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(defaultWorld);
            CreateClientWorld("ClientWorld", "GameCore");
            CreateServerWorld("ServerWorld", "GameCore");
            return(true);
        }
        public void AddRemoveScriptUpdate()
        {
            DefaultWorldInitialization.Initialize("Test World", true);

            var newWorld = new World("WorldA");

            newWorld.CreateSystem <InitializationSystemGroup>();
            newWorld.CreateSystem <SimulationSystemGroup>();
            newWorld.CreateSystem <PresentationSystemGroup>();
            Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld));

            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(newWorld);
            Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld));

            PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop());
            Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(newWorld));

            var playerLoop = PlayerLoop.GetDefaultPlayerLoop();

            ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(World.DefaultGameObjectInjectionWorld, ref playerLoop);
            PlayerLoop.SetPlayerLoop(playerLoop);
            Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInCurrentPlayerLoop(World.DefaultGameObjectInjectionWorld));
        }
        public override void Setup()
        {
            base.Setup();

            CloseAllDebuggers();

            m_Window = EditorWindow.GetWindow <EntityDebugger>();

            m_System = World.GetOrCreateSystem <SingleGroupSystem>();
            World.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(m_System.Managed);

            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(World);

            World2 = new World(World2Name);
            var emptySys = World2.GetOrCreateSystem <EmptySystem>();

            World.GetOrCreateSystem <SimulationSystemGroup>().AddSystemToUpdateList(emptySys);
            World.GetOrCreateSystem <SimulationSystemGroup>().SortSystems();

            entityQuery = m_System.Managed.EntityQueries[0];

            m_Entity = m_Manager.CreateEntity(typeof(EcsTestData));
        }
        /// <summary>
        /// 创建客户端世界
        /// </summary>
        public World CreateClientWorld(string ClientWorldName, params string[] EnableMods)
        {
            //创建世界
            World         ClientWorld = new World(ClientWorldName);
            EntityManager manager     = ClientWorld.EntityManager;
            //添加世界信息组件
            Entity e = manager.CreateEntity(ComponentType.ReadWrite <WorldTypeInfo>());

            manager.SetComponentData(e, new WorldTypeInfo()
            {
                type = WorldTypes.ClientWorld
            });
            manager.SetName(e, "WorldTypeInfo");
            //轮询添加系统
            for (int i = 0; i < EnableMods.Length; i++)
            {
                NativeModSystems mod = ModSystems[EnableMods[i]];
                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ClientWorld, mod.DefaultWorldSystem);
                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(ClientWorld, mod.ClientSystems);
            }
            //添加到Update列表
            ScriptBehaviourUpdateOrder.AddWorldToCurrentPlayerLoop(ClientWorld);
            return(ClientWorld);
        }