void Update() { if (State == StateEnum.InvalidDragging || State == StateEnum.ValidDragging) { ResetAssistPlaneRotation(); //坐标转换时使用的辅助平面,更新状态 var dragDisplacement = CurrentPosition - PressPosition; //屏幕坐标 WorldDragDisplacement = ScreenDragDisplacementToWorldDragDisplacement(dragDisplacement); //战场坐标 WorldAimingDisplacement = WorldDragDisplacementToWorldAiming(WorldDragDisplacement); //战场坐标 WorldActualDisplacement = WorldAimingDisplacementToWorldActual(WorldAimingDisplacement); var worldAimingMagnitude = WorldAimingDisplacement.magnitude; IsValidDrag = worldAimingMagnitude > WorldAimingDisplacementThreshold; if (IsValidDrag) //有效拖动 { if (State == StateEnum.InvalidDragging) //状态切换 { State = StateEnum.ValidDragging; } RefreshJoystickUI(dragDisplacement); Walker.transform.forward = WorldAimingDisplacement; if (_directionWalker) { _directionWalker.WalkTowards(WorldActualDisplacement); } else { _pathfindingWalker.WalkTo(Walker.transform.position + WorldActualDisplacement); } } else { if (State == StateEnum.ValidDragging)//状态切换 { State = StateEnum.InvalidDragging; HideUI(); if (_directionWalker) { _directionWalker.Stop(); } if (_pathfindingWalker) { _pathfindingWalker.Stop(); } } } } }
void Update() { if (State == StateEnum.InvalidDragging || State == StateEnum.ValidDragging) { ResetAssistPlaneRotation(); var dragDisplacement = CurrentPosition - PressPosition; var dragMagnitude = dragDisplacement.magnitude; if (dragMagnitude > DragThreshold)//有效拖动 { if (State == StateEnum.InvalidDragging) { State = StateEnum.ValidDragging; TouchCircle.gameObject.SetActive(true); TouchSpot.gameObject.SetActive(true); DragDrop.gameObject.SetActive(true); if (JoystickAssistCircle) { JoystickAssistCircle.gameObject.SetActive(true); } if (JoystickAssistSpot) { JoystickAssistSpot.gameObject.SetActive(true); } } var validDragDisplacement = CalcValidDragDisplacement(dragDisplacement); TouchSpot.localPosition = validDragDisplacement * (1800f / Screen.width); DragDrop.parent.right = validDragDisplacement; DragDrop.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, validDragDisplacement.magnitude + 71 + DragThreshold + 20); var geodesicDisplacement = DragDisplacementToGeodesicDisplacement(validDragDisplacement); //var arrow = MainController.Instance.Arrow; //var eA = arrow.localEulerAngles; //eA.z = Quaternion.FromToRotation(Vector3.right, geodesicDisplacement).eulerAngles.y; //arrow.localEulerAngles = -eA; if (JoystickAssistCircle) { JoystickAssistCircle.position = Walker.transform.position.SetV3Y(0.01f); } if (JoystickAssistSpot) { var spotPos = Vector3.ClampMagnitude(geodesicDisplacement * 0.03f, 9003.88f); spotPos = new Vector3(spotPos.x, spotPos.z, -0.01f); JoystickAssistSpot.localPosition = spotPos; } if (!UsePathfinding) { _directionWalker.WalkTowards(geodesicDisplacement); } else { _pathfindingWalker.WalkTo(Walker.transform.position + geodesicDisplacement); } } else { if (State == StateEnum.ValidDragging) { State = StateEnum.InvalidDragging; TouchCircle.gameObject.SetActive(false); TouchSpot.gameObject.SetActive(false); DragDrop.gameObject.SetActive(false); if (JoystickAssistCircle) { JoystickAssistCircle.gameObject.SetActive(false); } if (JoystickAssistSpot) { JoystickAssistSpot.gameObject.SetActive(false); } if (!UsePathfinding) { _directionWalker.Stop(); } else { _pathfindingWalker.Stop(); } } } } }