private void SetBackGround(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetBackGround(_Space.left); SetBackGround(_Space.right); } else { var roomType = _Space.roomType; for (int i = (int)_Space.rect.x; i < _Space.rect.xMax; i++) { for (int j = (int)_Space.rect.y; j < _Space.rect.yMax; j++) { if (map[i, j] == null) { map[i, j] = new MapTileData(roomType, (int)TileType.BackGround, UnityEngine.Random.Range(0, tileRefernce[roomType].backGroundSprite.Count)); } } } } }
/* * public GameObject gSprite_Attackable; * public GameObject gSprite_Moveable; * public GameObject gSprite_MouseArea; * public GameObject gSprite_Companion; * public GameObject gSprite_SkillPlayer; * public GameObject gSprite_SkillEnemy; * public GameObject gSprite_SkillBoth; * public GameObject rootMoveParent; * public GameObject rootAttackParent; * public GameObject rootRoutineParent; * public GameObject rootCompanionParent;*/ #if UNITY_EDITOR /// <summary> /// 计算网格的高度到数组中 /// </summary> void ComputeHeight() { _heights = new float[(TileWidth + 1), (TileHeight + 1)]; RaycastHit hitInfo; Vector3 origin; int terrainLayerMask = LayerMask.GetMask("Terrain"); for (int z = 0; z < TileHeight + 1; z++) { for (int x = 0; x < TileWidth + 1; x++) { origin = new Vector3(x * CELLSIZE, 200, z * CELLSIZE); Physics.Raycast(transform.TransformPoint(origin), Vector3.down, out hitInfo, Mathf.Infinity, terrainLayerMask); _heights[x, z] = hitInfo.point.y; } } float[,] CenterHeightData = new float[TileWidth, TileHeight]; for (int i = 0; i < TileHeight; i++) { for (int j = 0; j < TileWidth; j++) { CenterHeightData[j, i] = Mathf.Max(_heights[j, i], _heights[j + 1, i], _heights[j, i + 1], _heights[j + 1, i + 1]); } } MapTileData.InitMapData(TileWidth, TileHeight, CenterHeightData, new int[TileWidth, TileHeight]); }
void Test() { var maptile = new MapTileData { Index = 0, Path = "Grass", R = 255, G = 255, B = 112, LayerMask = 0, Components = new List <string> { "Script", "BoxCollider" } }; var list = new List <MapTileData> { maptile }; var setting = new JsonSerializerSettings(); setting.Formatting = Formatting.Indented; setting.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; var json = JsonConvert.SerializeObject(list, setting); var path = Path.Combine(Application.dataPath, "tiledata.json"); File.WriteAllText(path, json); }
public override void OnInspectorGUI() { base.OnInspectorGUI(); blockTerrainCount = EditorGUILayout.IntField("地块种类数量", blockTerrainCount); if (GUILayout.Button("Generate")) { mapData.tileList.Clear(); mapData.tileList.Capacity = Map.MAP_TILE_COUNT; for (int i = 0; i < Map.MAP_TILE_COUNT; ++i) { MapTileData td = new MapTileData(); td.blockList.Capacity = Map.MAP_BLOCK_COUNT; for (int j = 0; j < Map.MAP_BLOCK_COUNT; ++j) { MapBlockData bd = new MapBlockData(); bd.terrain = Random.Range(1, blockTerrainCount); td.blockList.Add(bd); } mapData.tileList.Add(td); ; } EditorUtility.SetDirty(mapData); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } }
public void ChangeTile(int x, int y, eCountry country) { Destroy(GetTile(x, y).gameObject); MapTileData mapTileData = mapData.tiles[getTileIndex(x, y)]; createTile(x, y, country, mapTileData); }
public RepointerTool(Game game, MapTileData mtd, EntityLoader entityL, bool entity) { InitializeComponent(); LAGame = game; mapTileData = mtd; entityLoader = entityL; entities = entity; setAddressValue(); }
// Start is called before the first frame update void Start() { _tileData = new MapTileData[CHUNKSIZE, CHUNKSIZE]; for (int x = 0; x < CHUNKSIZE; x++) { for (int y = 0; y < CHUNKSIZE; y++) { _tileData[x, y] = new MapTileData(x, y); } } }
public void CreateMap() { for (int i = 0; i < mapData.width; i++) { for (int j = 0; j < mapData.height; j++) { MapTileData mapTileData = mapData.tiles[getTileIndex(i, j)]; if (mapTileData.type != eTileType.None) { createTile(i, j, mapTileData.initCountry, mapTileData); } } } }
public MapTileData GetFreeTile() { MapTileData returnedTile = null; for (int x = 0; x < CHUNKSIZE; x++) { for (int y = 0; y < CHUNKSIZE; y++) { if (_tileData[x, y]._state == Enums.MapTileState.Empty && _tileData[x, y]._structure == null) { return(_tileData[x, y]); } } } return(returnedTile); }
public void SetTileData(MapTileData data) { _data = data; _currentHp = _data._structure._hp; // If is spawner, enable spawner script if (_data._structure._type == Enums.StructureType.Spawner && _data._state == Enums.MapTileState.Struture) { GetComponent <SpawnerTileScript>().enabled = true; } if (_data._structure._type == Enums.StructureType.Warfare && _data._state == Enums.MapTileState.Struture) { var warTile = GetComponent <WarfareTileScript>(); warTile.enabled = true; warTile.SetWarfareData(StoreService.GetWarfareData(Enums.WarfareType.NormalTower)); } }
public void StartMap() { sceneCamera = sceneCameraTrans.GetComponent <Camera>(); plane = new Plane(); DontDestroyOnLoad(this); md = XLoader.Load <MapData>("Map/MapContainer/map_data.asset"); for (int ty = 0; ty < MAP_TILE_COUNT_Y; ++ty) { for (int tx = 0; tx < MAP_TILE_COUNT_X; ++tx) { int tile_id = ty * MAP_TILE_COUNT_X + tx; MapTileData td = md.tileList[tile_id]; MapTile tile = new MapTile(tile_id, td); tile.basePos.x = tx * MAP_TILE_DEMANSION_X; tile.basePos.z = ty * MAP_TILE_DEMANSION_Y; tiles[tile_id] = tile; for (int by = 0; by < MAP_BLOCK_COUNT_Y; ++by) { for (int bx = 0; bx < MAP_BLOCK_COUNT_X; ++bx) { int yy = ty * MAP_BLOCK_COUNT_Y + by; int xx = tx * MAP_BLOCK_COUNT_X + bx; int block_id = yy * MAP_BLOCK_COUNT_TOTAL_X + xx; MapBlock block = new MapBlock(tile, block_id, td.blockList[by * MAP_BLOCK_COUNT_X + bx]); block.basePos.x = tile.basePos.x + bx * MAP_BLOCK_DEMANSION_X; block.basePos.z = tile.basePos.z + by * MAP_BLOCK_DEMANSION_Y; blocks[block_id] = block; } } } } sceneCameraTrans.position = new Vector3(MAP_DEMANSION_X / 2, 10, MAP_DEMANSION_Y / 2); run = true; }
private void btn_Start_Click(object sender, EventArgs e) { List <MapTileInfo> tiles = MapData.Database.TilesGetAll(); int count = tiles.Count(); int i = 1; foreach (MapTileInfo tile in tiles) { try { string dirname = Path.Combine(Properties.Settings.Default.MapTilesRootPath, tile.Zoom.ToString(), tile.X.ToString()); if (!Directory.Exists(dirname)) { Directory.CreateDirectory(dirname); } string filename = Path.Combine(dirname, tile.Y.ToString()) + ".png"; MapTileData d = MapData.Database.TileDataFind(tile.ID); if (d != null && !File.Exists(filename) || (File.GetLastWriteTime(filename) != tile.CacheTime)) { using (BinaryWriter bw = new BinaryWriter(File.Create(filename))) { bw.Write(d.Tile); } File.SetCreationTime(filename, tile.CacheTime); File.SetLastWriteTime(filename, tile.CacheTime); File.SetLastAccessTime(filename, tile.CacheTime); } Say("Saving [" + i.ToString() + " of " + count.ToString() + "] " + filename); } catch (Exception ex) { Say(ex.Message); } i++; Application.DoEvents(); } Say("Ready."); }
private void createTile(int x, int y, eCountry country, MapTileData mapTileData) { GameObject go = Instantiate(tileData.GetTilePrefab(country), transform); go.name = "tile_" + x + "_" + y; go.transform.localScale = Vector3.one; go.transform.localPosition = GridToPosition(x, y); MapTile tile = go.GetComponent <MapTile>(); tile.type = mapTileData.type; tile.country = country; tile.SetOrder(getTileOrder(x, y)); tile.SetTile(x, y); tile.SetTapCallback(onTapTile); mapTiles[x + "_" + y] = tile; if (mapTileData.type == eTileType.CoreLand) { if (mapTileData.initCountry == eCountry.A) { go = Instantiate(Resources.Load <GameObject>("baseA"), transform); go.transform.localPosition = GridToPosition(x, y); go.GetComponent <SortingGroup>().sortingOrder = getObjOrder(x, y); } else if (mapTileData.initCountry == eCountry.B) { go = Instantiate(Resources.Load <GameObject>("baseB"), transform); go.transform.localPosition = GridToPosition(x, y); go.GetComponent <SortingGroup>().sortingOrder = getObjOrder(x, y); } } }
/// <summary> /// 방으로 설정한 부분을 배열 map에서 타일 설정 /// </summary> /// <param name="_Space"></param> public void SetRoom(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetRoom(_Space.left); SetRoom(_Space.right); } else { var roomType = _Space.roomType; for (int i = (int)_Space.room.x; i < _Space.room.xMax; i++) { for (int j = (int)_Space.room.y; j < _Space.room.yMax; j++) { map[i, j] = new MapTileData(roomType, (int)TileType.Floor, UnityEngine.Random.Range(0, tileRefernce[roomType].floorSprite.Count)); } } } }
public MapTile(int id, MapTileData data) { tile_id = id; this.data = data; }
public SpaceCalculator(Game game, MapTileData mtd) { LAGame = new Game(game); mapTileData = mtd; }
/// <summary> /// 방 노드를 모두 돌면서 테두리 생성 /// </summary> /// <param name="_Space"></param> private void SetRoomOutLine(Space _Space) { if (_Space == null) { return; } if (_Space.CheckLeaf()) { SetRoomOutLine(_Space.left); SetRoomOutLine(_Space.right); } else { var x = (int)_Space.room.x; var y = (int)_Space.room.y; var xMax = (int)_Space.room.xMax; var yMax = (int)_Space.room.yMax; var wallTileNum = (int)TileType.Wall; var roomType = _Space.roomType; for (int i = x - 1; i <= xMax; i++) { for (int j = y - 1; j <= yMax; j++) { if (map[i, j] == null) { if (i == x - 1 && j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.LeftBottom); } else if (i == x - 1 && j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.LeftTop); } else if (i == xMax && j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.RightBottom); } else if (i == xMax && j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.RightTop); } else if (i == x - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Left); } else if (j == y - 1) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Bottom); } else if (i == xMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Right); } else if (j == yMax) { map[i, j] = new MapTileData(roomType, wallTileNum, (int)Dir.Top); } } } } } }
public CollisionRepointer(Game game, MapTileData mtd) { LAGame = game; mapTileData = mtd; spaceCalculator = new SpaceCalculator(LAGame, mapTileData); }