/// <summary> /// 行走到指定位置【暂时没有用,npc不会动】 /// </summary> /// <param name="position">Position.</param> /// <param name="cb">Cb.</param> /// <param name="showAlertArea">If set to <c>true</c> show alert area.</param> public override void WalkToPosition(Vector3 position, CallBack cb, bool showAlertArea = true) { int oriPosX = Mathf.RoundToInt(transform.position.x); int oriPosY = Mathf.RoundToInt(transform.position.y); int targetPosX = Mathf.RoundToInt(position.x); int targetPosY = Mathf.RoundToInt(position.y); moveOrigin = new Vector3(oriPosX, oriPosY, 0); moveDestination = new Vector3(targetPosX, targetPosY, 0); if (MyTool.ApproximatelySamePosition2D(position, ExploreManager.Instance.battlePlayerCtr.transform.position)) { return; } baCtr.PlayRoleAnim(CommonData.roleWalkAnimName, 0, null); //Debug.LogFormat("MOVE ORIGIN:{0}++++++MOVE DESTINATION:{1}", moveOrigin, moveDestination); RefreshWalkableInfoWhenStartMove(); if (moveCoroutine != null) { StopCoroutine(moveCoroutine); } float timeScale = 3f; if (position.x >= transform.position.x) { baCtr.TowardsRight(); } else { baCtr.TowardsLeft(); } moveCoroutine = MoveTo(position, timeScale, delegate { this.transform.position = position; baCtr.PlayRoleAnim(CommonData.roleIdleAnimName, 0, null); if (cb != null) { cb(); } SetSortingOrder(-Mathf.RoundToInt(position.y)); if (needPosFix) { needPosFix = false; } }); StartCoroutine(moveCoroutine); }
/// <summary> /// 判断当前是否已经走到了终点位置 /// </summary> /// <returns><c>true</c>, if end point was arrived, <c>false</c> otherwise.</returns> private bool ArriveEndPoint() { if (MyTool.ApproximatelySamePosition2D(moveDestination, transform.position)) { return(true); } return(false); }
/// <summary> /// 获取上下左右中的一个随机点 /// </summary> /// <returns>The random position around.</returns> /// <param name="position">Position.</param> protected Vector3 GetRandomPositionAround(Vector3 position) { int posX = Mathf.RoundToInt(position.x); int posY = Mathf.RoundToInt(position.y); Vector3 oriIntergerPos = new Vector3(posX, posY, 0); if (!MyTool.ApproximatelySamePosition2D(position, oriIntergerPos)) { return(oriIntergerPos); } int directionSeed = Random.Range(0, 4); Vector3 randomPosition = position; switch (directionSeed) { case 0: if (posY + 1 < ExploreManager.Instance.newMapGenerator.rows) { randomPosition = new Vector3(posX, posY + 1, position.z); } break; case 1: if (posY - 1 > 0) { randomPosition = new Vector3(posX, posY - 1, position.z); } break; case 2: if (posX - 1 > 0) { randomPosition = new Vector3(posX - 1, posY, position.z); } break; case 3: if (posX + 1 < ExploreManager.Instance.newMapGenerator.columns) { randomPosition = new Vector3(posX + 1, posY, position.z); } break; } return(randomPosition); }
public void OnTriggerEnter2D(Collider2D other) { BattlePlayerController battlePlayer = other.GetComponent <BattlePlayerController> (); if (battlePlayer == null) { return; } if (!MyTool.ApproximatelySamePosition2D(battlePlayer.moveDestination, this.transform.position)) { return; } MoveToNearestPosition(other.transform); }
private Vector3 GetPairedPos() { return(MyTool.ApproximatelySamePosition2D(transform.position, movePosPair [0]) ? movePosPair [1] : movePosPair [0]); }