public override void MapEventTriggered(bool isSuccess, BattlePlayerController bp) { if (isOpen) { Vector3 continueMovePos = Vector3.zero; switch (bp.towards) { case MyTowards.Up: continueMovePos = pairDoorPos + new Vector3(0, 1, 0); break; case MyTowards.Down: continueMovePos = pairDoorPos + new Vector3(0, -1, 0); break; case MyTowards.Left: continueMovePos = pairDoorPos + new Vector3(-1, 0, 0); break; case MyTowards.Right: continueMovePos = pairDoorPos + new Vector3(1, 0, 0); break; } ExploreManager.Instance.expUICtr.DisplayTransitionMaskAnim(delegate { // 直接在门外的位置,没有移动动画 bp.transform.position = continueMovePos; bp.singleMoveEndPos = continueMovePos; bp.moveDestination = continueMovePos; bp.SetSortingOrder(-Mathf.RoundToInt(continueMovePos.y)); ExploreManager.Instance.newMapGenerator.miniMapPlayer.localPosition = (continueMovePos); ExploreManager.Instance.newMapGenerator.ClearMiniMapMaskAround(continueMovePos); ExploreManager.Instance.newMapGenerator.MiniMapCameraLatelySleep(); ExploreManager.Instance.expUICtr.UpdateMiniMapDisplay(continueMovePos); bp.isInEvent = false; }); } }
/// <summary> /// 角色随地板一起移动到最近的可移动地板目的地 /// </summary> /// <returns>The move to position.</returns> /// <param name="startPos">Start position.</param> /// <param name="endPos">End position.</param> /// <param name="ba">Ba.</param> private IEnumerator SmoothMoveToPos(Vector3 startPos, Vector3 endPos, BattlePlayerController bp) { yield return(new WaitUntil(() => bp.isIdle)); Transform background = Camera.main.transform.Find("Background"); int[,] realMapWalkableInfo = exploreManager.GetComponent <MapGenerator> ().mapWalkableInfoArray; realMapWalkableInfo [(int)startPos.x, (int)startPos.y] = -1; bp.ActiveBattlePlayer(false, false, true); bp.PlayRoleAnim("wait", 0, null); float moveDuration = Mathf.Sqrt((endPos - startPos).sqrMagnitude) / moveSpeed; // x轴方向的移动速度 if (endPos.x > startPos.x) { bp.TowardsRight(); } else { bp.TowardsLeft(); } float myMoveSpeedX = (endPos.x - startPos.x) / moveDuration; // y轴方向的移动速度 float myMoveSpeedY = (endPos.y - startPos.y) / moveDuration; float timer = 0; bool endPosInit = false; while (timer < moveDuration) { Vector3 moveVector = new Vector3(myMoveSpeedX * Time.deltaTime, myMoveSpeedY * Time.deltaTime, 0); timer += Time.deltaTime; this.transform.position += moveVector; bp.transform.position += moveVector; background.transform.position -= 0.3f * moveVector; // 走到一半时终点位置开始初始化(地板和物品,怪物出现) if (timer / moveDuration > 0.5 && !endPosInit) { exploreManager.GetComponent <ExploreManager> ().ItemsAroundAutoIntoLifeWithBasePoint(endPos); endPosInit = true; } yield return(null); } transform.position = endPos; bp.transform.position = endPos; bp.SetSortingOrder(-(int)endPos.y); // 如果要自动走到一个可行走点,则开启下面的代码 // Vector3 walkablePositionAround = exploreManager.GetComponent<MapGenerator>().GetAWalkablePositionAround (endPos); // // yield return new WaitUntil (()=>realMapWalkableInfo [(int)walkablePositionAround.x, (int)walkablePositionAround.y] == 1); // realMapWalkableInfo [(int)endPos.x, (int)endPos.y] = 10; bp.MoveToStoredDestination(); }