public Mesh GenerateMap(TileMapData tileMapData)
    {
        int tilesCount = size_x * size_z;

        int verticesSizeX = size_x + 1;
        int verticesSizeZ = size_z + 1;

        int verticesCount  = verticesSizeX * verticesSizeZ;
        int trianglesCount = 2 * tilesCount;

        Vector3[] mapVertices    = new Vector3[verticesCount];
        Vector3[] normalVertices = new Vector3[verticesCount];
        Vector2[] uvVertices     = new Vector2[verticesCount];

        int[] triangleVertices = new int[trianglesCount * 3];

        InitMapVertices(verticesSizeZ, verticesSizeX, mapVertices, normalVertices, uvVertices, tileMapData);
        InitTriangleVertices(verticesSizeX, triangleVertices);

        Mesh mesh = new Mesh
        {
            vertices = mapVertices, triangles = triangleVertices, normals = normalVertices, uv = uvVertices,
            name     = "TileMapMesh"
        };

        return(mesh);
    }
Пример #2
0
    public TileMapData CreateNewMap(int sizex, int sizez)
    {
        TileMapData tmpmap = new TileMapData(sizex, sizez);

        currentMap = tmpmap;
        return(tmpmap);
    }
Пример #3
0
 public void EnemySpawningDifficulty(TileMapData map, int numEnemies)
 {
     for (int i = 0; i < numEnemies; i++)
     {
         Spawning.SpawnEnemies(map, 1, SpawnAppropriateEnemy(DungeonFloor), PlayerInstance);
     }
 }
    public void Setup()
    {
        _tileMapData         = new TileMapData(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE);
        TileData[,] tileData = _tileMapData.GetTileData();
        for (int x = 0; x < MAP_SQUARE_SIZE; x++)
        {
            for (int z = 0; z < MAP_SQUARE_SIZE; z++)
            {
                tileData [x, z] = GetGrassTileData();
            }
        }

        // Add un-walkable tiles in middle of tilemap
        tileData [4, 4] = GetWaterTileData();
        tileData [5, 4] = GetWaterTileData();
        tileData [6, 4] = GetWaterTileData();

        Graph graph = new Graph(MAP_SQUARE_SIZE, MAP_SQUARE_SIZE);

        graph.Generate4WayGraph();
        _nodeGrapth = graph.GetGraph();

        _validStraightPathfinder = new Pathfinder(_tileMapData, _nodeGrapth);
        _validStraightPathfinder.GeneratePath(0, 0, 5, 0);

        _invalidPathfinder = new Pathfinder(_tileMapData, _nodeGrapth);
        _invalidPathfinder.GeneratePath(0, 0, 0, 0);

        _validIgnoreUnWalkablePathfinder = new Pathfinder(_tileMapData, _nodeGrapth);
        _validIgnoreUnWalkablePathfinder.GeneratePath(new Vector3(3, 0, 4), new Vector3(7, 0, 4));
    }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AI"/> class.
 /// </summary>
 /// <param name="self">Self.</param>
 /// <param name="tileMapData">Tile map data.</param>
 /// <param name="tileDiscoverer">Tile discoverer.</param>
 /// <param name="pathfinder">Pathfinder.</param>
 protected AI(Unit self, TileMapData tileMapData, TileDiscoverer tileDiscoverer, Pathfinder pathfinder)
 {
     _self           = self;
     _tileMapData    = tileMapData;
     _tileDiscoverer = tileDiscoverer;
     _pathfinder     = pathfinder;
 }
    /// <summary>
    /// Moves a unit across x tiles.
    /// </summary>
    private IEnumerator MoveToTiles()
    {
        Vector3 oldTile = _pathfinder.GetGeneratedPathAt(0);
        Vector3 newTile = Vector3.zero;
        int     index   = 0;

        while (_pathfinder.GetGeneratedPath() != null && index < _pathfinder.GetGeneratedPath().Count - 1)
        {
            newTile = _pathfinder.GetGeneratedPathAt(index + 1);
            Vector3 startingPosition = TileMapUtil.TileMapToWorldCentered(_pathfinder.GetGeneratedPathAt(index), tileMap.TileSize);
            Vector3 endingPosition   = TileMapUtil.TileMapToWorldCentered(newTile, tileMap.TileSize);

            yield return(StartCoroutine(MoveToTile(controller.HighlightedUnit, startingPosition, endingPosition)));

            index++;
            yield return(null);
        }
        _pathfinder.Clear();

        // After move is finished, swap out tile unit is standing on
        if (!TileMapUtil.IsInvalidTile(oldTile))
        {
            TileMapData tileMapData = tileMap.GetTileMapData();
            TileData    oldTileData = tileMapData.GetTileDataAt(oldTile);
            oldTileData.SwapUnits(tileMapData.GetTileDataAt(newTile));
            controller.HighlightedUnit.Tile = newTile;
        }
        yield break;
    }
Пример #7
0
        public BuildingPlacement()
        {
            playerHandler = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerHandler>();

            resManager  = playerHandler.resourceManager;
            tileMapData = GameObject.FindGameObjectWithTag("TileMap").GetComponent <CreateTileMap>().TMData;
        }
Пример #8
0
    private void SaveAllTileMap()
    {
        foreach (var map in tileMaps)
        {
            var allPositions = map.cellBounds.allPositionsWithin;

            var tilePos   = new List <Vector2Int>();
            var tileNames = new List <string>();

            foreach (var pos in allPositions)
            {
                var localPlace = new Vector3Int(pos.x, pos.y, 0);

                if (map.HasTile(localPlace))
                {
                    var tile = map.GetTile(localPlace);
                    tilePos.Add((Vector2Int)localPlace);
                    tileNames.Add(tile.name);
                }
            }


            TileMapData tileMapData = new TileMapData();
            tileMapData.tilePos   = tilePos;
            tileMapData.tileNames = tileNames;
            JsonExporter.CreateJsonFile <TileMapData>(mapDataPath, map.name, tileMapData);
        }
    }
Пример #9
0
    void SpawnItem(TileMapData map)
    {
        int r = (int)Random.Range(0, 4);

        if (r == 0)
        {
            Spawning.SpawnItem(map, Sword);
            GameObject.FindGameObjectWithTag("Equip").GetComponent <Weapon>().setStats(DungeonFloor + 1, DungeonFloor / 2, 0);
        }
        else if (r == 1)
        {
            Spawning.SpawnItem(map, Helmet);
            GameObject.FindGameObjectWithTag("Equip").GetComponent <Helmet>().setStats(DungeonFloor / 2, DungeonFloor + 1, 0);
        }
        else if (r == 2)
        {
            Spawning.SpawnItem(map, Necklace);
            GameObject.FindGameObjectWithTag("Equip").GetComponent <Necklace>().setStats(DungeonFloor + 1, DungeonFloor + 1, DungeonFloor + 1);
        }
        else if (r == 3)
        {
            Spawning.SpawnItem(map, Armor);
            GameObject.FindGameObjectWithTag("Equip").GetComponent <Armor>().setStats(DungeonFloor / 2, 0, DungeonFloor + 1);
        }
    }
Пример #10
0
    bool SanityCheck()
    {
        TileMapData data = dataProvider.MapData();

        if (width > data.cols)
        {
            return(false);
        }
        else if (height > data.rows)
        {
            return(false);
        }
        else if (colOffset >= data.cols)
        {
            return(false);
        }
        else if (rowOffset >= data.rows)
        {
            return(false);
        }
        else
        {
            return(true);
        }
    }
Пример #11
0
    public void SaveMap()
    {
        IsometricTileMap tileMap = FindObjectOfType <IsometricTileMap>();

        int way = 0;

        foreach (var set in DoorToggle)
        {
            way |= set.toggle.isOn ? (int)set.way : 0;
        }

        TileMapData data = new TileMapData()
        {
            mapName       = saveMapName.text,
            mapTheme      = saveMapTheme.text,
            mapWeight     = int.Parse(saveMapWeight.text),
            mapMin        = tileMap.min,
            mapMax        = tileMap.max,
            mapDifficulty = int.Parse(saveMapDifficulty.text),
            mapData       = tileMap.ToJson(),
            mapWay        = way,
            mapDraw       = int.Parse(saveMapDraw.text),
            mapCost       = int.Parse(saveMapCost.text)
        };

        File.WriteAllText(Application.dataPath + "/Resources/Map/" + data.mapName + ".txt", JsonUtility.ToJson(data));
    }
Пример #12
0
 public Exit(TileMapData m, int ID, int x, int y)
 {
     Map           = m;
     TargetMapID   = ID;
     Destination_X = x;
     Destination_Y = y;
 }
Пример #13
0
    public static Room CreateRoom(string roomName, Vector2Int index)
    {
        string      jsonData = ResourceManager.GetResource <TextAsset>("Map/" + roomName).text;
        TileMapData data     = JsonUtility.FromJson <TileMapData>(jsonData);

        Room room = new GameObject(roomName).AddComponent <Room>();

        room.RoomIndex      = index;
        room.RoomAllEntitys = new List <Character>();
        room.RoomDoors      = new List <Door>();
        room.RoomWays       = new List <MapWay>();

        room.MapData          = data;
        room.SupportDrawCount = data.mapDraw;
        room.SupportCostCount = data.mapCost;

        foreach (var pair in data.mapData.data)
        {
            room.LoadMapElement(EffectiveUtility.VectorMultiple(new Vector3(pair.index.x, pair.index.y, pair.index.z), Isometric.IsometricTileSize),
                                ResourceManager.GetResource <GameObject>("Tiles/" + pair.tag));
        }

        room.NavData = DynamicNavigation.Instance.BuildNavigation(room.transform);
        room.gameObject.SetActive(false);
        return(room);
    }
Пример #14
0
    // Use this for initialization
    void Start()
    {
        TileMapData map = gm.map.CreateNewMap(size_X, size_Z);

        gm.map.BuildMesh(this.gameObject, size_X, size_Z);
        gm.map.BuildTexture(this.gameObject, map, size_X, size_Z);
    }
Пример #15
0
    public void NextFloor()//called when player hits action on downstairs
    {
        float startTime = Time.realtimeSinceStartup;

        PlayerInstance.SetActive(false);
        toPrevFloor = false;
        DungeonFloor++;
        ClearEnemies();
        ClearItems();

        if (DungeonFloor >= dungeon.length())//if the player hasn't been here before, generate a new floor
        {
            TileMapData generated = genTMD();
            MoveMap(generated);
            dungeon.add(generated);
            EnemySpawningDifficulty(generated, numEnemies);
        }
        else
        {
            MoveMap(dungeon.getTMD(DungeonFloor));    //if the player has been here, load it from the list
            Spawning.RespawnEnemies(DungeonFloor);
        }
        PlayerInstance.SetActive(true);
        float endTime = Time.realtimeSinceStartup;

        Debug.Log(endTime - startTime + "seconds loadtime");
        Debug.Log("DungeonFloor: " + DungeonFloor);
    }
Пример #16
0
    public void CreateNewMap(int sizex, int sizez)
    {
        TileMapData tmpmap = new TileMapData(sizex, sizez);

        currentMap = tmpmap;
        BuildMesh(map, sizex, sizez);
        BuildTexture(map, currentMap, sizex, sizez);
    }
Пример #17
0
        protected override void OnOverTile(Vector2Int tileXY)
        {
            base.OnOverTile(tileXY);

            bool canPlace = TileMapData.IsTilePassable(tileXY) && !AreUnitsOnTile(tileXY);

            m_OverlayRenderer.SetOverlayColor(canPlace ? Color.white : Color.red);
        }
        public TileMapData GenerateMapData()
        {
            TileMapData tileMapData = new TileMapData(_sizeX, _sizeY);

            InitTiles(tileMapData);

            return(tileMapData);
        }
Пример #19
0
    private void Awake()
    {
        t_data = Resources.Load("Data/TileMap Data") as TileMapData;
        t_data.CalcTileSize();
        tileAvailable = new GameObject[(int)t_data.mapWidth, (int)t_data.mapHeight];

        isEdit = false;
    }
Пример #20
0
    // Start is called before the first frame update
    void Start()
    {
        string      jsonData = ResourceManager.GetResource <TextAsset>("Map/" + _mapDataName).text;
        TileMapData data     = JsonUtility.FromJson <TileMapData>(jsonData);

        GetComponent <IsometricTileMap>().FromJson(data.mapData, true);
        DynamicNavigation.Instance.BuildNavigation();
    }
Пример #21
0
    /// <summary>
    /// 그리드 타일의 위치를 통해 World Position을 반환하는 함수
    /// </summary>
    /// <param name="x">그리드 타일의 x 위치</param>
    /// <param name="y">그리드 타일의 y 위치</param>
    /// <param name="initPos">그리드 타일의 World Position 시작 위치</param>
    /// <param name="data">현재 계산하고자 하는 맵의 데이ㅌ</param>
    /// <returns>x,y 위치의 그리드 타일의 World Position 값을 담은 Vector2 반환</returns>
    public Vector2 CalcTilePosition(int x, int y, Vector2 initPos, ref TileMapData data)
    {
        float xpos = initPos.x;
        float ypos = initPos.y;

        xpos += (x - y) * data.tileWidth;
        ypos += -(x + y) * data.tileHeight;
        return(new Vector2(xpos, ypos));
    }
Пример #22
0
 public Tile(TileMapData map, int x, int y, TileType t, Exit e = null)
 {
     this.map   = map;
     neighbours = new Tile[9];
     tileX      = x;
     tileY      = y;
     TileType   = t;
     exit       = e;
 }
Пример #23
0
 public static void LoadTileMap(TileMapData data, Tilemap tileMap)
 {
     for (int i = data.Bounds.Left; i < data.Bounds.Right; i++)
     {
         for (int j = data.Bounds.Bottom; j < data.Bounds.Top; j++)
         {
             tileMap.SetTile(new Vector3Int(i, j, 0), LoadTile(data.TileNames[j - data.Bounds.Bottom, i - data.Bounds.Left]));
         }
     }
 }
Пример #24
0
 public void add(TileMapData tmd)
 {
     TileMapData[] temp = new TileMapData[floors.Length + 1];
     for (int i = 0; i < floors.Length; i++)
     {
         temp[i] = floors[i];
     }
     temp[temp.Length - 1] = tmd;
     floors = temp;
 }
Пример #25
0
        protected override void OnOverTile(Vector2Int tileXY)
        {
            base.OnOverTile(tileXY);

            if (m_SelectedButtonName != "StartLocation")
            {
                bool canPlace = TileMapData.IsTilePassable(tileXY) && !AreUnitsOnTile(tileXY) && !IsWallOnTile(tileXY);
                m_OverlayRenderer.SetTileStatus(Vector2Int.zero, canPlace ? Color.green : Color.red);
            }
        }
Пример #26
0
    void PlaceMap()
    {
        float       startTime = Time.realtimeSinceStartup;
        TileMapData map       = genTMD();

        dungeon.add(map);
        PlaceMap(map);
        float endTime = Time.realtimeSinceStartup;

        Debug.Log(endTime - startTime + "seconds loadtime");
    }
Пример #27
0
        public void Deserialize()
        {
            XmlSerializer serializer = new XmlSerializer(typeof(TileMapData));

            TileMapData mapData = null;

            using (FileStream stream = new FileStream(TEST_TILEMAP_PATH, FileMode.Open))
            {
                mapData = serializer.Deserialize(stream) as TileMapData;
            }
        }
Пример #28
0
    public void InitTileMap(int sizeX, int sizeY, TileMapData tileMapData)
    {
        GrabComponents();

        _sizeX       = sizeX;
        _sizeY       = sizeY;
        _tileMapData = tileMapData;

        BuildMap();
        BuildTexture();
    }
Пример #29
0
 public void SpawnPotion(TileMapData map, int x, int y, float z) //x and y of tile
 {
     if (map.GetTileAt(x - 1, y) == eTile.Floor)
     {
         Instantiate(Potion, new Vector3(x - 1, y, z), Quaternion.identity);
     }
     else if (map.GetTileAt(x + 1, y) == eTile.Floor)
     {
         Instantiate(Potion, new Vector3(x + 1, y, z), Quaternion.identity);
     }
 }
 private void loadTileMapData()
 {
     string outStr = "";
     var tileMapObject = GameObject.FindGameObjectWithTag("tileMap");
     tileMapData = new TileMapData(tileMapObject);
     foreach (var b in tileMapData.collisionBoundsList)
     {
         outStr += b + "\n";
         displayBoundingRect(b);
     }
     setDebugText2(outStr);
 }
Пример #31
0
        protected override void OnPaintTile(Vector2Int tileXY)
        {
            if (m_SelectedButtonName == "StartLocation")
            {
                // Add game coordinates
                tileXY += Vector2Int.one;

                // Set player start location
                PlayerData   player1    = UserData.current.selectedVariant.players[m_DropdownPlayer.value];
                DataLocation centerView = new DataLocation();
                centerView.x = tileXY.x;
                centerView.y = tileXY.y;
                UserData.current.GetPlayerResourceData(player1).centerView = centerView;
                UserData.current.SetUnsaved();

                m_UnitRenderer.SetStartLocation(m_DropdownPlayer.value, player1);
                return;
            }

            // Check if tile is passable
            if (!TileMapData.IsTilePassable(tileXY))
            {
                return;
            }

            // Check if area is blocked by units or structures
            if (AreUnitsOnTile(tileXY))
            {
                return;
            }

            // Check if area is blocked by wall
            if (IsWallOnTile(tileXY))
            {
                return;
            }

            // Add game coordinates
            tileXY += Vector2Int.one;

            UnitData vehicle = GetVehicleData();

            vehicle.position = new LOCATION(tileXY.x, tileXY.y);

            // Add vehicle to tile
            PlayerData player = UserData.current.selectedVariant.players[m_DropdownPlayer.value];

            UserData.current.GetPlayerResourceData(player).units.Add(vehicle);
            UserData.current.SetUnsaved();

            m_UnitRenderer.AddUnit(player, vehicle);
        }
 void Start()
 {
     selectionCubeGameObject = GameObject.Find ("TileSelectionIndicator");
     _tileMap = GetComponent<TileMapVisual>();
     mapData = _tileMap.getMapData();
     gameManager = GameObject.Find("GameManager(Clone)").GetComponent<GameManager>();
     // check for the runtime system
     isAndroid = Application.platform == RuntimePlatform.Android;
 }
    void BuildTexture()
    {
        // get Data TileMap
        mapData = new TileMapData(size_x, size_y);

        int texWidth = size_x*tileResolution;
        int texHeight = size_y*tileResolution;

        // object for our texture
        Texture2D texture = new Texture2D(texWidth,texHeight);

        // stores texture of tiles
        Color[][] tiles = ChopUpTiles();
        // set texture for one tile
        for (int y = 0; y < size_y; y++) {
            for(int x = 0; x < size_x; x++){
                Color[] p = tiles[mapData.GetTileID(x,y)];
                texture.SetPixels(x*tileResolution, y*tileResolution, tileResolution, tileResolution, p);

            }
        }
        texture.filterMode = FilterMode.Point;
        texture.wrapMode = TextureWrapMode.Clamp;
        // Apply pixel to texture
        texture.Apply();

        MeshRenderer mesh_renderer = GetComponent<MeshRenderer>();
        mesh_renderer.sharedMaterials[0].mainTexture = texture;

          //  Debug.Log("Done Texture!");
    }
Пример #34
0
        protected virtual void Awake()
        {
            if (m_tileMeshSettings == null)
                m_tileMeshSettings = new TileMeshSettings(2, 2, 16, 1f, MeshMode.SingleQuad);

            if (m_tileSheet == null)
                m_tileSheet = ScriptableObject.CreateInstance<TileSheet>();

            if (m_chunkManager == null)
            {
                m_chunkManager = new TileChunkManager();
                m_chunkManager.Initialize(this, m_tileMeshSettings);
            }

            if (m_tileMapData == null)
            {
                m_tileMapData = new TileMapData();
                m_tileMapData.SetSize(m_tileMeshSettings.TilesX, m_tileMeshSettings.TilesY);
            }

            if (Application.isPlaying || m_activeInEditMode)
                CreateMesh();
        }
Пример #35
0
 /**
 * Load a map from a file
 * @param filename name of the file relative to the "Assets/Resources" folder
 */
 public void loadMap(string filename)
 {
     var map_color = filename.Substring(0, filename.IndexOf('_'));
     var map_index = SaveDataScript.map_to_slot(map_color);
     _tileMapData = SaveDataScript.save_data.map_data[map_index];
 }
Пример #36
0
 // Get the position of a key point
 public int[] get_key_point(TileMapData.KeyPoint key_point)
 {
     return _tileMapData.get_key_point(key_point);
 }
 private void loadTileMapData()
 {
     tileMapData = new TileMapData(tileMapObject);
 }
 private void loadTileMapData()
 {
     tileMapPrefab = Resources.Load<GameObject>(battleTree.treeName);
     tileMapObject = (GameObject)Instantiate(tileMapPrefab);
     //tileMapObject.tag = "tileMap";
     tileMapData = new TileMapData(tileMapObject);
 }