private void UserClickAt(Vector3 clickPos) { int targetX = 0; int targetY = 0; Vector3 targetPos = Vector3.zero; if (clickForConsumablesPos) { targetX = (int)(clickPos.x + 0.5f); targetY = (int)(clickPos.y + 0.5f); // 以地图左下角为坐标原点时的点击位置 targetPos = new Vector3(targetX, targetY, 0); mapGenerator.ClickConsumablesPosAt(targetPos); clickForConsumablesPos = false; return; } // 点击位置在地图有效区之外,直接返回 if (clickPos.x + 0.5f >= mapGenerator.columns || clickPos.y + 0.5f >= mapGenerator.rows || clickPos.x + 0.5f < 0 || clickPos.y + 0.5f < 0) { Debug.Log("点击在地图有效区外部"); return; } // 由于地图贴图 tile时是以中心点为参考,宽高为1,所以如果以实际拼出的地图左下角为坐标原点,则点击位置需要进行如下坐标转换 targetX = (int)(clickPos.x + 0.5f); targetY = (int)(clickPos.y + 0.5f); // 以地图左下角为坐标原点时的点击位置 targetPos = new Vector3(targetX, targetY, 0); // 如果点在镂空区域,则直接返回 if (mapGenerator.mapWalkableInfoArray [(int)targetPos.x, (int)targetPos.y] == -1) { return; } // 游戏角色按照自动寻路路径移动到点击位置 bool arrivable = battlePlayerCtr.MoveToPosition(targetPos, mapGenerator.mapWalkableInfoArray); // 地图上点击位置生成提示动画 mapGenerator.PlayDestinationAnim(targetPos, arrivable); }
private IEnumerator WalkOutOfHole(MapGenerator mapGenerator, Vector3 walkablePositionAround, BattlePlayerController bp, Hole targetHole) { targetHole.bc2d.enabled = false; int[,] mapWalkableInfo = mapGenerator.mapWalkableInfoArray; yield return(new WaitUntil(() => mapWalkableInfo[(int)walkablePositionAround.x, (int)walkablePositionAround.y] == 1)); bp.SetEffectAnim("HoleFog"); // mapGenerator.PlayMapOtherAnim("HoleFog",targetHole.transform.position); Debug.LogFormat("around items come to life,time:{0}", Time.realtimeSinceStartup); bp.MoveToPosition(walkablePositionAround, mapGenerator.mapWalkableInfoArray); yield return(new WaitUntil(() => bp.isIdle)); Debug.LogFormat("player move End:{0}", Time.realtimeSinceStartup); targetHole.bc2d.enabled = true; mapGenerator.GetComponent <ExploreManager> ().EnableInteractivity(); }
/// <summary> /// 用户点击 /// </summary> /// <param name="clickPos">Click position.</param> private void UserClickAt(Vector3 clickPos) { int targetX = 0; int targetY = 0; Vector3 targetPos = Vector3.zero; // 由于地图贴图 tile时是以中心点为参考,宽高为1,所以如果以实际拼出的地图左下角为坐标原点,则点击位置需要进行如下坐标转换 targetX = (int)(clickPos.x + 0.5f); targetY = (int)(clickPos.y + 0.5f); if (targetX >= newMapGenerator.columns || targetY >= newMapGenerator.rows || targetX < 0 || targetY < 0) { return; } // 以地图左下角为坐标原点时的点击位置 targetPos = new Vector3(targetX, targetY, 0); // 如果点在镂空区域,则直接返回 if (newMapGenerator.mapWalkableInfoArray [(int)targetPos.x, (int)targetPos.y] == -1) { newMapGenerator.PlayDestinationAnim(targetPos, false); return; } // 游戏角色按照自动寻路路径移动到点击位置 bool arrivable = battlePlayerCtr.MoveToPosition(targetPos, newMapGenerator.mapWalkableInfoArray); // 地图上点击位置生成提示动画 // mapGenerator.PlayDestinationAnim(targetPos,arrivable); newMapGenerator.PlayDestinationAnim(targetPos, arrivable); }