切换主武器

This commit is contained in:
SoulliesOfficial
2025-12-23 19:47:06 -05:00
parent eaa688c7a9
commit 2a2aa728d5
275 changed files with 12579 additions and 2770 deletions

View File

@@ -230,19 +230,19 @@ namespace Cielonos.MainGame.Characters
}
};
inputActions.Player.SwitchMainWeapon.performed += ctx =>
inputActions.Player.SwitchPreviousMainWeapon.performed += ctx =>
{
if (ctx.performed && isCursorLocked.Value)
{
operation.SwitchMainWeapon(ctx.ReadValue<float>());
operation.SwitchMainWeapon(-1);
}
};
inputActions.Player.FastSwitchMainWeapon.performed += ctx =>
inputActions.Player.SwitchNextMainWeapon.performed += ctx =>
{
if (ctx.performed && isCursorLocked.Value)
{
operation.FastSwitchMainWeapon();
operation.SwitchMainWeapon(1);
}
};

View File

@@ -0,0 +1,11 @@
using System.Collections.Generic;
using Cielonos.MainGame.Inventory;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
public class PlayerBackpack
{
public List<MainWeaponBase> mainWeapons = new List<MainWeaponBase>();
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: b2c6ef7e33fccdf41848bc44e0432c59

View File

@@ -13,11 +13,24 @@ namespace Cielonos.MainGame.Characters
public PlayerEquipmentSubmodule(PlayerInventorySubcontroller owner) : base(owner)
{
preparedMainWeapons = new List<MainWeaponBase>();
foreach (MainWeaponBase mainWeapon in owner.backpack.mainWeapons)
{
ObtainMainWeapon(mainWeapon);
}
EquipMainWeapon(preparedMainWeapons[0]);
}
public void ObtainMainWeapon(MainWeaponBase newWeapon)
{
if (!preparedMainWeapons.Contains(newWeapon))
{
preparedMainWeapons.Add(newWeapon);
newWeapon.Initialize();
}
}
public void EquipMainWeapon(MainWeaponBase newWeapon)
{
newWeapon.Initialize();
currentMainWeapon = newWeapon;
currentMainWeapon.OnEquipped();
currentMainWeapon.RegisterFullBodyFuncAnims();
@@ -27,8 +40,23 @@ namespace Cielonos.MainGame.Characters
public void RemoveMainWeapon()
{
Debug.Log("Unequipping main weapon: " + currentMainWeapon);
currentMainWeapon.OnUnequipped();
currentMainWeapon = null;
}
public void DiscardMainWeapon(MainWeaponBase weaponToDiscard)
{
if (preparedMainWeapons.Contains(weaponToDiscard))
{
if (currentMainWeapon == weaponToDiscard)
{
RemoveMainWeapon();
}
preparedMainWeapons.Remove(weaponToDiscard);
Object.Destroy(weaponToDiscard);
}
}
}
}

View File

@@ -1,4 +1,4 @@
using Cielonos.MainGame.Inventory;
using Cielonos.MainGame.Inventory;
using UnityEngine;
namespace Cielonos.MainGame.Characters
@@ -8,15 +8,14 @@ namespace Cielonos.MainGame.Characters
public Player player => owner;
private PlayerInputSubcontroller inputSc => player.inputSc;
private PlayerOperationSubcontroller operationSc => player.operationSc;
public MainWeaponBase testMainWeapon;
public PlayerBackpack backpack;
public PlayerEquipmentSubmodule equipmentSm;
public override void Initialize()
{
base.Initialize();
RegisterOperations();
equipmentSm = new PlayerEquipmentSubmodule(this);
equipmentSm.EquipMainWeapon(testMainWeapon);
equipmentSm ??= new PlayerEquipmentSubmodule(this);
}
}
@@ -38,6 +37,8 @@ namespace Cielonos.MainGame.Characters
operationSc.OnMainWeaponQuaternaryPress += MainWeaponSpecialBPress;
operationSc.OnMainWeaponQuaternaryRelease += MainWeaponSpecialBRelease;
operationSc.OnSwitchMainWeapon += SwitchMainWeapon;
/*
operationSc.OnSwitchMainWeapon += delegate(float dir) { SwitchMainWeapon(dir > 0 ? 1 : -1); };
operationSc.OnUseSupportEquipment0Press += delegate { SupportEquipmentPress(0); };
@@ -73,6 +74,15 @@ namespace Cielonos.MainGame.Characters
public partial class PlayerInventorySubcontroller
{
private void SwitchMainWeapon(int direction)
{
int currentIndex = equipmentSm.preparedMainWeapons.IndexOf(currentMainWeapon);
equipmentSm.RemoveMainWeapon();
int newIndex = (currentIndex + direction + equipmentSm.preparedMainWeapons.Count) % equipmentSm.preparedMainWeapons.Count;
Debug.Log($"Switching main weapon from index {currentIndex} to {newIndex}");
equipmentSm.EquipMainWeapon(equipmentSm.preparedMainWeapons[newIndex]);
}
public void MainWeaponPrimaryPress()
{
if (currentMainWeapon != null)

View File

@@ -44,7 +44,7 @@ namespace Cielonos.MainGame.Characters
public event Action OnMainWeaponQuaternaryHold;
public event Action OnMainWeaponQuaternaryRelease;
public event Action<float> OnSwitchMainWeapon;
public event Action<int> OnSwitchMainWeapon;
public event Action OnOpenMainWeaponRoulette;
public event Action OnCloseMainWeaponRoulette;
public event Action OnFastSwitchMainWeapon;
@@ -95,7 +95,7 @@ namespace Cielonos.MainGame.Characters
public void MainWeaponQuaternaryHold() => OnMainWeaponQuaternaryHold?.Invoke();
public void MainWeaponSpecialBRelease() => OnMainWeaponQuaternaryRelease?.Invoke();
public void SwitchMainWeapon(float direction) => OnSwitchMainWeapon?.Invoke(direction);
public void SwitchMainWeapon(int direction) => OnSwitchMainWeapon?.Invoke(direction);
public void OpenMainWeaponRoulette() => OnOpenMainWeaponRoulette?.Invoke();

View File

@@ -1,6 +1,8 @@
using DG.Tweening;
using Sirenix.OdinInspector;
using SLSFramework.General;
using UnityEngine;
using Ease = DG.Tweening.Ease;
namespace Cielonos.MainGame.Characters
{
@@ -18,7 +20,6 @@ namespace Cielonos.MainGame.Characters
public float cinemachineTargetPitch;
public float topClamp = 70.0f;
public float bottomClamp = -30.0f;
public float cameraAngleOverride = 0.0f;
public bool lockCameraPosition = false;
[Title("Combat Recenter Settings")]
@@ -61,13 +62,16 @@ namespace Cielonos.MainGame.Characters
cinemachineTargetYaw = MathExtensions.ClampAngle(cinemachineTargetYaw, float.MinValue, float.MaxValue);
cinemachineTargetPitch = MathExtensions.ClampAngle(cinemachineTargetPitch, bottomClamp, topClamp);
viewSc.cameraRoot.rotation = Quaternion.Euler(
cinemachineTargetPitch + cameraAngleOverride /*- viewSc.muzzleLiftModule.currentMuzzlePositionY*/, cinemachineTargetYaw, 0.0f);
if (viewSc.isLockingTarget)
if (viewSc.lockTargetModule.isUsingLockTargetCamera)
{
cinemachineEndLockYaw = viewSc.lockOnCamera.transform.eulerAngles.y;
cinemachineEndLockYaw = viewSc.lockingTargetCamera.transform.eulerAngles.y;
}
else
{
viewSc.cameraRoot.rotation = Quaternion.Euler(
cinemachineTargetPitch /*- viewSc.muzzleLiftModule.currentMuzzlePositionY*/, cinemachineTargetYaw, 0.0f);
}
/*
@@ -108,23 +112,34 @@ namespace Cielonos.MainGame.Characters
recenterTimer = duration;
isRecentering = true;
}
private bool tt;
// 将此方法添加到你控制相机旋转的脚本中 (例如 PlayerCameraController)
public void SyncRotationWithCamera(Camera camera = null)
/// <summary>
/// 同步相机旋转到当前摄像机朝向
/// </summary>
public void SyncRotationWithCamera()
{
camera ??= viewSc.playerCamera;
// 确保获取的是当前正在起作用的锁定相机的旋转
var camera = viewSc.currentCamera;
Vector3 currentEuler = camera.transform.eulerAngles;
cinemachineTargetYaw = currentEuler.y;
float currentPitch = currentEuler.x;
if (currentPitch > 180)
{
currentPitch -= 360;
}
cinemachineTargetPitch = currentPitch - cameraAngleOverride;
float yaw = currentEuler.y;
float pitch = currentEuler.x;
// --- 核心修复:处理欧拉角跨度问题 ---
// 如果 pitch > 180 (例如 355), 则转为负数 ( -5 )
if (pitch > 180) pitch -= 360;
isRecentering = false;
// 强制执行一次旋转更新,防止下一帧才生效导致的微小跳动 (可选)
// viewSc.cameraRoot.rotation = Quaternion.Euler(
// cinemachineTargetPitch + cameraAngleOverride, cinemachineTargetYaw, 0.0f);
// 更新目标值
cinemachineTargetYaw = yaw;
cinemachineTargetPitch = pitch;
// --- 立即应用旋转 ---
// 强制立即更新一次 cameraRoot防止等待下一帧 Update 产生的跳变
viewSc.cameraRoot.rotation = Quaternion.Euler(cinemachineTargetPitch, cinemachineTargetYaw, 0.0f);
}
}
}

View File

@@ -1,16 +0,0 @@
using UnityEngine;
public class LockTargetCamera : MonoBehaviour
{
// Start is called once before the first execution of Update after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: cbc378284638d9549945b8c5090f5a1b

View File

@@ -0,0 +1,138 @@
using System;
using DG.Tweening;
using SickscoreGames.HUDNavigationSystem;
using UniRx;
using UnityEngine;
using UnityEngine.UI;
using SLSFramework.General;
using Ease = DG.Tweening.Ease;
namespace Cielonos.MainGame.Characters
{
public partial class LockTargetSubmodule : SubmoduleBase<PlayerViewSubcontroller>
{
private Player player => owner.player;
private PlayerViewSubcontroller viewSc => owner;
private PlayerInputSubcontroller inputSc => player.inputSc;
private HUDNavigationSystem navigationSystem => HUDNavigationSystem.Instance;
private HUDNavigationCanvas navigationCanvas => HUDNavigationCanvas.Instance;
/// <summary>
/// 通常ACT类武器锁定目标时自动旋转摄像机即使用LockTargetCamera
/// TPS类远程武器不自动旋转仅在目标上显示锁定标记不切换摄像机
/// </summary>
public bool isAutoRotate;
/// <summary>
/// 是否正在锁定目标
/// </summary>
public bool isLocking;
/// <summary>
/// 是否正在使用锁定目标摄像机
/// </summary>
public bool isUsingLockTargetCamera => isLocking && isAutoRotate;
public bool isDuringSwitch;
public CharacterBase lockTarget;
public Transform targetPoint;
private Tweener iconTween;
public LockTargetSubmodule(PlayerViewSubcontroller owner) : base(owner)
{
isLocking = false;
isAutoRotate = false;
isDuringSwitch = false;
lockTarget = null;
targetPoint = null;
}
public void Update()
{
if (isUsingLockTargetCamera && !isDuringSwitch)
{
viewSc.cameraRoot.LookAt(targetPoint);
float distance = (targetPoint.position - viewSc.cameraRoot.transform.position).Flatten().magnitude;
if (isUsingLockTargetCamera && distance < 1f)
{
UnlockTarget();
}
}
}
}
public partial class LockTargetSubmodule
{
public void SwitchLockState()
{
if (isLocking)
{
UnlockTarget();
}
else
{
LockTarget(true);
}
}
public void LockTarget(bool isAutoRotate)
{
if(isDuringSwitch) return;
CharacterBase target = BattleManager.EnemySm.GetNearestEnemy(50f);
if (target != null)
{
this.isLocking = true;
this.isAutoRotate = isAutoRotate;
this.lockTarget = target;
this.isDuringSwitch = true;
if (isAutoRotate)
{
targetPoint = target.bodyPartsSc.cameraLockingPoint ?? target.bodyPartsSc.staticCenterPoint;
viewSc.currentCamera = viewSc.lockingTargetCamera;
viewSc.lockingTargetCamera.LookAt = targetPoint;
viewSc.stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", true);
viewSc.cameraRoot.DOLookAt(targetPoint.position, 0.5f)
.SetEase(Ease.InOutSine)
.OnComplete(() => { isDuringSwitch = false; })
.Play();
}
else
{
Observable.Timer(TimeSpan.FromSeconds(0.5f)).First().Subscribe(_ =>
{
isDuringSwitch = false;
});
}
lockTarget.navigationElement.showIndicator = true;
Image icon = lockTarget.navigationElement.Indicator.OnscreenIcon;
iconTween?.Kill(true);
iconTween = icon.GetComponent<RectTransform>().DOScale(1f, 0.5f).From(0f).SetEase(Ease.OutQuart).Play();
}
}
public void UnlockTarget()
{
if(isDuringSwitch) return;
if (isAutoRotate)
{
viewSc.cameraRotationSm.SyncRotationWithCamera();
viewSc.stateDrivenCamera.GetComponent<Animator>().SetBool("isLockTarget", false);
viewSc.stateDrivenCamera.InternalUpdateCameraState(Vector3.up, Time.deltaTime);
viewSc.currentCamera = viewSc.freeLookCamera;
}
this.isLocking = false;
this.isAutoRotate = false;
Image icon = lockTarget.navigationElement.Indicator.OnscreenIcon;
iconTween?.Kill(true);
iconTween = icon.GetComponent<RectTransform>().DOScale(0f, 0.5f).SetEase(Ease.OutQuart).OnComplete(() =>
{
lockTarget.navigationElement.showIndicator = false;
this.lockTarget = null;
this.targetPoint = null;
this.isDuringSwitch = false;
}).Play();
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: e462ecfd74196754181689f4a89f54af

View File

@@ -12,99 +12,45 @@ 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 currentCamera;
public CinemachineCamera freeLookCamera;
public CinemachineCamera lockOnCamera;
[FormerlySerializedAs("isLockedOn")] public bool isLockingTarget = false;
public bool isLockedSetRoot;
public CinemachineCamera lockingTargetCamera;
public CharacterBase testEnemy;
public Transform testEnemyTarget;
public CameraRotationSubmodule cameraRotationSm;
public OcclusionFadeSubmodule occlusionFadeSm;
public LockTargetSubmodule lockTargetModule;
public override void Initialize()
{
base.Initialize();
cameraRotationSm = new CameraRotationSubmodule(this, player.transform.eulerAngles.y);
occlusionFadeSm = new OcclusionFadeSubmodule(this);
lockTargetModule = new LockTargetSubmodule(this);
}
private void Start()
{
testEnemyTarget = testEnemy.bodyPartsSc.staticCenterPoint;
//SwitchToLockTarget( testEnemyTarget );
currentCamera = freeLookCamera;
}
private void Update()
{
if (Keyboard.current.tabKey.wasPressedThisFrame)
{
if (!isLockingTarget)
{
SwitchToLockTarget( testEnemyTarget );
}
else
{
SwitchToFreeLook();
}
lockTargetModule.SwitchLockState();
}
}
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();
}
lockTargetModule.Update();
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");
}
}
}