Exemple #1
0
        private void CreateMap(float[] map)
        {
            var mapSize = map.Length;

            var mapArchetype  = _entityManager.CreateArchetype(typeof(MapSettings));
            var tileArchetype = _entityManager.CreateArchetype(typeof(MovementCost));
            var tiles         = new NativeArray <Entity>(mapSize, Allocator.Temp);

            _entityManager.CreateEntity(tileArchetype, tiles);
            var mapEntity = _entityManager.CreateEntity(mapArchetype);

            for (int i = 0; i < mapSize; i++)
            {
                _entityManager.SetComponentData(tiles[i], new MovementCost {
                    Cost = map[i]
                });
            }

            var blitableTiles = new BlitableArray <Entity>();

            blitableTiles.Allocate(tiles, Allocator.Temp);

            if (TargetSystem.HasSingleton <MapSettings>() == false)
            {
                TargetSystem.EntityManager.CreateEntity(typeof(MapSettings));
                TargetSystem.SetSingleton(new MapSettings {
                    MapEdgeSize = EdgeSize(mapSize), Tiles = blitableTiles
                });
            }
        }
Exemple #2
0
        public void NoMap_NoTile()
        {
            var entity = SetMouseInput(float2.zero);

            if (TargetSystem.HasSingleton <MapSettings>() == false)
            {
                TargetSystem.SetSingleton(new MapSettings()
                {
                    MapEdgeSize = 5
                });
            }

            Update();

            var tileUnderMouse = _entityManager.GetComponentData <TileUnderMouse>(entity);

            AreEqual(new Entity(), tileUnderMouse.Tile);
            False(_entityManager.Exists(tileUnderMouse.Tile));
        }
Exemple #3
0
        private void SetMap(int edgeSize)
        {
            var mapSize = edgeSize * edgeSize;
            var tile    = _entityManager.CreateEntity(typeof(GroundType));

            _entityManager.SetComponentData(tile, new GroundType(BlobsMemory.Instance.ReferencesOf <GroundTypeBlob>()[0]));
            var tiles = new BlitableArray <Entity>(mapSize, Unity.Collections.Allocator.Temp);

            for (int i = 0; i < mapSize; i++)
            {
                tiles[i] = tile;
            }

            _entityManager.CreateEntity(typeof(MapSettings));
            TargetSystem.SetSingleton(new MapSettings()
            {
                Tiles = tiles, MapEdgeSize = edgeSize
            });
        }