更新
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
using System;
|
||||
using DG.Tweening;
|
||||
using SLSFramework.General;
|
||||
using Unity.Cinemachine;
|
||||
using UnityEngine;
|
||||
using UnityEngine.InputSystem;
|
||||
using UnityEngine.Serialization;
|
||||
|
||||
namespace Cielonos.MainGame.Characters
|
||||
@@ -11,28 +13,102 @@ namespace Cielonos.MainGame.Characters
|
||||
public Player player => owner;
|
||||
|
||||
public Camera playerCamera;
|
||||
public Transform cameraTarget;
|
||||
public Transform cameraRoot;
|
||||
public CinemachineStateDrivenCamera stateDrivenCamera;
|
||||
public CinemachineCamera freeLookCamera;
|
||||
public CinemachineCamera lockOnCamera;
|
||||
public bool isLockedOn = false;
|
||||
public bool isLockedSetRoot;
|
||||
public CharacterBase testEnemy;
|
||||
public Transform testEnemyTarget;
|
||||
|
||||
public CameraRotationSubmodule cameraRotationSm;
|
||||
public OcclusionFadeSubmodule occlusionFadeSm;
|
||||
|
||||
public LerpFloat cameraDistance;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
cameraRotationSm = new CameraRotationSubmodule(this, player.transform.eulerAngles.y);
|
||||
occlusionFadeSm = new OcclusionFadeSubmodule(this);
|
||||
cameraDistance = new LerpFloat(10f, 1f);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
testEnemyTarget = testEnemy.bodyPartsSc.staticCenterPoint;
|
||||
//SwitchToLockTarget( testEnemyTarget );
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Keyboard.current.tabKey.wasPressedThisFrame)
|
||||
{
|
||||
if (!isLockedOn)
|
||||
{
|
||||
SwitchToLockTarget( testEnemyTarget );
|
||||
}
|
||||
else
|
||||
{
|
||||
SwitchToFreeLook();
|
||||
}
|
||||
}
|
||||
|
||||
cameraDistance.Update(player.selfTimeSm.DeltaTime);
|
||||
freeLookCamera.GetComponent<CinemachineThirdPersonFollow>().CameraDistance = cameraDistance.currentValue;
|
||||
lockOnCamera.GetComponent<CinemachinePositionComposer>().CameraDistance = cameraDistance.currentValue;
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
cameraRotationSm.Update();
|
||||
if (!isLockedOn)
|
||||
{
|
||||
cameraRotationSm.Update();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(isLockedSetRoot) cameraRoot.LookAt(testEnemyTarget);
|
||||
float distance = (testEnemyTarget.position - cameraRoot.transform.position).Flatten().magnitude;
|
||||
if(distance < 1f) SwitchToFreeLook();
|
||||
}
|
||||
occlusionFadeSm.Update();
|
||||
}
|
||||
|
||||
void SwitchToLockTarget(Transform target)
|
||||
{
|
||||
testEnemyTarget = target;
|
||||
isLockedOn = true;
|
||||
isLockedSetRoot = false;
|
||||
|
||||
// --- CM3 核心操作 ---
|
||||
// 1. 设置 LookAt 目标。在 CM3 中,LookingAt 是 Target 结构体的一部分,或者直接赋值给 LookAt 属性
|
||||
lockOnCamera.Target.LookAtTarget = testEnemyTarget;
|
||||
|
||||
// 2. 提高优先级,激活锁定相机
|
||||
stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", true);
|
||||
cameraRoot.DOLookAt(testEnemyTarget.position, 0.5f).SetEase(Ease.InOutSine).OnComplete(()=>isLockedSetRoot = true).Play();
|
||||
|
||||
// (可选) 你可以在这里播放锁定音效或显示 UI 准星
|
||||
Debug.Log($"Locked on: {target.name}");
|
||||
}
|
||||
|
||||
void SwitchToFreeLook()
|
||||
{
|
||||
cameraRotationSm.SyncRotationWithCamera(playerCamera);
|
||||
|
||||
isLockedOn = false;
|
||||
|
||||
// --- CM3 核心操作 ---
|
||||
// 1. 重置 LookAt 目标
|
||||
//lockOnCamera.Target.LookAtTarget = null;
|
||||
|
||||
// 2. 降低优先级,切换回自由视角相机
|
||||
stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", false);
|
||||
|
||||
// (可选) 你可以在这里播放解锁音效或隐藏 UI 准星
|
||||
Debug.Log("Switched to Free Look");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user