Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/View/PlayerViewSubcontroller.cs
SoulliesOfficial eaa688c7a9 调整
2025-12-22 23:27:18 -05:00

110 lines
3.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using DG.Tweening;
using SLSFramework.General;
using Unity.Cinemachine;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Serialization;
using Ease = DG.Tweening.Ease;
namespace Cielonos.MainGame.Characters
{
public class PlayerViewSubcontroller : SubcontrollerBase<Player>, IPlayerSubcontroller
{
public Player player => owner;
public Camera playerCamera;
public Transform cameraRoot;
public CinemachineStateDrivenCamera stateDrivenCamera;
public CinemachineCamera freeLookCamera;
public CinemachineCamera lockOnCamera;
[FormerlySerializedAs("isLockedOn")] public bool isLockingTarget = false;
public bool isLockedSetRoot;
public CharacterBase testEnemy;
public Transform testEnemyTarget;
public CameraRotationSubmodule cameraRotationSm;
public OcclusionFadeSubmodule occlusionFadeSm;
public override void Initialize()
{
base.Initialize();
cameraRotationSm = new CameraRotationSubmodule(this, player.transform.eulerAngles.y);
occlusionFadeSm = new OcclusionFadeSubmodule(this);
}
private void Start()
{
testEnemyTarget = testEnemy.bodyPartsSc.staticCenterPoint;
//SwitchToLockTarget( testEnemyTarget );
}
private void Update()
{
if (Keyboard.current.tabKey.wasPressedThisFrame)
{
if (!isLockingTarget)
{
SwitchToLockTarget( testEnemyTarget );
}
else
{
SwitchToFreeLook();
}
}
}
private void LateUpdate()
{
cameraRotationSm.Update();
if (!isLockingTarget)
{
}
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;
isLockingTarget = 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);
isLockingTarget = false;
// --- CM3 核心操作 ---
// 1. 重置 LookAt 目标
//lockOnCamera.Target.LookAtTarget = null;
// 2. 降低优先级,切换回自由视角相机
stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", false);
// (可选) 你可以在这里播放解锁音效或隐藏 UI 准星
Debug.Log("Switched to Free Look");
}
}
}