| |
---|
| | /// 恢复系数 |
---|
| | /// </summary> |
---|
| | [Export] |
---|
| | public float RecoveryCoefficient = 100f; |
---|
| | |
---|
| | /// <summary> |
---|
| | /// 抖动开关 |
---|
| | /// </summary> |
---|
| | public bool Enable { get; set; } = true; |
---|
| | public bool EnableShake { get; set; } = true; |
---|
| | |
---|
| | /// <summary> |
---|
| | /// 相机跟随目标 |
---|
| | /// </summary> |
---|
| | private Role _followTarget; |
---|
| | |
---|
| | public Vector2 SubPixelPosition { get; private set; } |
---|
| | // 3.5 |
---|
| | //public Vector2 SubPixelPosition { get; private set; } |
---|
| | |
---|
| | private long _index = 0; |
---|
| | private Vector2 _processDistance = Vector2.Zero; |
---|
| | private Vector2 _processDirection = Vector2.Zero; |
---|
| | //抖动数据 |
---|
| | private readonly Dictionary<long, Vector2> _shakeMap = new Dictionary<long, Vector2>(); |
---|
| | |
---|
| | private Vector2 _camPos; |
---|
| | private Vector2 _shakeOffset = Vector2.Zero; |
---|
| |
---|
| | // _camPos = _camPos.Lerp(camPos, Mathf.Min(6 * newDelta, 1)) + _shakeOffset; |
---|
| | // SubPixelPosition = _camPos.Round() - _camPos; |
---|
| | // (viewportContainer.Material as ShaderMaterial)?.SetShaderParameter("offset", SubPixelPosition); |
---|
| | // GlobalPosition = _camPos.Round(); |
---|
| | |
---|
| | var player = GameApplication.Instance.RoomManager.Player; |
---|
| | var mousePosition = InputManager.GetViewportMousePosition(); |
---|
| | var playerPosition = player.GlobalPosition; |
---|
| | Vector2 targetPos; |
---|
| | if (playerPosition.DistanceSquaredTo(mousePosition) >= (60 / 0.3f) * (60 / 0.3f)) |
---|
| | |
---|
| | if (_followTarget != null) |
---|
| | { |
---|
| | targetPos = playerPosition.MoveToward(mousePosition, 60); |
---|
| | var mousePosition = InputManager.GetViewportMousePosition(); |
---|
| | var targetPosition = _followTarget.GlobalPosition; |
---|
| | Vector2 targetPos; |
---|
| | if (targetPosition.DistanceSquaredTo(mousePosition) >= (60 / 0.3f) * (60 / 0.3f)) |
---|
| | { |
---|
| | targetPos = targetPosition.MoveToward(mousePosition, 60); |
---|
| | } |
---|
| | else |
---|
| | { |
---|
| | targetPos = targetPosition.Lerp(mousePosition, 0.3f); |
---|
| | } |
---|
| | _camPos = _camPos.Lerp(targetPos, Mathf.Min(6 * newDelta, 1)) + _shakeOffset; |
---|
| | GlobalPosition = _camPos.Round(); |
---|
| | } |
---|
| | else |
---|
| | { |
---|
| | targetPos = playerPosition.Lerp(mousePosition, 0.3f); |
---|
| | } |
---|
| | _camPos = _camPos.Lerp(targetPos, Mathf.Min(6 * newDelta, 1)) + _shakeOffset; |
---|
| | SubPixelPosition = _camPos.Round() - _camPos; |
---|
| | GlobalPosition = _camPos.Round(); |
---|
| | } |
---|
| | |
---|
| | /// <summary> |
---|
| | /// 设置相机跟随目标 |
---|
| | /// </summary> |
---|
| | public void SetFollowTarget(Role target) |
---|
| | { |
---|
| | _followTarget = target; |
---|
| | GlobalPosition = target.GlobalPosition; |
---|
| | } |
---|
| | |
---|
| | /// <summary> |
---|
| | /// 获取相机跟随目标 |
---|
| | /// </summary> |
---|
| | public Role GetFollowTarget() |
---|
| | { |
---|
| | return _followTarget; |
---|
| | } |
---|
| | |
---|
| | /// <summary> |
---|
| | /// 设置帧抖动, 结束后自动清零, 需要每一帧调用 |
---|
| |
---|
| | |
---|
| | //抖动调用 |
---|
| | private void _Shake(float delta) |
---|
| | { |
---|
| | if (Enable) |
---|
| | if (EnableShake) |
---|
| | { |
---|
| | var distance = _CalculateDistance(); |
---|
| | _shakeOffset += _processDirection + new Vector2( |
---|
| | Utils.RandomRangeFloat(-distance.X, distance.X) - _shakeOffset.X, |
---|
| |
---|
| | |