예제 #1
0
        public void MakeClientMapFromArray()
        {
            var mapObject = new GameObject {
                name = "Map"
            };
            var hexMap = new HexMap(_serializedMap[0], _serializedMap[1]);

            GameState.Me.HexMap = hexMap;

            for (var t = 2; t < _serializedMap.Length; t += 8)
            {
                //Serialized maps have large deserts of 0,0,0,0,0... on their tails. Cut this off when that happens.
                if (_serializedMap[t + 2] == 0)
                {
                    break;
                }

                GameObject hexObject;
                if (_serializedMap[t] % 2 == 0)
                {
                    hexObject = Object.Instantiate(HexPrefab, new Vector3(_serializedMap[t] * 0.815f, _serializedMap[t + 1], 0), Quaternion.identity) as GameObject;
                }
                else
                {
                    hexObject = Object.Instantiate(HexPrefab, new Vector3(_serializedMap[t] * 0.815f, _serializedMap[t + 1] + 0.5f, 0), Quaternion.identity) as GameObject;
                }
                if (hexObject == null)
                {
                    continue;
                }
                var tile = hexObject.GetComponent <HexTile>();
                hexMap.AllTiles[_serializedMap[t], _serializedMap[t + 1]] = tile;
                tile.X  = _serializedMap[t];
                tile.Y  = _serializedMap[t + 1];
                tile.Id = _serializedMap[t + 2];
                tile.SetTerrain((Terrain)_serializedMap[t + 3]);
                tile.Resource              = new Resource(_serializedMap[t + 4], _serializedMap[t + 5], _serializedMap[t + 6], _serializedMap[t + 7]);
                hexObject.name             = (tile.X + ", " + tile.Y);
                hexObject.transform.parent = mapObject.transform;

                //Add the tile to reference lists.
                hexMap.TileList.Add(tile);
                if (!GameState.Me.AllTiles.ContainsKey(tile.Id))
                {
                    GameState.Me.AllTiles.Add(tile.Id, tile);
                }
            }
        }
예제 #2
0
        public Dictionary <int, HexTile> MakeServerMapFromArray()
        {
            var hexHolder = new GameObject {
                name = "Map"
            };
            var result = new Dictionary <int, HexTile>();
            var hexMap = new HexMap(_serializedMap[0], _serializedMap[1]);

            Debug.Log("The map we got from the client is " + _serializedMap[0] + " by " + _serializedMap[1] + " tiles big.");
            GameState.Server.HexMap = hexMap;
            for (var t = 2; t < _serializedMap.Length; t += 8)
            {
                //Serialized maps have large deserts of 0,0,0,0,0... on their tails. Cut this off when that happens.
                if (_serializedMap[t + 2] == 0)
                {
                    break;
                }

                var newObject = new GameObject();
                newObject.transform.parent = hexHolder.transform;
                var tile = newObject.AddComponent <HexTile>();
                tile.X         = _serializedMap[t];
                tile.Y         = _serializedMap[t + 1];
                tile.Id        = _serializedMap[t + 2];
                tile.Terrain   = (Terrain)_serializedMap[t + 3];
                tile.Resource  = new Resource(_serializedMap[t + 4], _serializedMap[t + 5], _serializedMap[t + 6], _serializedMap[t + 7]);
                newObject.name = tile.X + ", " + tile.Y;

                //Add the tile to reference lists.
                try
                {
                    GameState.Server.HexMap.AllTiles[tile.X, tile.Y] = tile;
                    tile.ParentMap = GameState.Server.HexMap;
                    result.Add(tile.Id, tile);
                }
                catch (Exception e)
                {
                    Debug.Log(_serializedMap[t + 2]);
                    Debug.Log(e);
                }
            }
            Debug.Log("Built the entire map!");
            return(result);
        }