void OnClick(Vector2 screenPos) { if (EditMode) { return; } if (_clickAnimationing) { return; } if (State == LodState.Lod0) { OnClickLod0(screenPos); EventManager.GetInstance().SendEvent(EventId.MapBlockSelected, screenPos); #if UNITY_EDITOR Coord c = Layout.ScreenPos2Coord(MapCamera, screenPos); MapTileVO data = ProxyManager.GetInstance().Get <MapProxy>().GetTile(c); LogModule.DebugLog(string.Format("coord:{0},height:{1},type:{2},blockType:{3},camp{4}", data.coord, data.height, data.type, data.blockType, data.camp)); #endif } else if (State == LodState.Lod1) { OnClickLod1(screenPos); } }
public void DoClickOnTile(Coord c) { MapTileVO mt = GameFacade.GetProxy <MapProxy>().GetTile(c); _clickAnimationing = true; Vector3 prePos = MapCamera.transform.localPosition; Vector3 lookPos = prePos + (Layout.HexCenter(c) - Layout.ScreenPos2WorldPos(MapCamera, MapInfoHighlightPos)); GoTweenConfig config = new GoTweenConfig(); FloatCallbackTweenProterty ftpy = new FloatCallbackTweenProterty(0, 1, delegate(float obj) { MoveCamera(Vector3.Lerp(prePos, lookPos, obj)); }); config.addTweenProperty(ftpy); config.onCompleteHandler = delegate(AbstractGoTween go) { _clickAnimationing = false; }; ShowHighLight(Layout.HexCenter(c)); Go.to(MapCamera.transform, 0.5f, config); if (onClickHandler != null) { onClickHandler(c); } }
Mesh CreateHexagonMeshWithoutUVColor() { Mesh mesh = new Mesh(); mesh.name = "Hexagon"; List <Vector3> vertices = new List <Vector3>(); List <int> triangles = new List <int>(); for (int col = 0; col < width; ++col) { for (int row = 0; row < height; ++row) { Coord local = new Coord(col, row); Coord world = new Coord(col + xMin, row + yMin); MapTileVO tileVo = GameFacade.GetProxy <MapProxy>().GetTile(world); if (tileVo != null) { AddHexagonVertices(vertices, triangles, layout.HexCenter(local)); } } } mesh.vertices = vertices.ToArray(); mesh.triangles = triangles.ToArray(); return(mesh); }
string SpriteNameInAtlas(MapTileVO tile) { return("west_0"); //switch (tile.type) //{ // case MapTileType.Block: // { // if (tile.blockType == MapBlockType.Sea) // { // return "sea_" + Mathf.Clamp(tile.camp1, 0, 4); // } // else if (tile.blockType == MapBlockType.Empty) // { // return MapTileVO.Camp2String(tile.camp) + "_empty"; // } // else // { // return MapTileVO.Camp2String(tile.camp) + "_block"; // } // } // case MapTileType.Camp: // case MapTileType.PVE: // { // return MapTileVO.Camp2String(tile.camp) + "_" + tile.level; // } // case MapTileType.Strait: // { // return "sea_" + Mathf.Clamp(tile.camp1, 0, 4); // } // default: // return ""; //} }
public static MapTileVO TileDecodeLocal(uint bin, Coord coord) { // mat-height-TileType-TileCamp-TileCamp1-TileLevel-PvELevel-BlockType // 4b- 4b - 4b - 4b - 4b - 4b - 4b - 4b MapTileVO tile = new MapTileVO(); if (mDecodeTestMode) { tile.mat = 1; tile.height = MapConst.MAP_HEIGHT_HORIZON; tile.type = MapTileType.Normal; tile.camp = 0; tile.camp1 = 0; tile.level = 0; tile.pveLevel = 0; tile.blockType = MapBlockType.None; } else { tile.mat = Convert.ToByte((bin & 0xf0000000) >> 28); tile.height = Convert.ToByte((bin & 0xf000000) >> 24); tile.type = (MapTileType)Convert.ToInt32((bin & 0xf00000) >> 20); tile.camp = Convert.ToInt32((bin & 0xf0000) >> 16); tile.camp1 = Convert.ToInt32((bin & 0xf000) >> 12); tile.level = Convert.ToInt32((bin & 0xf00) >> 8); tile.pveLevel = Convert.ToInt32((bin & 0xf0) >> 4); tile.blockType = (MapBlockType)Convert.ToInt32((bin & 0xf) >> 0); } tile.coord = coord; return(tile); }
// coordinate x/y and data x/y is opposite because: // when encoding to binary, the 1st demension of array represents line while the 2nd represents col, that is, // when we say (x, y) in binary data, we mean the xth line and yth col. // in the other hand, when we get tile by coord from binary, for example, coord is c, // in this case, c.x represents col and c.y represents line MapTileVO GetTile(int x, int y, byte[] bytes) { uint data = GetTileBytes(x, y, bytes); MapTileVO re = MapTileVO.TileDecodeLocal(data, new Coord(x, y)); return(re); }
//Seed All void OnMRBAction_Common() { MapTileVO tile = mapProxy.GetTile(mDst); ModifyVOByOp(tile); GameFacade.GetProxy <MapProxy>().SeedTile(tile); }
public static void DispMapStats(int[,] stats) { float total = MapConst.MAP_WIDTH * MapConst.MAP_HEIGHT; GUILayout.Label("camp\t | level | count | percent"); for (int camp = 0; camp < 4; ++camp) { for (int level = 0; level < 3; ++level) { GUILayout.Label(string.Format("{0:D4}", camp) + " " + MapTileVO.Camp2String(camp).Substring(0, 4) + "\t" + " | " + string.Format("{0:D5}", level) + " | " + string.Format("{0:D7}", stats[camp, level]) + " | " + stats[camp, level] / total * 100); } } GUILayout.Label("strait | " + string.Format("{0:D7}", stats[4, 0]) + " | " + stats[4, 0] / total * 100); GUILayout.Label("block | " + string.Format("{0:D7}", stats[4, 1]) + " | " + stats[4, 1] / total * 100); GUILayout.Label("neutral | " + string.Format("{0:D7}", stats[4, 2]) + " | " + stats[4, 2] / total * 100); }
void AddHexagonColor(List <Color> colors, MapTileVO tile) { for (int i = 0; i < layout.HexVertices.Length; ++i) { colors.Add(Color.white); } }
int GetMatNameInd(int thisCoordX, int thisCoordY, int neighborInd) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); if (neighborInd > 5 || neighborInd < 0) { Coord thisCoord = new Coord(thisCoordX, thisCoordY); byte thisMat = mapProxy.GetTile(thisCoord).mat; if (thisMat == 8) { thisMat = 0; } int thisMatNameNum = thisSprites[thisMat]; spriteIds[0] = thisMatNameNum; return(0); } Coord c_neighbor = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd); MapTileVO t_neighbor = mapProxy.GetTile(c_neighbor); if (t_neighbor == null) { return(-1); } byte m_neighbor = t_neighbor.mat; if (m_neighbor == 8) { m_neighbor = 0; } int neighborMatNameNum = -1; int neighborMatNameInd = -1; switch (neighborInd) { default: case 4: neighborMatNameNum = leftSprites[m_neighbor]; spriteIds[1] = neighborMatNameNum; neighborMatNameInd = 1; break; case 2: neighborMatNameNum = prevSprites[m_neighbor]; spriteIds[2] = neighborMatNameNum; neighborMatNameInd = 2; break; case 3: neighborMatNameNum = diagSprites[m_neighbor]; spriteIds[3] = neighborMatNameNum; neighborMatNameInd = 3; break; } return(neighborMatNameInd); }
public void ShowMarks(MapEditorEntry.EDIT_OP op, Color[] color) { if (mMarks == null) { mMarks = new SpriteRenderer[hex.xTile][]; } for (int x = 0; x < hex.xTile; ++x) { if (mMarks[x] == null) { mMarks[x] = new SpriteRenderer[hex.yTile]; } for (int y = 0; y < hex.yTile; ++y) { Coord c = new Coord(x + hex.xTile * xIdx, y + hex.yTile * yIdx); if (mapProxy == null) { mapProxy = GameFacade.GetProxy <MapProxy>(); } MapTileVO tileVo = mapProxy.GetTile(c); if (tileVo != null) { int index; if (op == MapEditorEntry.EDIT_OP.EDIT_AREA) { index = tileVo.camp; } else if (op == MapEditorEntry.EDIT_OP.EDIT_LV) { index = tileVo.level; } else { Debug.LogError("Error Op."); return; } if (index >= color.Length) { Debug.LogError("No defined color of this index."); return; } SpriteRenderer mark; if (mMarks[x][y] != null) { mMarks[x][y].color = color[index]; continue; } mark = GetAMark(); mark.color = color[index]; mark.transform.localPosition = layout.HexCenter(tileVo.coord) - transform.localPosition; mark.transform.localScale = new Vector3(1.5f, 1.55f, 1f); mark.transform.localEulerAngles = new Vector3(90f, 0f, 0f); mMarks[x][y] = mark; } } } markRoot.gameObject.SetActive(true); }
public static uint WayPointEncodeLocal(MapTileVO tile) { uint re = 0; re |= Convert.ToUInt32(Convert.ToUInt32(tile.coord.x) << 16); re |= Convert.ToUInt32(Convert.ToUInt32(tile.coord.y) << 4); re |= Convert.ToUInt32(Convert.ToUInt32(tile.camp) << 0); return(re); }
public MapTileVO[] GetWayPointsByCamp() { MapTileVO[] wayPoints = new MapTileVO[4]; foreach (MapTileVO wayPoint in _wayPoints) { wayPoints[wayPoint.camp] = wayPoint; } return(wayPoints); }
public List <int> GetSprLists(int x, int y) { if (x >= 0 && x < MapConst.MAP_SUBMAPS && y >= 0 && y < MapConst.MAP_SUBMAPS) { return(MapTileVO.TileSprDecodeLocal(_tilesSprs[y, x])); } else { return(null); } }
public static MapTileVO WayPointDecodeLocal(uint bin) { MapTileVO tile = new MapTileVO(); tile.camp = Convert.ToInt32((bin & 0xf) >> 0); Coord coord = new Coord(); coord.y = Convert.ToInt32((bin & 0xfff0) >> 4); coord.x = Convert.ToInt32((bin & 0xfff0000) >> 16); tile.coord = coord; return(tile); }
int GetMatNameInd(int thisCoordX, int thisCoordY, int neighborInd) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); if (neighborInd > 5 || neighborInd < 0) { Coord thisCoord = new Coord(thisCoordX, thisCoordY); byte thisMat = mapProxy.GetTile(thisCoord).mat; if (thisMat == 8) { thisMat = 0; } int thisMatNameNum = thisSprites[thisMat]; int thisMatNameInd = FindInSpriteIds(spriteIds, thisMatNameNum); return(thisMatNameInd); } Coord c_neighbor = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd); MapTileVO t_neighbor = mapProxy.GetTile(c_neighbor); if (t_neighbor == null) { return(-1); } byte m_neighbor = t_neighbor.mat; if (m_neighbor == 8) { m_neighbor = 0; } int neighborMatNameNum = -1; if (neighborInd == 4) { neighborMatNameNum = leftSprites[m_neighbor]; } else { if (thisCoordY % 2 == 0) { neighborMatNameNum = leftSprites[m_neighbor]; } else { neighborMatNameNum = thisSprites[m_neighbor]; } } int neighborMatNameInd = FindInSpriteIds(spriteIds, neighborMatNameNum); return(neighborMatNameInd); }
int GetNeighborHeight(int thisCoordX, int thisCoordY, int neighborInd) { int height_neighbor = -1; Coord c_neighbor = GetNeighborCoord(thisCoordX, thisCoordY, neighborInd); MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); MapTileVO t_neighbor = mapProxy.GetTile(c_neighbor); if (t_neighbor != null) { height_neighbor = t_neighbor.height; } return(height_neighbor); }
public static uint TileEncodeLocal(MapTileVO tile) { // mat-height-TileType-TileCamp-TileCamp1-TileLevel-PvELevel-BlockType // 4b- 4b - 4b - 4b - 4b - 4b - 4b - 4b uint re = 0; re |= Convert.ToUInt32(Convert.ToUInt32(tile.mat) << 28); re |= Convert.ToUInt32(Convert.ToUInt32(tile.height) << 24); re |= Convert.ToUInt32(Convert.ToUInt32(tile.type) << 20); re |= Convert.ToUInt32(Convert.ToUInt32(tile.camp) << 16); re |= Convert.ToUInt32(Convert.ToUInt32(tile.camp1) << 12); re |= Convert.ToUInt32(Convert.ToUInt32(tile.level) << 8); re |= Convert.ToUInt32(Convert.ToUInt32(tile.pveLevel) << 4); re |= Convert.ToUInt32(Convert.ToUInt32(tile.blockType) << 0); return(re); }
List <MapTileVO> GetWayPoints(byte[] bytes) { List <MapTileVO> wayPoints = new List <MapTileVO>(); int idx = 4 * MapConst.MAP_HEIGHT * MapConst.MAP_WIDTH; int realBytesLen = MapConst.MAP_HEIGHT * MapConst.MAP_WIDTH * 4 + 4 * 4; while (idx + 3 < bytes.Length && idx + 3 < realBytesLen) { uint data = 0; data |= Convert.ToUInt32(Convert.ToUInt32(bytes[idx]) << 0); data |= Convert.ToUInt32(Convert.ToUInt32(bytes[idx + 1]) << 8); data |= Convert.ToUInt32(Convert.ToUInt32(bytes[idx + 2]) << 16); data |= Convert.ToUInt32(Convert.ToUInt32(bytes[idx + 3]) << 24); wayPoints.Add(MapTileVO.WayPointDecodeLocal(data)); idx += 4; } return(wayPoints); }
void RefreshUVS() { if (null == uvs) { uvs = new Vector2[width * height * layout.HexUvs.Length]; } for (int col = 0; col < width; ++col) { for (int row = 0; row < height; ++row) { Coord world = new Coord(col + xMin, row + yMin); MapTileVO tileVo = GameFacade.GetProxy <MapProxy>().GetTile(world); if (null != tileVo) { AddHexagonUV((height * col + row) * layout.HexUvs.Length, tileVo); } } } }
Color[] GeteMeshColors() { List <Color> colors = new List <Color>(); for (int col = 0; col < width; ++col) { for (int row = 0; row < height; ++row) { Coord world = new Coord(col + xMin, row + yMin); MapTileVO tileVo = GameFacade.GetProxy <MapProxy>().GetTile(world); if (null != tileVo) { AddHexagonColor(colors, tileVo); } } } return(colors.ToArray()); }
SpriteRenderer CreateBlock(MapTileVO tile) { SpriteRenderer block = GameObjectPool.GetInstance().SpawnGo(blockTmp.gameObject).GetComponent <SpriteRenderer>(); block.gameObject.name = blockTmp.gameObject.name; int blockIdx = Mathf.Clamp(tile.camp1, 0, 2); if (tile.blockType == MapBlockType.Mountain) { block.sprite = mapSprites.Get(MapTileVO.Camp2String(tile.camp) + "_mountain_" + blockIdx); } else if (tile.blockType == MapBlockType.Forest) { block.sprite = mapSprites.Get(MapTileVO.Camp2String(tile.camp) + "_tree_" + blockIdx); } return(block); }
void AddHexagonUV(int startIdx, MapTileVO tile) { int key = ((int)tile.type << 24) + ((int)tile.blockType << 16) + ((int)tile.camp << 8) + tile.level + (tile.camp1 << 28); UISpriteData spd = null; if (!spdDataMap.TryGetValue(key, out spd)) { string name = SpriteNameInAtlas(tile); spd = mapTileAtlas.GetSprite(name); if (spd == null) { Debug.LogError("# Cant Get Sprite " + name + " in Atlas " + mapTileAtlas.name); } spdDataMap.Add(key, spd); } float atlasSide = mapTileAtlas.texture.height; float uvl = 0f; //if (spd.rotated){ // uvl = spd.width / atlasSide / 2f; //}else{ uvl = spd.height / atlasSide / 2f; //} uvl = 256f / atlasSide / 2f; float cx = (spd.x + spd.width / 2f) / atlasSide; float cy = 1f - (spd.y + spd.height / 2f) / atlasSide; Vector2 cen = new Vector2(cx, cy); for (int i = 0; i < layout.HexUvs.Length; ++i) { var hexUV = layout.HexUvs[i]; //if (spd.rotated){ // Vector2 rotatedUV = new Vector2(hexUV.y, - hexUV.x); // uvs[startIdx + i] = cen + rotatedUV * uvl; //}else{ uvs[startIdx + i] = cen + hexUV * uvl; //} } }
void MarkTileDirectionAndLevel(MapTileVO vo) { int dl = 0; if (vo.camp != 0) { dl = vo.camp * 10 + vo.level; } if (_regions.ContainsKey(dl)) { if (_regions[dl].Contains(new Vector2(vo.coord.x, vo.coord.y))) { } else { Rect current = _regions[dl]; if (vo.coord.x < current.x) { current.x = vo.coord.x; } else if (vo.coord.x > current.x + current.width) { current.width = vo.coord.x - current.x; } if (vo.coord.y < current.y) { current.y = vo.coord.y; } else if (vo.coord.y > current.y + current.height) { current.height = vo.coord.y - current.y; } _regions[dl] = current; } } else { _regions.Add(dl, new Rect(vo.coord.x, vo.coord.y, 1, 1)); } }
public void InitBlocks() { for (int x = 0; x < xTileCnt; ++x) { for (int y = 0; y < yTileCnt; ++y) { Coord c = new Coord(x + xTileCnt * xIdx, y + yTileCnt * yIdx); MapTileVO tileVo = GameFacade.GetProxy <MapProxy>().GetTile(c); if (tileVo != null) { if (!tileVo.IsWater()) { SpriteRenderer block = CreateBlock(tileVo); block.transform.parent = blockRoot; block.gameObject.SetActive(true); block.transform.localPosition = layout.HexCenter(tileVo.coord) - this.transform.localPosition; blocks.Add(c, block); } } } } }
public MapTileVO GetTile(int x, int y) { if (x >= 0 && x < MapConst.MAP_WIDTH && y >= 0 && y < MapConst.MAP_HEIGHT) { #if UNITY_EDITOR if (!useEditorDataSource) { return(MapTileVO.TileDecodeLocal(_tiles[y, x], new Coord(x, y))); } else { return(_editorTiles[y, x]); } #else return(MapTileVO.TileDecodeLocal(_tiles[y, x], new Coord(x, y))); #endif } else { return(null); } }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } element e = new element(); _reindex reindex = (ref element _elm, int _ver, int _col, int _row, float tmpindex, Vector2 uv2) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; //if (idx >= 0) // return idx; idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; /* * // sz test * if(_x==0 && _y==0) * { * m=0; * } * else if(_x==1 && _y==0) * { * m=0; * } * else if(_x==0 && _y==1) * { * m=0; * } * else if(_x==1 && _y==1) * { * m=0; * } * // sz test */ int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _c = sc[0]; _t = vc[0]; } else { _c = sc[m <= 3 ? m + 1 : 0]; _t = vc[m >= 4 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon[_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(_c); if (tmpindex < 100) { _t.z = tmpindex; } else { _t.w = (int)tmpindex / 100; _t.z = tmpindex - _t.w * 100; } _elm.vTan.Add(_t); _elm.vTex.Add(_u); _elm.vNorTex.Add(uv2); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); List <int> vBld = new List <int>(); bool pass = true; Color R = new Color(1, 0, 0, 1); Color G = new Color(0, 1, 0, 1); Color B = new Color(0, 0, 1, 1); Color C1 = new Color(1, 1, 1, 1); Color C0 = new Color(0, 0, 0, 0); Vector4 V1 = new Vector4(1, 1, 1, 1); Vector4 V0 = new Vector4(0, 0, 0, 0); Vector2 uv2_zero = new Vector2(0, 0); /*Vector2 uv2_normal_block0_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_block0_5 = new Vector2(0.743f, 0.643f); * Vector2 uv2_normal_block0_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_block0_3 = new Vector2(0.755f, 0.357f); * Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); * Vector2 uv2_normal_hex_5 = new Vector2(0.746f, 0.643f); * Vector2 uv2_normal_hex_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); * Vector2 uv2_normal_hex_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_hex_3 = new Vector2(0.755f, 0.357f); * Vector2 uv2_normal_tri_6 = new Vector2(0.251f, 0.643f); * Vector2 uv2_normal_tri_2 = new Vector2(0.259f, 0.357f); * Vector2 uv2_normal_tri_4 = new Vector2(0.003f, 0.523f); * Vector2 uv2_normal_tri_5 = new Vector2(0.746f, 0.643f); * Vector2 uv2_normal_tri_1 = new Vector2(0.998f, 0.509f); * Vector2 uv2_normal_tri_3 = new Vector2(0.755f, 0.357f);*/ Vector2 uv2_normal_block0_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_block0_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_block0_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_block0_3 = new Vector2(0.668f, 0.250f); Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); Vector2 uv2_normal_hex_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_hex_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); Vector2 uv2_normal_hex_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_hex_3 = new Vector2(0.668f, 0.250f); Vector2 uv2_normal_tri_6 = new Vector2(0.324f, 0.670f); Vector2 uv2_normal_tri_2 = new Vector2(0.329f, 0.249f); Vector2 uv2_normal_tri_4 = new Vector2(0.154f, 0.494f); Vector2 uv2_normal_tri_5 = new Vector2(0.662f, 0.670f); Vector2 uv2_normal_tri_1 = new Vector2(0.843f, 0.485f); Vector2 uv2_normal_tri_3 = new Vector2(0.668f, 0.250f); /*Vector2 uv2_normal_block0_6 = new Vector2(0.326f, 0.668f); * Vector2 uv2_normal_block0_5 = new Vector2(0.660f, 0.668f); * Vector2 uv2_normal_block0_2 = new Vector2(0.331f, 0.251f); * Vector2 uv2_normal_block0_3 = new Vector2(0.666f, 0.252f); * Vector2 uv2_normal_hex_0 = new Vector2(0.5f, 1.0f); * Vector2 uv2_normal_hex_5 = new Vector2(0.662f, 0.670f); * Vector2 uv2_normal_hex_6 = new Vector2(0.324f, 0.670f); * Vector2 uv2_normal_hex_00 = new Vector2(0.5f, 0.0f); * Vector2 uv2_normal_hex_2 = new Vector2(0.329f, 0.249f); * Vector2 uv2_normal_hex_3 = new Vector2(0.668f, 0.250f); * Vector2 uv2_normal_tri_6 = new Vector2(0.326f, 0.672f); * Vector2 uv2_normal_tri_2 = new Vector2(0.331f, 0.247f); * Vector2 uv2_normal_tri_4 = new Vector2(0.152f, 0.494f); * Vector2 uv2_normal_tri_5 = new Vector2(0.660f, 0.668f); * Vector2 uv2_normal_tri_1 = new Vector2(0.845f, 0.485f); * Vector2 uv2_normal_tri_3 = new Vector2(0.666f, 0.252f);*/ for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { /*if(!(x==1 && y==1 || x== && y==1)) * { * continue; * }*/ /*if (_x == 1 && _y == 1 && (x < 11 || y < 6)) * { * continue; * }*/ // get height info int thisCoordX = x + _xTile * _x; int thisCoordY = y + _yTile * _y; Coord c = new Coord(thisCoordX, thisCoordY); int thisHeight = mapProxy.GetTile(c).height; int height_neighbor0 = GetNeighborHeight(thisCoordX, thisCoordY, 0); int height_neighbor1 = GetNeighborHeight(thisCoordX, thisCoordY, 1); int height_neighbor2 = GetNeighborHeight(thisCoordX, thisCoordY, 2); int height_neighbor3 = GetNeighborHeight(thisCoordX, thisCoordY, 3); int height_neighbor4 = GetNeighborHeight(thisCoordX, thisCoordY, 4); int height_neighbor5 = GetNeighborHeight(thisCoordX, thisCoordY, 5); // block5 left Vector2 uv2_hex0_0 = new Vector2(0.0f, 0.5f); Vector2 uv2_hex0_1 = new Vector2(0.375f, 0.211f); Vector2 uv2_hex0_2 = new Vector2(0.375f, 0.785f); // block0 right Vector2 uv2_hex3_0 = new Vector2(1.0f, 0.5f); Vector2 uv2_hex3_4 = new Vector2(0.621f, 0.785f); Vector2 uv2_hex3_5 = new Vector2(0.621f, 0.211f); float[] hex_index1 = { 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 2.5f, 2.5f, 2.5f, 1.5f, 1.5f, 1.5f, 0.5f, 0.5f, 0.5f, 2.5f, 2.5f, 2.5f, }; Vector2[] hex_index2 = { uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex0_0, uv2_hex0_1, uv2_hex0_1, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, uv2_hex3_0, uv2_hex3_4, uv2_hex3_5, }; float heightCompare0 = CompareHeight(thisHeight, height_neighbor0); float heightCompare1 = CompareHeight(thisHeight, height_neighbor1); float heightCompare2 = CompareHeight(thisHeight, height_neighbor2); float heightCompare3 = CompareHeight(thisHeight, height_neighbor3); float heightCompare4 = CompareHeight(thisHeight, height_neighbor4); float heightCompare5 = CompareHeight(thisHeight, height_neighbor5); float[] hex_index3 = { thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare0, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare1, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare2, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare3, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare4, thisHeight *100 + heightCompare5, thisHeight *100 + heightCompare5, thisHeight *100 + heightCompare5, }; Vector2[] hex_index4 = { uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_00, uv2_normal_hex_2, uv2_normal_hex_3, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, uv2_normal_hex_0, uv2_normal_hex_5, uv2_normal_hex_6, }; // hexgon for (int i = 0; i < nHexIndices; i++) { if (recheck(tdx[i], x, y) == true) { //vIdx.Add(reindex(ref e, tdx[i], x, y, hex_index3[i], hex_index4[i])); vIdx.Add(reindex(ref e, tdx[i], x, y, 4.5f, hex_index4[i])); } } // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { Vector2 uv2_block0_6 = new Vector2(0.621f, 0.211f); Vector2 uv2_block0_5 = new Vector2(0.621f, 0.785f); Vector2 uv2_block0_3 = new Vector2(0.375f, 0.785f); Vector2 uv2_block0_2 = new Vector2(0.375f, 0.211f); Vector2 uv2_tri0_6 = new Vector2(0.621f, 0.211f); Vector2 uv2_tri0_2 = new Vector2(0.375f, 0.211f); Vector2 uv2_tri0_4 = new Vector2(0.5f, 0.0f); Vector2 uv2_tri5_5 = new Vector2(0.621f, 0.785f); Vector2 uv2_tri5_1 = new Vector2(0.5f, 1.0f); Vector2 uv2_tri5_3 = new Vector2(0.375f, 0.785f); // block 4 pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); bool bBld = false; if (x == 0 && isBlend) { bBld = true; } if (pass == true && !bBld) { /*vSub.Add( reindex(ref e, edx[0][0] - nIndexOffset, x, y, 0.5f, uv2_block0_6) ); * vSub.Add( reindex(ref e, edx[0][1] - nIndexOffset, x, y, 0.5f, uv2_block0_5) ); * vSub.Add( reindex(ref e, edx[0][2] - nIndexOffset, ww, y, 0.5f, uv2_block0_2) );*/ vSub.Add(reindex(ref e, edx[0][0] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[0][1] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[0][2] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == true && !bBld) { /*vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y, 0.5f, uv2_block0_3)); * vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y, 0.5f, uv2_block0_2)); * vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y, 0.5f, uv2_block0_5));*/ vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y, heightCompare4, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y, heightCompare4, uv2_normal_block0_5)); } // tri 4 if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); Vector2 v0_uv = new Vector2(); Vector2 v1_uv = new Vector2(); Vector2 v2_uv = new Vector2(); int heightCompare_type = CompareHeight_Tri0(height_neighbor5, height_neighbor4, thisHeight); float heightCompare_tri0 = 0; switch (heightCompare_type) { case 0: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_3; v1_uv = uv2_normal_tri_5; v2_uv = uv2_normal_tri_1; break; case 1: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; case 2: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 3: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_6; v1_uv = uv2_normal_tri_2; v2_uv = uv2_normal_tri_4; break; case 4: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 5: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; default: heightCompare_tri0 = 4.5f; break; } if (pass == true && !bBld) { //if (heightCompare_type == 3) { /*vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y, 0.5f, uv2_tri0_6)); * vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y, 0.5f, uv2_tri0_2)); * vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y+1, 0.5f, uv2_tri0_4));*/ vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y, heightCompare_tri0, v0_uv)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y, heightCompare_tri0, v2_uv)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y + 1, heightCompare_tri0, v1_uv)); } } } // tri 3 if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); Vector2 v0_uv = new Vector2(); Vector2 v1_uv = new Vector2(); Vector2 v2_uv = new Vector2(); int heightCompare_type = CompareHeight_Tri0(height_neighbor3, thisHeight, height_neighbor4); float heightCompare_tri0 = 0; switch (heightCompare_type) { case 0: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_1; v1_uv = uv2_normal_tri_3; v2_uv = uv2_normal_tri_5; break; case 1: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; case 2: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 3: heightCompare_tri0 = 5.5f; v0_uv = uv2_normal_tri_6; v1_uv = uv2_normal_tri_2; v2_uv = uv2_normal_tri_4; break; case 4: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_2; v1_uv = uv2_normal_tri_4; v2_uv = uv2_normal_tri_6; break; case 5: heightCompare_tri0 = 3.5f; v0_uv = uv2_normal_tri_5; v1_uv = uv2_normal_tri_1; v2_uv = uv2_normal_tri_3; break; default: heightCompare_tri0 = 4.5f; break; } if (y == 0 && isBlend) { bBld = true; } float heightCompare_tri5 = 4.5f; if (heightCompare3 != 4.5f) { heightCompare_tri5 = heightCompare3; } if (heightCompare4 != 4.5f) { heightCompare_tri5 = heightCompare4; } if (pass == true && !bBld) { /*vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y, 0.5f, uv2_tri5_5)); * vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y-1, 0.5f, uv2_tri5_1)); * vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y, 0.5f, uv2_tri5_3));*/ vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y, heightCompare_tri5, v0_uv)); vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y - 1, heightCompare_tri5, v1_uv)); vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y, heightCompare_tri5, v2_uv)); } } } if (IsValid(sw, y - 1)) { Vector2 uv2_block5_5 = new Vector2(0.621f, 0.211f); Vector2 uv2_block5_4 = new Vector2(0.621f, 0.785f); Vector2 uv2_block5_2 = new Vector2(0.375f, 0.785f); Vector2 uv2_block5_1 = new Vector2(0.375f, 0.211f); // block 3 pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); bool bBld = false; if ((x == 0 && y % 2 == 0 || y == 0) && isBlend) { bBld = true; } if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[1][0] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[1][1] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[1][2] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[1][3] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[1][4] - nIndexOffset, sw, y - 1, heightCompare3, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[1][5] - nIndexOffset, x, y, heightCompare3, uv2_normal_block0_5)); } } if (IsValid(nw, y + 1)) { Vector2 uv2_block1_1 = new Vector2(0.621f, 0.211f); Vector2 uv2_block1_6 = new Vector2(0.621f, 0.785f); Vector2 uv2_block1_4 = new Vector2(0.375f, 0.785f); Vector2 uv2_block1_3 = new Vector2(0.375f, 0.211f); // block 5 pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); bool bBld = false; if (x == 0 && y % 2 == 0 && isBlend) { bBld = true; } if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_6)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_5)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_2)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == true && !bBld) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_3)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, nw, y + 1, heightCompare5, uv2_normal_block0_2)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y, heightCompare5, uv2_normal_block0_5)); } } } } Mesh me = new Mesh(); me.subMeshCount = 3; me.vertices = e.vHex.ToArray(); me.SetTriangles(vIdx.ToArray(), 0); me.SetTriangles(vSub.ToArray(), 1); me.SetTriangles(vBld.ToArray(), 2); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.uv2 = e.vNorTex.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterials = _hex.GetTerrainMats(); //mr.SetPropertyBlock(UpdateBlock()); }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } element e = new element(); _reindex_Blend reindex_Blend = (ref element _elm, int _ver, int _col, int _row, Color BlendColor, Vector4 BlendTangent) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; //if (idx >= 0) // return idx; idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _c = sc[0]; _t = vc[0]; } else { _c = sc[m <= 3 ? m + 1 : 0]; _t = vc[m >= 4 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon[_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(BlendColor); _elm.vTan.Add(BlendTangent); _elm.vTex.Add(_u); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); List <int> vBld = new List <int>(); bool pass = true; Color C1000 = new Color(1, 0, 0, 0); Color C0000 = new Color(0, 0, 0, 0); Color C0001 = new Color(0, 0, 0, 1); Color C0010 = new Color(0, 0, 1, 0); Color C0100 = new Color(0, 1, 0, 0); Color C1010 = new Color(1, 0, 1, 0); Color C0110 = new Color(0, 1, 1, 0); Color C1111 = new Color(1, 1, 1, 1); for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { /*if (!(_x == 1 && _y == 0 && x == 0 && (y >= 11 && y < 15))) * { * continue; * }*/ /*if (!(_x == 1 && _y == 1 && x == 0 && (y >= 1 && y < 5))) * { * continue; * }*/ int thisCoordX = x + _xTile * _x; int thisCoordY = y + _yTile * _y; int thisMatNameInd = GetMatNameInd(thisCoordX, thisCoordY, -1); // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { // block 4 int neighbor4MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 4); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, -1, -1); pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); bool bBld = false; if (x == 0) { bBld = true; } if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[0][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][2] - nIndexOffset, ww, y, C0100, tangent)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[0][3] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][4] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[0][5] - nIndexOffset, x, y, C1000, tangent)); } // tri 4 int neighbor5MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 5); tangent = new Vector4(thisMatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, neighbor5MatNameInd * 0.1f, -1); if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[3][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][1] - nIndexOffset, ww, y, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][2] - nIndexOffset, nw, y + 1, C0010, tangent)); } } // tri 3 int neighbor3MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 3); tangent = new Vector4(thisMatNameInd * 0.1f, neighbor3MatNameInd * 0.1f, neighbor4MatNameInd * 0.1f, -1); if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag tri 3 } else { vBld.Add(reindex_Blend(ref e, edx[3][3] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][4] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[3][5] - nIndexOffset, ww, y, C0010, tangent)); } } } } if (IsValid(sw, y - 1)) { // block 3 int neighbor3MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 3); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor3MatNameInd * 0.1f, -1, -1); bool bBld = false; if (x == 0 && y % 2 == 0) { bBld = true; } pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag block 3 } else { vBld.Add(reindex_Blend(ref e, edx[1][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][2] - nIndexOffset, sw, y - 1, C0100, tangent)); } } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == true && bBld) { if (x == 0 && y == 0) { // diag block 3 } else { vBld.Add(reindex_Blend(ref e, edx[1][3] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][4] - nIndexOffset, sw, y - 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[1][5] - nIndexOffset, x, y, C1000, tangent)); } } } if (IsValid(nw, y + 1)) { // block 5 int neighbor5MatNameInd = GetMatNameInd(thisCoordX, thisCoordY, 5); Vector4 tangent = new Vector4(thisMatNameInd * 0.1f, neighbor5MatNameInd * 0.1f, -1, -1); bool bBld = false; if (x == 0 && y % 2 == 0) { bBld = true; } pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[2][0] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][1] - nIndexOffset, x, y, C1000, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][2] - nIndexOffset, nw, y + 1, C0100, tangent)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == true && bBld) { vBld.Add(reindex_Blend(ref e, edx[2][3] - nIndexOffset, nw, y + 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][4] - nIndexOffset, nw, y + 1, C0100, tangent)); vBld.Add(reindex_Blend(ref e, edx[2][5] - nIndexOffset, x, y, C1000, tangent)); } } } } Mesh me = new Mesh(); me.subMeshCount = 1; me.vertices = e.vHex.ToArray(); //me.SetTriangles(vIdx.ToArray(), 0); //me.SetTriangles(vSub.ToArray(), 1); me.SetTriangles(vBld.ToArray(), 0); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterial = _hex.GetTerrainBlendMat(); //mr.SetPropertyBlock(UpdateBlock()); }
void GenHexMesh(HEX _hex) { MapProxy mapProxy = GameFacade.GetProxy <MapProxy>(); Vector3[] hexgon = { #if HEXGON0 new Vector3(0, 0, 0), // 0 #endif new Vector3(0, +1, 0), // 1 new Vector3(+Tx, +Ty, 0), // 2 new Vector3(+Tx, -Ty, 0), // 3 new Vector3(0, -1, 0), // 4 new Vector3(-Tx, -Ty, 0), // 5 new Vector3(-Tx, +Ty, 0), // 6 }; Vector2[] water = { new Vector2(0, 0), new Vector2(1, 0), }; Color[] sc = { new Color(0, 0, 0, 0), new Color(1, 0, 0, 0), new Color(0, 1, 0, 0), new Color(0, 0, 1, 0), new Color(0, 0, 0, 1), }; Vector4[] vc = { new Vector4(0, 0, 0, 0), new Vector4(1, 0, 0, 0), new Vector4(0, 1, 0, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1), }; int siz = (_hex.yTile + 1) * (_hex.yTile + 1) * 8; if (lst == null) { lst = new int[siz]; } for (int i = 0; i < siz; i++) { lst[i] = -1; } welement e = new welement(); _reindex reindex = (ref welement _elm, int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); int loc = ((_row + 1) * (_hex.xTile + 1) + (_col + 1)) * 8 + _ver; int idx = lst[loc]; if (idx >= 0) { return(idx); } idx = _elm.vHex.Count; lst[loc] = idx; Vector3 _v = Vector3.zero; Vector3 _n = Vector3.zero; Vector4 _t = Vector4.zero; Vector2 _u = Vector2.zero; Color _c; Vector2 _waterColor; float _R = Tx * 2.0f + _hex.fvHex.x; int m = tileVo.mat; int n = isGenHeight ? tileVo.height : MapConst.MAP_HEIGHT_HORIZON; if (m == 8) { _waterColor = water[1]; _c = sc [0]; _t = vc [0]; } else { _waterColor = water[0]; _c = sc [m < 4 ? m + 1 : 0]; _t = vc [m > 3 ? m - 3 : 0]; } _v.x = _R * _col; _v.y = _R * Tx * _row; _v.z = n; _n.z = m; if (_row % 2 == 0) { _v.x += 0.0f; } else { _v.x += Tx + Ty * _hex.fvHex.x; } _elm.vHex.Add(hexgon [_ver] + _v); _elm.vNor.Add(_n); _elm.vClr.Add(_c); _elm.vTan.Add(_t); _elm.vTex.Add(_u); _elm.vWater.Add(_waterColor); _elm.hasFoam.Add(new Vector2(tileVo.blockType == MapBlockType.WaterWave ? 1 : 0, 0)); return(idx); }; _recheck recheck = (int _ver, int _col, int _row) => { MapTileVO tileVo = mapProxy.GetTile(_col + _hex.xTile * _x, _row + _hex.yTile * _y); //if (tileVo.mat < 1) if (tileVo.IsWater()) { return(false); } return(true); }; int nHexIndices, nIndexOffset; #if HEXGON0 int[] tdx = { 0, 1, 2, 0, 2, 3, 0, 3, 4, 0, 4, 5, 0, 5, 6, 0, 6, 1, }; nHexIndices = 18; nIndexOffset = 0; #else int[] tdx = { 0, 1, 5, 5, 1, 4, 2, 4, 1, 3, 4, 2 }; nHexIndices = 12; nIndexOffset = 1; #endif int[][] edx = { new int[] { 6, 5, 2, 3, 2, 5 }, new int[] { 5, 4, 1, 2, 1, 4 }, new int[] { 1, 6, 3, 4, 3, 6 }, new int[] { 6, 2, 4, 5, 1, 3 }, }; List <int> vIdx = new List <int>(); List <int> vSub = new List <int>(); bool pass = true; for (int y = 0; y < _yTile; y++) { for (int x = 0; x < _xTile; x++) { for (int i = 0; i < nHexIndices; i++) { if (recheck(tdx[i], x, y) == false) { vIdx.Add(reindex(ref e, tdx[i], x, y)); } } // west -> x-1 // south west -> odd : x, y-1 even: x-1, y-1 // south -> odd: x+1, y-1 even: x, y-1 int t = y % 2; int ww = x - 1; // y int sw = t > 0 ? x : x - 1; // y-1 int nw = t > 0 ? x : x - 1; // y+1 if (IsValid(ww, y)) { pass = true; pass &= recheck(edx[0][0] - nIndexOffset, x, y); pass &= recheck(edx[0][1] - nIndexOffset, x, y); pass &= recheck(edx[0][2] - nIndexOffset, ww, y); if (pass == false) { vSub.Add(reindex(ref e, edx[0][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[0][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[0][2] - nIndexOffset, ww, y)); } pass = true; pass &= recheck(edx[0][3] - nIndexOffset, ww, y); pass &= recheck(edx[0][4] - nIndexOffset, ww, y); pass &= recheck(edx[0][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[0][3] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[0][4] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[0][5] - nIndexOffset, x, y)); } if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y); pass &= recheck(edx[3][1] - nIndexOffset, ww, y); pass &= recheck(edx[3][2] - nIndexOffset, nw, y + 1); if (pass == false) { vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, ww, y)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, nw, y + 1)); } } if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[3][3] - nIndexOffset, x, y); pass &= recheck(edx[3][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[3][5] - nIndexOffset, ww, y); if (pass == false) { vSub.Add(reindex(ref e, edx[3][3] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[3][4] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[3][5] - nIndexOffset, ww, y)); } } } if (IsValid(sw, y - 1)) { pass = true; pass &= recheck(edx[1][0] - nIndexOffset, x, y); pass &= recheck(edx[1][1] - nIndexOffset, x, y); pass &= recheck(edx[1][2] - nIndexOffset, sw, y - 1); if (pass == false) { vSub.Add(reindex(ref e, edx[1][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[1][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[1][2] - nIndexOffset, sw, y - 1)); } pass = true; pass &= recheck(edx[1][3] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][4] - nIndexOffset, sw, y - 1); pass &= recheck(edx[1][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[1][3] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[1][4] - nIndexOffset, sw, y - 1)); vSub.Add(reindex(ref e, edx[1][5] - nIndexOffset, x, y)); } } if (IsValid(nw, y + 1)) { pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y); pass &= recheck(edx[2][1] - nIndexOffset, x, y); pass &= recheck(edx[2][2] - nIndexOffset, nw, y + 1); if (pass == false) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, nw, y + 1)); } pass = true; pass &= recheck(edx[2][3] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][4] - nIndexOffset, nw, y + 1); pass &= recheck(edx[2][5] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, nw, y + 1)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, nw, y + 1)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y)); } } if (y == 0) { // we only patch west, north west, south west, which leaves crack in zero line if (IsValid(x, y - 1)) { pass = true; pass &= recheck(edx[2][3] - nIndexOffset, x, y); pass &= recheck(edx[2][4] - nIndexOffset, x, y); pass &= recheck(edx[2][5] - nIndexOffset, x, y - 1); if (pass == false) { vSub.Add(reindex(ref e, edx[2][3] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][4] - nIndexOffset, x, y)); vSub.Add(reindex(ref e, edx[2][5] - nIndexOffset, x, y - 1)); } pass = true; pass &= recheck(edx[2][0] - nIndexOffset, x, y - 1); pass &= recheck(edx[2][1] - nIndexOffset, x, y - 1); pass &= recheck(edx[2][2] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[2][0] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[2][1] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[2][2] - nIndexOffset, x, y)); } if (IsValid(x - 1, y - 1)) { pass = true; pass &= recheck(edx[3][0] - nIndexOffset, x, y - 1); pass &= recheck(edx[3][1] - nIndexOffset, x - 1, y - 1); pass &= recheck(edx[3][2] - nIndexOffset, x, y); if (pass == false) { vSub.Add(reindex(ref e, edx[3][0] - nIndexOffset, x, y - 1)); vSub.Add(reindex(ref e, edx[3][1] - nIndexOffset, x - 1, y - 1)); vSub.Add(reindex(ref e, edx[3][2] - nIndexOffset, x, y)); } } } } } } Mesh me = new Mesh(); me.subMeshCount = 2; me.vertices = e.vHex.ToArray(); me.SetTriangles(vIdx.ToArray(), 0); me.SetTriangles(vSub.ToArray(), 1); me.normals = e.vNor.ToArray(); me.colors = e.vClr.ToArray(); me.tangents = e.vTan.ToArray(); me.uv = e.vTex.ToArray(); me.uv2 = e.vWater.ToArray(); me.uv3 = e.hasFoam.ToArray(); me.bounds = _bound; var mf = gameObject.GetComponent <MeshFilter>(); if (mf == null) { mf = gameObject.AddComponent <MeshFilter>(); } mf.sharedMesh = me; var mr = gameObject.GetComponent <MeshRenderer>(); if (mr == null) { mr = gameObject.AddComponent <MeshRenderer>(); } mr.shadowCastingMode = UnityEngine.Rendering.ShadowCastingMode.Off; mr.sharedMaterials = _hex.GetWaterMats(); //mr.SetPropertyBlock(UpdateBlock()); }
//public static MapTileVO[,] GeneratePVETiles(MapTileVO[,] tileVOs){ // // Generate PvETiles from GDS // var pveStats = TableManager.GetPVETile(); // // Generate tileVOs Mapping // Dictionary<int, Dictionary<int, List<string>>> tileMapping = new Dictionary<int, Dictionary<int, List<string>>>(); // TileType: TileCamp -> x_y // for (int y=0; y<MapConst.MAP_HEIGHT; ++y) { // for (int x=0; x<MapConst.MAP_WIDTH; ++x) { // var tileVO = tileVOs[y, x] as MapTileVO; // var tileType = Convert.ToInt32(tileVO.type); // var tileLevel = Convert.ToInt32(tileVO.level); // if (tileVO.IsNeutral()) { // tileType = 10; // tileLevel = 0; // } // if(tileMapping.ContainsKey(tileType) == false) { // tileMapping[tileType] = new Dictionary<int, List<string>>(); // } // if (tileMapping[tileType].ContainsKey(tileLevel) == false) { // tileMapping[tileType][tileLevel] = new List<string>(); // } // tileMapping[tileType][tileLevel].Add(String.Join("_", new string[]{x.ToString(), y.ToString()})); // } // } // // Generate PvE tile // foreach(List<Tab_PVETile> pveTiles in pveStats.Values) // { // if (pveTiles.Count <= 0) continue; // Tab_PVETile pveTile = pveTiles[0]; // System.Random random = new System.Random(); // List<string> newList = new List<string>(); // try{ // var tileType = Convert.ToInt32(pveTile.map_region); // var tileLevel = Convert.ToInt32(pveTile.camp_region); // if (tileType == 4) { // Former Neutral Tiles // tileType = 10; // tileLevel = 0; // } // foreach (string coordXY in tileMapping[tileType][tileLevel]) // { // newList.Insert(random.Next(newList.Count), coordXY); // } // var totalQty = pveTile.total_quantity; // int i = 0; // while (i < totalQty) { // string[] coords = newList[i].Split('_'); // if (tileVOs[Convert.ToInt32(coords[1]), Convert.ToInt32(coords[0])].type != MapTileType.PVE) { // tileVOs[Convert.ToInt32(coords[1]), Convert.ToInt32(coords[0])].pveLevel = pveTile.pve_tile_level; // tileVOs[Convert.ToInt32(coords[1]), Convert.ToInt32(coords[0])].type = MapTileType.PVE; // tileVOs[Convert.ToInt32(coords[1]), Convert.ToInt32(coords[0])].camp1 = random.Next(3); // i++; // } else { // i++; // totalQty++; // } // } // } catch(Exception e) { // Debug.LogWarning(e); // Debug.LogWarning(Newtonsoft.Json.JsonConvert.SerializeObject(pveTile)); // Debug.LogWarning(Newtonsoft.Json.JsonConvert.SerializeObject(tileMapping.Keys)); // } // } // return tileVOs; //} public static void GenerateMapTilesLocal(MapTileVO[,] tileVOs, List <MapTileVO> wayPoints, uint[,] sprs) { // Rewrite Source Map Binary FileStream fs = File.Open(Application.dataPath + "/Resources/" + MapPrefabDef.MapSource + ".bytes", FileMode.OpenOrCreate, FileAccess.Write); BinaryWriter bw = new BinaryWriter(fs, System.Text.Encoding.BigEndianUnicode); for (int y = 0; y < MapConst.MAP_HEIGHT; ++y) { for (int x = 0; x < MapConst.MAP_WIDTH; ++x) { // mat-height-TileType-TileCamp-TileCamp1-TileLevel-PvELevel-BlockType // 4b- 4b - 4b - 4b - 4b - 4b - 4b - 4b try { uint tileInfo = MapTileVO.TileEncodeLocal(tileVOs[y, x]); bw.Write(tileInfo); } catch (Exception e) { Debug.Log(tileVOs[y, x].camp); Debug.Log((int)tileVOs[y, x].type); Debug.Log(tileVOs[y, x].level); throw e; } } } if (wayPoints != null) { foreach (MapTileVO wayPoint in wayPoints) { try { uint tileInfo = MapTileVO.WayPointEncodeLocal(wayPoint); bw.Write(tileInfo); } catch (Exception e) { Debug.Log("writing waypoint error: " + wayPoint.coord.x + ", " + wayPoint.coord.y); throw e; } } } bw.Close(); // Rewrite Map Binary with PvE Tiles //tileVOs = GeneratePVETiles(tileVOs); fs = File.Open(Application.dataPath + "/Resources/" + MapPrefabDef.MapUint16 + ".bytes", FileMode.OpenOrCreate, FileAccess.Write); bw = new BinaryWriter(fs, System.Text.Encoding.BigEndianUnicode); for (int y = 0; y < MapConst.MAP_HEIGHT; ++y) { for (int x = 0; x < MapConst.MAP_WIDTH; ++x) { // TileType-TileCamp-TileCamp1-TileLevel-PvELevel-BlockType // 4b - 4b - 4b - 2b - 6b - 2b try { UInt32 tileInfo = MapTileVO.TileEncodeLocal(tileVOs[y, x]); bw.Write(tileInfo); } catch (Exception e) { Debug.Log(tileVOs[y, x].camp); Debug.Log((int)tileVOs[y, x].type); Debug.Log(tileVOs[y, x].level); throw e; } } } if (wayPoints != null) { foreach (MapTileVO wayPoint in wayPoints) { try { UInt32 tileInfo = MapTileVO.WayPointEncodeLocal(wayPoint); bw.Write(tileInfo); } catch (Exception e) { Debug.Log("writing waypoint error: " + wayPoint.coord.x + ", " + wayPoint.coord.y); throw e; } } } bw.Close(); // sprite list fs = File.Open(Application.dataPath + "/Resources/" + MapPrefabDef.MapSprData + ".bytes", FileMode.OpenOrCreate, FileAccess.Write); bw = new BinaryWriter(fs, System.Text.Encoding.BigEndianUnicode); for (int y = 0; y < MapConst.MAP_SUBMAPS; ++y) { for (int x = 0; x < MapConst.MAP_SUBMAPS; ++x) { try { uint sprInfo = sprs[y, x]; bw.Write(sprInfo); } catch (Exception e) { Debug.LogError(e.ToString()); throw e; } } } bw.Close(); AssetDatabase.Refresh(); }