//校验点击点是否在地图里 public static bool CheckOnHexGrid(Vector3 position, HexModelInfo hexModelInfo) { if (hexModelInfo.arrayMode == HexMetrics.MODE_ERECT) { float x = position.x / (HexMetrics.innerRadius * 2f); float y = -x; float offset = position.z / (HexMetrics.outerRadius * 3f); x -= offset; y -= offset; int iX = Mathf.RoundToInt(x); int iY = Mathf.RoundToInt(y); int iZ = Mathf.RoundToInt(-x - y); if (iX + Mathf.RoundToInt(iZ / 2) < 0 || iX + Mathf.RoundToInt(iZ / 2) >= hexModelInfo.width || iZ < 0 || iZ >= hexModelInfo.height) { return(false); } else { return(true); } } else { float y = -position.z / (HexMetrics.innerRadius * 2f); float z = -y; float offset = position.x / (HexMetrics.outerRadius * 3f); z -= offset; y -= offset; int iZ = Mathf.RoundToInt(z); int iY = Mathf.RoundToInt(y); int iX = Mathf.RoundToInt(-z - y); if (iX < 0 || iX >= hexModelInfo.width || iZ + Mathf.RoundToInt(iX / 2) < 0 || iZ + Mathf.RoundToInt(iX / 2) >= hexModelInfo.height) { return(false); } else { return(true); } } }
//设置当前游戏模式 public void setGameModelNow(string name) { //先默认是安多尔模式 gameModelNow = this.gameModelInfoMap[name]; UtilityLog.Log("当前游戏模式:" + gameModelNow.name, LogUtType.Other); //地图模式 string arrayMode = gameModelNow.arrayMode; //地图大小 int height = gameModelNow.height; int width = gameModelNow.width; hexModelInfoNow = new HexModelInfo(width, height, arrayMode, HexModelType.Source); hexModelInfoNow.expansionVector.Add(new HexCoordinates(0, 1)); hexModelInfoNow.expansionVector.Add(new HexCoordinates(1, 0)); hexModelInfoNow.expansionVector.Add(new HexCoordinates(1, -1)); hexModelInfoNow.expansionVector.Add(new HexCoordinates(0, -1)); hexModelInfoNow.expansionVector.Add(new HexCoordinates(-1, 0)); hexModelInfoNow.expansionVector.Add(new HexCoordinates(-1, 1)); SendNotification(OrderSystemEvent.CLINET_SYS, hexModelInfoNow, OrderSystemEvent.CLINET_SYS_GMAE_MODEL_SET); }
//移动动画 public IEnumerator MoveMinionCellShowMove(CardEntry minionCellItemNew, MinionCellView minCellView, UnityAction callBack, HexModelInfo hexModelInfo) { for (int n = 0; n < minionCellItemNew.cellRoute.Count; n++) { Vector3 startPosition = minCellView.transform.position; HexCoordinates hexCoordinates = minionCellItemNew.cellRoute[n].coordinates; Vector3 endPosition = new Vector3(); HexCoordinates showHexCoordinates = HexCoordinates.ReverseFromOffsetCoordinates(hexCoordinates.X, hexCoordinates.Z, hexModelInfo.arrayMode); endPosition = HexMetrics.erectPosition( endPosition, showHexCoordinates.X, showHexCoordinates.Z, hexModelInfo.arrayMode); bool isNear = false; Vector3 position = new Vector3(); position.y = 0; int xdirection = endPosition.x - startPosition.x == 0 ? 0 : endPosition.x - startPosition.x > 0 ? 1 : -1; int zdirection = endPosition.z - startPosition.z == 0 ? 0 : endPosition.z - startPosition.z > 0 ? 1 : -1; position.x = Math.Abs(endPosition.x - startPosition.x) * xdirection; position.y = Math.Abs(endPosition.z - startPosition.z) * zdirection; //到达目的点 while (!isNear) { minCellView.transform.Translate(position * Time.deltaTime); if (Math.Abs(minCellView.transform.position.x - endPosition.x) < 0.5) { if (Math.Abs(minCellView.transform.position.z - endPosition.z) < 0.5) { isNear = true; } } yield return(null); } //直接设置为目标点,避免有偏差 Vector3 OverPosition = new Vector3(endPosition.x, minCellView.transform.position.y, endPosition.z); minCellView.transform.position = OverPosition; } callBack(); }