Esempio n. 1
0
 public void Setup()
 {
     m_PrevPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
     m_CustomInjectionWorld.Setup();
     DefaultWorldInitialization.Initialize("TestWorld", false);
     m_World = World.DefaultGameObjectInjectionWorld;
 }
Esempio n. 2
0
        // Start is called before the first frame update
        private void Start()
        {
            DefaultWorldInitialization.Initialize("SwarmOfIron", false);

            World w = World.DefaultGameObjectInjectionWorld;

            //Init entityManager
            entityManager      = w.EntityManager;
            updateMoveToSystem = w.GetOrCreateSystem <UpdateMoveToSystem>();

            //create selection Mesh
            unitSelectedCircleMesh = SelectionMesh.CreateMesh(1.0f, 1.0f);

            //spawn some woods
            // Wood.SpawnWood(spawnWoodAmount);
            CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Wood), spawnWoodAmount);
            CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Rock), spawnRockAmount);

            //spawn some workers
            CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Worker), spawnWorkerAmount);


            //spawn some soldiers
            Soldier.init();
            CustomEntity.SpawnEntitiesAtRandomPosition(typeof(Soldier), spawnSoldierAmount);
            //spawn Enemie soldiers
            E_Soldier.init();
            CustomEntity.SpawnEntitiesAtRandomPosition(typeof(E_Soldier), EspawnSoldierAmount);

            MiniMap.SpawnMiniMap();

            //CityHall.SpawnCityHall(new float3(0.0f, 0.0f, 0.0f));
        }
Esempio n. 3
0
        public virtual void Setup()
        {
            m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
            DefaultWorldInitialization.Initialize("Test World", true);
            var world = World.DefaultGameObjectInjectionWorld;

            m_Manager = world.EntityManager;

            m_Container = new MockHierarchy
            {
                Strategy  = new EntityHierarchyDefaultGroupingStrategy(world),
                QueryDesc = null,
                World     = world
            };

            m_AssertHelper = new TestHierarchyHelper(m_Container.Strategy);
            EntityHierarchyDiffSystem.Register(m_Container);

            world.GetOrCreateSystem <SceneSystem>().LoadSceneAsync(m_SubScene.SceneGUID, new SceneSystem.LoadParameters
            {
                Flags = SceneLoadFlags.BlockOnImport | SceneLoadFlags.BlockOnStreamIn
            });

            world.Update();
        }
Esempio n. 4
0
    private void OnEnable()
    {
        var worldNameA = "BuildConfiguration Test World A";
        var worldNameB = "BuildConfiguration Test World B";

        World.DisposeAllWorlds();
        DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying);
        DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying);

        foreach (var world in World.All)
        {
            if (worldA == null && world.Name == worldNameA)
            {
                worldA = world;
            }
            else if (worldB == null && world.Name == worldNameB)
            {
                worldB = world;
            }
        }

        OnValidate();

        var playerLoop = PlayerLoop.GetDefaultPlayerLoop(); // TODO(DOTS-2283): shouldn't stomp the default player loop here

        ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldA, ref playerLoop);
        ScriptBehaviourUpdateOrder.AddWorldToPlayerLoop(worldB, ref playerLoop);
        PlayerLoop.SetPlayerLoop(playerLoop);
    }
Esempio n. 5
0
        public override void InstallBindings()
        {
            //Signals
            Container.DeclareSignal <Match3Signals.OnBoardCreatedSignal>();
            Container.DeclareSignal <Match3Signals.StartSwapSignal>();
            Container.DeclareSignal <Match3Signals.FindMatchesSignal>();
            Container.DeclareSignal <Match3Signals.StartFallSignal>();
            Container.DeclareSignal <Match3Signals.OnPlayerTurnStart>();
            Container.DeclareSignal <Match3Signals.GemCreatedSignal>();
            Container.DeclareSignal <Match3Signals.GemDestroyedSignal>();
            Container.DeclareSignal <Match3Signals.StateChartSignal>();

            //High-level controllers
            Container.BindInterfacesAndSelfTo <CreateBoardCommand>().AsSingle();
            Container.BindSignal <Match3Signals.CreateBoardSignal>()
            .ToMethod <CreateBoardCommand>(x => x.Execute).FromResolve();

            Container.BindInterfacesAndSelfTo <StartSwapCommand>().AsSingle();
            Container.BindSignal <Match3Signals.StartSwapSignal>()
            .ToMethod <StartSwapCommand>(x => x.Execute).FromResolve();

            Container.BindInterfacesAndSelfTo <BoardModel>().AsSingle();
            Container.BindInterfacesAndSelfTo <BoardStateChart.BoardStateChart>().AsSingle();

            DefaultWorldInitialization.Initialize("Match3World", false);
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

            Container.Bind <EntityManager>().FromInstance(entityManager).AsSingle();
            Container.BindInterfacesAndSelfTo <Match3SimulationController>().AsSingle().NonLazy();
        }
Esempio n. 6
0
        protected virtual void OneTimeSetup()
        {
            // We need to intitialise the default world to get a list
            // of default systems, DefaultSystems is set in TestBootStrap
            if (!m_HasInitialised)
            {
                DefaultWorldInitialization.Initialize("Default World", false);
                m_HasInitialised = true;
            }

            // This is so we can preserve the initial worlds
            // This is redundant in Entities.30 as we can't remove
            // worlds or systems without breaking stuff
            //foreach (var w in World.AllWorlds)
            //{
            //    m_InitialWorlds.Add(w);
            //}

            // Set up our default list of systems to test with.
            // Inherited classes can add to this list
            m_DefaultSystems = new List <Type>();
            m_DefaultSystems.AddRange(DefaultSystems);

            // Just to fake the PostInitialize function;
            m_FakeCWB = new FakeCustomWorldBootstrap();
        }
Esempio n. 7
0
    void Awake()
    {
        var w = new World("world");

        DefaultWorldInitialization.Initialize("world", false);
        unitNames = new List <string>();
        spawner   = this;
        Material gpmat         = Resources.Load <Material>("BestMaterial");
        var      entityManager = World.Active.EntityManager;

        id            = 0;
        sp            = new SkillPatterns();
        unitArchetype = entityManager.CreateArchetype(
            typeof(Id),
            typeof(Lvl),
            typeof(Translation),
            typeof(Unit),
            typeof(UnitType),
            typeof(HP),
            typeof(Team),
            typeof(Initiative),
            typeof(Attack),
            typeof(Move),
            typeof(Skill),
            typeof(Cost),
            typeof(ReadyToAction),
            typeof(BoardPosition)
            );
        cellArchetype = entityManager.CreateArchetype(
            typeof(Cell),
            typeof(Translation)
            );
        endGameScreen = Resources.Load <GameObject>("Prefabs/EndGame");
    }
Esempio n. 8
0
        protected virtual void Setup()
        {
            World = DefaultWorldInitialization.Initialize("Test World");
            DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(World,
                                                                         DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Editor));

            BlobStore = new BlobAssetStore();
        }
Esempio n. 9
0
        IEnumerator ReloadScene()
        {
            yield return(new WaitForSeconds(9f));

            World.DisposeAllWorlds();
            DefaultWorldInitialization.Initialize("Default World", false);
            SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
        }
Esempio n. 10
0
    public static void ResetDefaultWorld()
    {
        DefaultWorld.EntityManager.CompleteAllJobs();
        foreach (var system in DefaultWorld.Systems)
        {
            system.Enabled = false;
        }

        DefaultWorld.Dispose();
        DefaultWorldInitialization.Initialize("Default World", false);
    }
        protected static void SwitchWorlds()
        {
            var defaultWorld = World.DefaultGameObjectInjectionWorld;

            defaultWorld.EntityManager.CompleteAllJobs();
            foreach (var system in defaultWorld.Systems)
            {
                system.Enabled = false;
            }

            defaultWorld.Dispose();
            DefaultWorldInitialization.Initialize("Default World", false);
        }
    public virtual void Setup()
    {
        // Ensure we have full stack traces when running tests.
        OldLeakMode = NativeLeakDetection.Mode;
        NativeLeakDetection.Mode = NativeLeakDetectionMode.EnabledWithStackTrace;

        if (World != null)
        {
            return;
        }

        World = DefaultWorldInitialization.Initialize("Test World");
        DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(World, DefaultWorldInitialization.GetAllSystems(WorldSystemFilterFlags.Default));
    }
Esempio n. 13
0
 public void ChangeScene(string _scene)
 {
     if (World.DefaultGameObjectInjectionWorld.IsCreated)
     {
         var systems = World.DefaultGameObjectInjectionWorld.Systems;
         foreach (var s in systems)
         {
             s.Enabled = false;
         }
         World.DefaultGameObjectInjectionWorld.Dispose();
         DefaultWorldInitialization.Initialize("Default World", false);
     }
     SceneManager.LoadScene(_scene);
 }
Esempio n. 14
0
        private void InitWorld(string name)
        {
            DefaultWorldInitialization.Initialize(name, false);
            world = World.DefaultGameObjectInjectionWorld;
            world.GetExistingSystem(typeof(RenderMeshSystemV2)).Enabled = false;
            // Let's instantiate the Map
            var           themap  = ManagerComponent.Get().maps.Find(m => m.name == map);
            EntityManager manager = world.EntityManager;
            GameObjectConversionSettings settings = GameObjectConversionSettings.FromWorld(world, blobAssetStore);
            Entity entity = GameObjectConversionUtility.ConvertGameObjectHierarchy(themap.mapObj, settings);
            Entity spawn  = manager.Instantiate(entity);

            GetSpawnPoints();
        }
Esempio n. 15
0
        public virtual void Setup()
        {
            // unit tests preserve the current player loop to restore later, and start from a blank slate.
            _previousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();
            PlayerLoop.SetPlayerLoop(PlayerLoop.GetDefaultPlayerLoop());

            _previousWorld = World.DefaultGameObjectInjectionWorld;
            World          = World.DefaultGameObjectInjectionWorld = DefaultWorldInitialization.Initialize("Test World", true);
            EntityManager  = World.EntityManager;

            // Many ECS tests will only pass if the Jobs Debugger enabled;
            // force it enabled for all tests, and restore the original value at teardown.
            _jobsDebuggerWasEnabled        = JobsUtility.JobDebuggerEnabled;
            JobsUtility.JobDebuggerEnabled = true;
        }
        public void Setup()
        {
            m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
            const string kTestWorldName = "Test World";

#if UNITY_DOTSPLAYER
            // Tiny always runs outside of process from the Editor, as such we need to
            // invoke the tiny bootstrapping for worlds manually
            World = DefaultWorldInitialization.Initialize(kTestWorldName);
#else
            World = World.DefaultGameObjectInjectionWorld = new World(kTestWorldName);
#endif

            m_Manager      = World.EntityManager;
            m_ManagerDebug = new EntityManager.EntityManagerDebug(m_Manager);
        }
Esempio n. 17
0
 private void Update()
 {
     if (Input.GetKeyDown(KeyCode.Escape))
     {
         Application.Quit();
         return;
     }
     if (Input.GetKeyDown(KeyCode.Space))
     {
         World.DisposeAllWorlds();
         DefaultWorldInitialization.Initialize("Default World", !Application.isPlaying);
         UnityEngine.SceneManagement.SceneManager.LoadScene(0);
         //Invoke("ReLoadScene", 1);
         return;
     }
 }
Esempio n. 18
0
    private void Update()
    {
        timer += Time.deltaTime;

        //end simulation
        if (timer > simulationTime)
        {
            Debug.Log(testName + "_" + StateToString(_state) + "_" + testedValue);
            TimerRecorderManager.Instance.Dump(testName + "_" + StateToString(_state) + "_" + testedValue);
            World.DisposeAllWorlds();
            SceneManager.LoadScene(_scene);
            DefaultWorldInitialization.Initialize("Default World", false);
            Blackboard.Instance.ResetDefaultValues();
            Step();
            timer = 0;
        }
    }
Esempio n. 19
0
        public void AddRemoveScriptUpdate()
        {
            DefaultWorldInitialization.Initialize("Test World", true);

            var newWorld = new World("WorldA");

            Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(newWorld));

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(newWorld);
            Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(newWorld));

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(null);
            Assert.IsFalse(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(newWorld));

            ScriptBehaviourUpdateOrder.UpdatePlayerLoop(World.DefaultGameObjectInjectionWorld);
            Assert.IsTrue(ScriptBehaviourUpdateOrder.IsWorldInPlayerLoop(World.DefaultGameObjectInjectionWorld));
        }
        public virtual void Setup()
        {
            m_PreviousPlayerLoop = PlayerLoop.GetCurrentPlayerLoop();

            m_PreviousWorld = World.DefaultGameObjectInjectionWorld;
            DefaultWorldInitialization.Initialize("Test World", true);
            m_Manager = World.DefaultGameObjectInjectionWorld.EntityManager;

            m_Window       = CreateWindow();
            m_AssertHelper = new TestHierarchyHelper(m_Window.State);

            World.DefaultGameObjectInjectionWorld.GetOrCreateSystem <SceneSystem>().LoadSceneAsync(m_SubScene.SceneGUID, new SceneSystem.LoadParameters
            {
                Flags = SceneLoadFlags.BlockOnImport | SceneLoadFlags.BlockOnStreamIn
            });

            World.DefaultGameObjectInjectionWorld.Update();
        }
Esempio n. 21
0
    private void OnEnable()
    {
        var worldNameA = "BuildSettings Test World A";
        var worldNameB = "BuildSettings Test World B";

        World.DisposeAllWorlds();
        DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying);
        DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying);

        worldA = World.AllWorlds.First(w => w.Name == worldNameA);
        worldB = World.AllWorlds.First(w => w.Name == worldNameB);

        OnValidate();

        //@TODO: This API is confusing. Should be way more explicit.
        //       Current API makes it very easy to have the same system injected multiple times
        ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worldA, null);
        ScriptBehaviourUpdateOrder.UpdatePlayerLoop(worldB, PlayerLoop.GetCurrentPlayerLoop());
    }
        protected static void ResetDefaultWorld()
        {
            var entityManager = DefaultWorld.EntityManager;
            var entities      = entityManager.GetAllEntities();

            entityManager.DestroyEntity(entities);
            entities.Dispose();

            if (DefaultWorld.IsCreated)
            {
                var systems = DefaultWorld.Systems;
                foreach (var s in systems)
                {
                    s.Enabled = false;
                }
                DefaultWorld.Dispose();
            }

            DefaultWorldInitialization.Initialize("Default World", false);
        }
Esempio n. 23
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
            m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }
Esempio n. 24
0
    // Start is called before the first frame update
    void Start()
    {
        if (World.Active == null)
        {
            DefaultWorldInitialization.Initialize("UI World", false);
        }
        //var entityManager = World.Active.EntityManager;

        World.Active.GetOrCreateSystem <UserInputSystemGroup>().AddSystemToUpdateList(World.Active.GetOrCreateSystem <InstantiationSystem>());
        World.Active.GetOrCreateSystem <UserInputSystemGroup>().AddSystemToUpdateList(World.Active.GetOrCreateSystem <CloseButtonSystem>());

        //RectTransformToEntity transformToEntity = new RectTransformToEntity(100, Allocator.Temp);
        //RectTransformConversionUtils.ConvertCanvasHierarchy(m_TopCanvas, World.Active.EntityManager, transformToEntity);
        //RectTransformConversionUtils.ConvertCanvasHierarchy(m_RightCanvas, World.Active.EntityManager, transformToEntity);
        //RectTransformConversionUtils.ConvertCanvasHierarchy(m_PrefabDestination, World.Active.EntityManager, transformToEntity);

        //GameObject.Destroy(m_TopCanvas.gameObject);
        //GameObject.Destroy(m_RightCanvas.gameObject);
        //GameObject.Destroy(m_PrefabDestination.gameObject);
        //transformToEntity.Dispose();
    }
Esempio n. 25
0
        protected static void SwitchWorlds()
        {
            var entityManager = DefaultWorld.EntityManager;
            var entities      = entityManager.GetAllEntities();

            entityManager.DestroyEntity(entities);
            entities.Dispose();

            if (DefaultWorld.IsCreated)
            {
                var systems = DefaultWorld.Systems;
                foreach (var s in systems)
                {
                    s.Enabled = false;
                }
                ScriptBehaviourUpdateOrder.RemoveWorldFromCurrentPlayerLoop(DefaultWorld);
                DefaultWorld.Dispose();
            }

            DefaultWorldInitialization.Initialize("Default World", false);
        }
Esempio n. 26
0
        private void Start()
        {
            DefaultWorldInitialization.Initialize("MyWorld", false);
            var entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
            var entity        = entityManager.CreateEntity();

            entityManager.AddComponentData(entity, new SpawnComponent
            {
                XSize   = xSize,
                YSize   = ySize,
                Spacing = spacing
            });


            var entityData = entityManager.CreateEntity();

            entityManager.AddSharedComponentData(entityData, new RenderDataComponent
            {
                MeshValue     = MainMesh,
                MaterialValue = MainMaterial,
            });
        }
Esempio n. 27
0
        public static World GetWorld()
        {
            if (world != null && world.IsCreated)
            {
                return(world);
            }
            else
            {
                world = World.DefaultGameObjectInjectionWorld;

                                #if UNITY_EDITOR
                if (world == null)
                {
                    // create editor world:
                    world = DefaultWorldInitialization.Initialize("Editor World", true);
                    // DefaultWorldInitialization.DefaultLazyEditModeInitialize();// not immediate
                }
                                #endif

                DefaultWorldInitialization.AddSystemsToRootLevelSystemGroups(world, typeof(SegmentInitializationSystem), typeof(SegmentRenderingSystem));

                // load default material asset:
                if (default_material == null)
                {
                    const string path = "packages/Segments/default";
                    default_material = UnityEngine.Resources.Load <Material>(path);
                    if (default_material != null)
                    {
                        default_material.hideFlags = HideFlags.DontUnloadUnusedAsset;
                    }
                    else
                    {
                        Debug.LogWarning($"loading Material asset failed, path: \'{path}\'");
                    }
                }

                return(world);
            }
        }
Esempio n. 28
0
    private void OnEnable()
    {
        var worldNameA = "BuildConfiguration Test World A";
        var worldNameB = "BuildConfiguration Test World B";

        World.DisposeAllWorlds();
        DefaultWorldInitialization.Initialize(worldNameA, !Application.isPlaying);
        DefaultWorldInitialization.Initialize(worldNameB, !Application.isPlaying);

        foreach (var world in World.All)
        {
            if (worldA == null && world.Name == worldNameA)
            {
                worldA = world;
            }
            else if (worldB == null && world.Name == worldNameB)
            {
                worldB = world;
            }
        }

        OnValidate();
    }
        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));
        }
Esempio n. 30
0
        private UnityInstance()
        {
            m_World = DefaultWorldInitialization.Initialize("Default World");

            m_BootPhase     = BootPhase.Booting;
            m_RunState      = RunState.Resuming;
            m_EntityManager = m_World.EntityManager;

            m_StartTimeInSeconds           = 0;
            m_ElapsedTimeInSeconds         = 0;
            m_PreviousElapsedTimeInSeconds = 0;

            // try to find SceneSystemGroup in worlds
            foreach (var w in World.All)
            {
                m_SceneSystemGroup = w.GetExistingSystem <SceneSystemGroup>();
                m_SceneSystem      = w.GetExistingSystem <SceneSystem>();

                if (m_SceneSystemGroup != null)
                {
                    break;
                }
            }

            // if cannot find - create in the default world
            if (m_SceneSystemGroup == null)
            {
                m_SceneSystemGroup = m_World.GetOrCreateSystem <SceneSystemGroup>();
                m_SceneSystem      = m_World.GetOrCreateSystem <SceneSystem>();
            }

            m_TimeData = (TimeData *)UnsafeUtility.Malloc(
                UnsafeUtility.SizeOf <TimeData>(),
                0,
                Collections.Allocator.Persistent);
        }