Bezi回来了
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DG.Tweening;
|
||||
using SickscoreGames.HUDNavigationSystem;
|
||||
using UniRx;
|
||||
@@ -31,8 +32,13 @@ namespace Cielonos.MainGame.Characters
|
||||
/// 是否正在使用锁定目标摄像机
|
||||
/// </summary>
|
||||
public bool isUsingLockTargetCamera => isLocking && isAutoRotate;
|
||||
public bool isDuringSwitch;
|
||||
|
||||
public bool isDuringCameraSwitch;
|
||||
private const float CameraSwitchCooldown = 0.25f;
|
||||
|
||||
public CharacterBase lockTarget;
|
||||
private float lastTargetSwitchTime;
|
||||
private const float TargetSwitchCooldown = 0.25f;
|
||||
public Transform targetPoint;
|
||||
private Tweener iconTween;
|
||||
|
||||
@@ -40,20 +46,27 @@ namespace Cielonos.MainGame.Characters
|
||||
{
|
||||
isLocking = false;
|
||||
isAutoRotate = false;
|
||||
isDuringSwitch = false;
|
||||
isDuringCameraSwitch = false;
|
||||
lockTarget = null;
|
||||
targetPoint = null;
|
||||
}
|
||||
|
||||
public void Update()
|
||||
{
|
||||
if (isUsingLockTargetCamera && !isDuringSwitch)
|
||||
if (isUsingLockTargetCamera && !isDuringCameraSwitch)
|
||||
{
|
||||
viewSc.cameraRoot.LookAt(targetPoint);
|
||||
float distance = (targetPoint.position - viewSc.cameraRoot.transform.position).Flatten().magnitude;
|
||||
if (isUsingLockTargetCamera && distance < 1f)
|
||||
if (targetPoint != null)
|
||||
{
|
||||
UnlockTarget();
|
||||
// 平滑跟随目标
|
||||
Vector3 currentRotation = viewSc.cameraRoot.eulerAngles;
|
||||
Vector3 targetDirection = targetPoint.position - viewSc.cameraRoot.position;
|
||||
Quaternion targetRotation = Quaternion.LookRotation(targetDirection);
|
||||
|
||||
viewSc.cameraRoot.rotation = Quaternion.Slerp(
|
||||
viewSc.cameraRoot.rotation,
|
||||
targetRotation,
|
||||
1f - Mathf.Exp(-10f * Time.deltaTime)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -75,7 +88,7 @@ namespace Cielonos.MainGame.Characters
|
||||
|
||||
public void LockTarget(bool isAutoRotate)
|
||||
{
|
||||
if(isDuringSwitch) return;
|
||||
if(isDuringCameraSwitch) return;
|
||||
|
||||
CharacterBase target = BattleManager.EnemySm.GetNearestEnemy(50f);
|
||||
|
||||
@@ -84,7 +97,7 @@ namespace Cielonos.MainGame.Characters
|
||||
this.isLocking = true;
|
||||
this.isAutoRotate = isAutoRotate;
|
||||
this.lockTarget = target;
|
||||
this.isDuringSwitch = true;
|
||||
this.isDuringCameraSwitch = true;
|
||||
|
||||
if (isAutoRotate)
|
||||
{
|
||||
@@ -94,14 +107,14 @@ namespace Cielonos.MainGame.Characters
|
||||
viewSc.stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", true);
|
||||
viewSc.cameraRoot.DOLookAt(targetPoint.position, 0.5f)
|
||||
.SetEase(Ease.InOutSine)
|
||||
.OnComplete(() => { isDuringSwitch = false; })
|
||||
.OnComplete(() => { isDuringCameraSwitch = false; })
|
||||
.Play();
|
||||
}
|
||||
else
|
||||
{
|
||||
Observable.Timer(TimeSpan.FromSeconds(0.5f)).First().Subscribe(_ =>
|
||||
{
|
||||
isDuringSwitch = false;
|
||||
isDuringCameraSwitch = false;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -114,7 +127,7 @@ namespace Cielonos.MainGame.Characters
|
||||
|
||||
public void UnlockTarget()
|
||||
{
|
||||
if(isDuringSwitch) return;
|
||||
if(isDuringCameraSwitch) return;
|
||||
|
||||
Vector3 currentEuler = viewSc.playerCamera.transform.rotation.eulerAngles;
|
||||
|
||||
@@ -134,12 +147,76 @@ namespace Cielonos.MainGame.Characters
|
||||
orbitalFollow.HorizontalAxis.Value = newYaw;
|
||||
orbitalFollow.VerticalAxis.Value = newPitch;
|
||||
|
||||
if (lockTarget != null)
|
||||
{
|
||||
lockTarget.navigationElement.showIndicator = false;
|
||||
}
|
||||
|
||||
this.isLocking = false;
|
||||
this.isAutoRotate = false;
|
||||
this.lockTarget.navigationElement.showIndicator = false;
|
||||
this.lockTarget = null;
|
||||
this.targetPoint = null;
|
||||
viewSc.stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 切换锁定目标
|
||||
/// </summary>
|
||||
public void SwitchTarget(float direction)
|
||||
{
|
||||
if (!isLocking || isDuringCameraSwitch) return;
|
||||
|
||||
if (Time.time - lastTargetSwitchTime < TargetSwitchCooldown) return;
|
||||
|
||||
List<CharacterBase> sortedEnemies = BattleManager.EnemySm.GetVisibleEnemiesSortedByScreenX();
|
||||
if (sortedEnemies.Count <= 1) return;
|
||||
|
||||
int currentIndex = sortedEnemies.IndexOf(lockTarget);
|
||||
if (currentIndex < 0)
|
||||
{
|
||||
currentIndex = 0;
|
||||
}
|
||||
|
||||
int dir = direction > 0 ? -1 : 1;
|
||||
int newIndex = currentIndex + dir;
|
||||
|
||||
// 边界检查(无循环)
|
||||
if (newIndex < 0 || newIndex >= sortedEnemies.Count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterBase newTarget = sortedEnemies[newIndex];
|
||||
|
||||
// 目标相同检查
|
||||
if (newTarget == lockTarget)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
lastTargetSwitchTime = Time.time;
|
||||
SetNewTarget(sortedEnemies[newIndex]);
|
||||
}
|
||||
|
||||
private void SetNewTarget(CharacterBase newTarget)
|
||||
{
|
||||
if (lockTarget != null)
|
||||
{
|
||||
lockTarget.navigationElement.showIndicator = false;
|
||||
}
|
||||
|
||||
lockTarget = newTarget;
|
||||
targetPoint = newTarget.bodyPartsSc.cameraLockingPoint ?? newTarget.bodyPartsSc.staticCenterPoint;
|
||||
|
||||
if (isUsingLockTargetCamera)
|
||||
{
|
||||
viewSc.lockingTargetCamera.LookAt = targetPoint;
|
||||
}
|
||||
|
||||
lockTarget.navigationElement.showIndicator = true;
|
||||
Image icon = lockTarget.navigationElement.Indicator.OnscreenIcon;
|
||||
iconTween?.Kill(true);
|
||||
iconTween = icon.GetComponent<RectTransform>().DOScale(1f, 0.3f).From(0.5f).SetEase(Ease.OutQuart).Play();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user