/// <Summary> /// Generate meshes. /// </Summary> void DrawMTraversedPos(VertexHelper vh, int mapAttrId, PositionSet pos) { if (mapAttrId != MapAttributeDefine.WALL) { // Left bottom UIVertex leftBottom = UIVertex.simpleVert; leftBottom.position = pos.bottomLeft; leftBottom.uv0 = leftBottomUv; // Left Top UIVertex leftTop = UIVertex.simpleVert; leftTop.position = pos.topLeft; leftTop.uv0 = leftTopUv; // Right Top UIVertex rightTop = UIVertex.simpleVert; rightTop.position = pos.topRight; rightTop.uv0 = rightTopUv; // Right bottom UIVertex rightBottom = UIVertex.simpleVert; rightBottom.position = pos.bottomRight; rightBottom.uv0 = rightBottomUv; vh.AddUIVertexQuad(new UIVertex[] { leftBottom, rightBottom, rightTop, leftTop }); } }
/// <Summary> /// Generates meshes of traversed position. /// If "isAutoMapping" is false, all hallways in the map are shown on the map. /// </Summary> void DrawMap(VertexHelper vh) { if (mapRt == null) { mapRt = gameObject.GetComponent <RectTransform>(); } Vector3 centerPos = mapRt.transform.localPosition; float cellWidth = mapRt.sizeDelta.x / (1 + showLengthHorizontal * 2); float cellHeight = mapRt.sizeDelta.y / (1 + showLengthVertical * 2); float widthOffset = cellWidth / 2; float heightOffset = cellHeight / 2; if (parentRt == null) { parentRt = GameObject.FindGameObjectWithTag("Map").GetComponent <RectTransform>(); } Vector2 parentPos = parentRt.transform.localPosition; float parentWidth = parentRt.sizeDelta.x; float parentHeight = parentRt.sizeDelta.y; Rect r = mapRt.rect; r.x += parentPos.x + centerPos.x; r.y += parentPos.y + centerPos.y; SetClipRect(r, true); int signX = centerPos.x < 0 ? -1 : 1; int signY = centerPos.y < 0 ? -1 : 1; Vector2 unitSize = new Vector2(cellWidth, cellHeight); float basePosX = parentWidth / 2 - signX * centerPos.x - widthOffset - posLerp.x * unitSize.x; float basePosY = parentHeight / 2 - signY * centerPos.y - heightOffset - posLerp.y * unitSize.y; Vector2 basePos = new Vector2(basePosX, basePosY); for (int yAxis = 0; yAxis < floorMapData.floorSizeVertical; yAxis++) { for (int xAxis = 0; xAxis < floorMapData.floorSizeHorizontal; xAxis++) { int index = xAxis + yAxis * floorMapData.floorSizeHorizontal; Vector3 basePosInLoop = new Vector3(basePos.x + unitSize.x * xAxis, basePos.y + unitSize.y * yAxis); int mapAttrId = MapAttributeDefine.WALL; Vector2Int pos = new Vector2Int(xAxis, yAxis); if (isAutoMapping) { if (!TraverseManager.GetPositionTraverseData(dungeonData.dungeonId, floorMapData.floorId, pos)) { continue; } } mapAttrId = floorMapData.mapInfo[index].mapAttr; PositionSet posSet = GetPositionSet(basePosInLoop, unitSize); DrawMTraversedPos(vh, mapAttrId, posSet); } } }
/// <Summary> /// Returns Ariadne.PositionSet data to define the position of the drawing mesh. /// </Summary> PositionSet GetPositionSet(Vector3 basePosInLoop, Vector2 unitSize) { PositionSet posSet = new PositionSet(); posSet.bottomLeft = new Vector3(basePosInLoop.x, basePosInLoop.y, 0f); posSet.topLeft = new Vector3(basePosInLoop.x, basePosInLoop.y + unitSize.y, 0f); posSet.topRight = new Vector3(basePosInLoop.x + unitSize.x, basePosInLoop.y + unitSize.y, 0f); posSet.bottomRight = new Vector3(basePosInLoop.x + unitSize.x, basePosInLoop.y, 0f); return(posSet); }