protected void SetGroupPoint(Vector2 pos, MapObjConf objConf, Vector3 scale) { int x = (int)pos.x, y = (int)pos.y; if (map[x, y] == null) { map[x, y] = new InGameMapPointData(MazeCreate.PointType.wall, pos); } map[x, y].AddObj(new MapPointObj(objConf, null, pos, scale)); SetWayProperty(pos, objConf); }
//从地图中删除一个障碍 public void DelMapObj(Vector3 pos, MapObjConf conf) { Vector2 startMapPos = GameCommon.GetMapPos(pos); int startX = (int)startMapPos.x; int startY = (int)startMapPos.y; InGameMapPointData data = map[startX, startY]; for (int i = 0; i < data.objList.Count; i++) { MapPointObj mapPointObj = data.objList[i]; if (mapPointObj.obj == null) { if (mapPointObj.conf.id == conf.id) { AddPoolObj(conf.id, mapPointObj.obj); data.objList.RemoveAt(i); if (map[startX, startX].type == MazeCreate.PointType.wallfull) { continue; } if (mapPointObj.conf.depth >= 3) { map[startX, startX].type = MazeCreate.PointType.wallfull; astarArray[startX, startX] = 0; } else { map[startX, startX].type = MazeCreate.PointType.way; astarArray[startX, startX] = 1; } } } } }
protected void SetWayProperty(Vector2 pos, MapObjConf objconf) { int x = (int)pos.x, y = (int)pos.y; MazeCreate.PointType type; int arrval = 0; if (objconf.depth >= 3) { type = MazeCreate.PointType.wallfull; arrval = 0; } else { type = MazeCreate.PointType.way; arrval = 1; } for (int i = 0; i < objconf.sizeX; i++) { for (int j = 0; j < objconf.sizeY; j++) { int _x = x + i; int _y = y + j; if (map[_x, _y] == null) { map[_x, _y] = new InGameMapPointData(MazeCreate.PointType.wall, new Vector2(_x, _y)); } if (map[_x, _y].type == MazeCreate.PointType.wallfull) { continue; } map[_x, _y].type = type; astarArray[_x, _y] = arrval; } } }
public override void InitMap(int group, int row, int col) { base.InitMap(group, row, col); List <List <int> > mapList = new List <List <int> >(); for (int i = 0; i < row; i++) { mapList.Add(new List <int>()); for (int j = 0; j < col; j++) { //if ((i >= 10 && i < 20) && // (j >= 10 && j < 20)) //{ // mapList[i].Add((int)MazeCreate.PointType.nullpoint); //} //else { mapList[i].Add((int)MazeCreate.PointType.wall); } } } mazeCreate = MazeCreate.GetMaze(mapList); AccumulationMap(mazeCreate.tree, Accumulation); ErosionMap(mazeCreate.tree); startPoint = mazeCreate.tree.position; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { if (IsPointType(i, j, MazeCreate.PointType.way)) { astarArray[i, j] = 1; //map[i, j] = new InGameMapPointData(MazeCreate.PointType.way,new Vector2(i,j)); if (mazeCreate.mapList[i][j] == (int)MazeCreate.PointType.fullway) { continue; } int scale = GetMaxFullSpace(i, j, MazeCreate.PointType.way); while (scale > 1 && !ConfigManager.mapObjConfManager.groupMap[mapGroup].ContainsKey(scale)) { scale--; } for (int x = 0; x < scale; x++) { for (int y = 0; y < scale; y++) { mazeCreate.mapList[i + x][j + y] = (int)MazeCreate.PointType.fullway; map[i + x, j + y] = new InGameMapPointData(MazeCreate.PointType.way, new Vector2(i + x, j + y)); } } //Vector3 objpos = new Vector3(i + (float)(scale - 1f) / 2f, j + (float)(scale - 1f) / 2f, 0); Vector3 objpos = new Vector3(i, j, 0); CreateGround(objpos, mapGroup, scale); } else if (IsNearFullGround(i, j)) { map[i, j] = new InGameMapPointData(MazeCreate.PointType.wall, new Vector2(i, j)); CreateGround(new Vector3(i, j), mapGroup, 1); CreateGround(new Vector3(i, j), mapGroup + 100000, 1); mazeCreate.mapList[i][j] = (int)MazeCreate.PointType.wallfull; } else { if (mazeCreate.mapList[i][j] == (int)MazeCreate.PointType.wallfull) { continue; } int scale = GetMaxFullSpace(i, j, MazeCreate.PointType.wall); while (scale > 1 && !ConfigManager.mapObjConfManager.groupMap[mapGroup + 100000].ContainsKey(scale)) { scale--; } if (scale < 2) { continue; } for (int x = 0; x < scale; x++) { for (int y = 0; y < scale; y++) { map[i + x, j + y] = new InGameMapPointData(MazeCreate.PointType.wall, new Vector2(i, j)); CreateGround(new Vector3(i + x, j + y), mapGroup, 1); mazeCreate.mapList[i + x][j + y] = (int)MazeCreate.PointType.wallfull; } } //CreateGround(new Vector3(i + (float)(scale - 1f) / 2f, j + (float)(scale - 1f) / 2f, 0), mapGroup + 100000, scale); CreateGround(new Vector3(i, j, 0), mapGroup + 100000, scale); } } } //StaticBatchingUtility.Combine(mapObj); }
//动态生成地面 public override void Update() { smallMap.Update(); Vector2 startPos = InGameManager.GetInstance().inGameCameraManager.GetCameraPos(); Vector2 startMapPos = GameCommon.GetMapPos(startPos); int startX = (int)startMapPos.x - UPDATE_MAP_SIZE / 2; int startY = (int)startMapPos.y - UPDATE_MAP_SIZE / 2; for (int i = 0; i < lastScreenObj.Count; i++) { Vector2 pos = lastScreenObj[i].pos; if (pos.x >= startX && pos.x < startX + UPDATE_MAP_SIZE && pos.y >= startY && pos.y < startY + UPDATE_MAP_SIZE) { continue; } List <MapPointObj> _list = lastScreenObj[i].objList; for (int j = 0; j < _list.Count; j++) { if (_list[j].obj == null) { continue; } AddPoolObj(_list[j].conf.id, _list[j].obj); _list[j].obj = null; } } lastScreenObj.Clear(); for (int x = 0; x < UPDATE_MAP_SIZE; x++) { for (int y = 0; y < UPDATE_MAP_SIZE; y++) { int sx = startX + x; int sy = startY + y; int _x = UPDATE_MAP_SIZE / 2 - x; int _y = UPDATE_MAP_SIZE / 2 - y; if (sx < 0 || sx >= map.GetLength(0)) { break; } if (sy < 0 || sy >= map.GetLength(1)) { continue; } bool isopen = false; //小地图中的点是否打开,如果已经打开 则不用计算距离 if (!smallMap.IsOpenPoint(sx, sy)) { if (Mathf.Sqrt(_x * _x + _y * _y) <= UPDATE_MAP_SIZE / 2) { isopen = true; } } InGameMapPointData data = map[sx, sy]; if (data == null) { if (isopen) { smallMap.OpenUnit(sx, sy, MazeCreate.PointType.nullpoint); } continue; } if (isopen) { smallMap.OpenUnit(sx, sy, data.type); } for (int i = 0; i < data.objList.Count; i++) { if (data.objList[i].obj == null) { MapPointObj mapPointObj = data.objList[i]; InGameBaseMapObj obj = GetPoolObj(mapPointObj.conf); obj.transform.position = GameCommon.GetWorldPos(mapPointObj.pos) + new Vector2(0, Random.Range(0, 0.1f)); obj.transform.localScale = mapPointObj.scale; GameCommon.SetObjZIndex(obj.gameObject, mapPointObj.conf.depth); mapPointObj.obj = obj; obj.Show(); mapObjActionList.Add(obj); } } lastScreenObj.Add(data); } } //处理mapobj 动画 for (int i = mapObjActionList.Count - 1; i >= 0; i--) { InGameBaseMapObj obj = mapObjActionList[i]; obj.ActionUpdate(); if (!obj.isAction) { mapObjActionList.RemoveAt(i); } } }