Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/Inventory/EquipmentSubmodule.cs

163 lines
6.7 KiB
C#
Raw Normal View History

2026-05-10 11:47:55 -04:00
using System.Collections.Generic;
2026-05-23 08:27:50 -04:00
using Cielonos.MainGame.Inventory;
2026-05-10 11:47:55 -04:00
using Cielonos.MainGame.UI;
2026-05-23 08:27:50 -04:00
using SLSUtilities.General;
2026-05-10 11:47:55 -04:00
using SLSUtilities.FunctionalAnimation;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
public partial class PlayerInventorySubcontroller
{
2026-07-18 03:16:20 -04:00
public partial class EquipmentSubmodule : SubmoduleBase<PlayerInventorySubcontroller>
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
public List<MainWeaponBase> preparedMainWeapons;
public MainWeaponBase currentMainWeapon;
public List<SupportEquipmentBase> currentSupportEquipments;
public EquipmentSubmodule(PlayerInventorySubcontroller owner) : base(owner)
{
preparedMainWeapons = new List<MainWeaponBase>();
currentSupportEquipments = new List<SupportEquipmentBase>(4) { null, null, null, null };
}
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
#region Main Weapon
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
public partial class EquipmentSubmodule
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
public void PrepareMainWeapon(MainWeaponBase weaponToPrepare)
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
if (!preparedMainWeapons.Contains(weaponToPrepare))
{
preparedMainWeapons.Add(weaponToPrepare);
}
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
public void EquipMainWeapon(MainWeaponBase newWeapon)
{
PlayerAnimationSubcontroller animSc = owner.player.animationSc;
// 停止当前动画到 Empty确保后续 Rebind 发生在无动画播放的安全状态
animSc.fullBodyFuncAnimSm.Stop(DisruptionType.Must, 0f);
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
currentMainWeapon = newWeapon;
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
// 开启批处理——后续所有 clip 替换积压到缓冲区
animSc.BeginOverrideBatch();
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
// 注册武器动画 clip全部进入缓冲区不触发 Rebind
// OnEquipped含 SetUp同样进入缓冲区内部调用 FlushOverrideBatch 关闭内层
currentMainWeapon.OnEquipped();
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
// 兜底 Flush若 OnEquipped 未调用 Flush如 Yasha 不调 base在此统一提交
animSc.FlushOverrideBatch();
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
PlayerCanvas.MainWeaponUIArea.Initialize(newWeapon);
(owner.player.eventSm as Player.PlayerEventSubmodule)?.onMainWeaponChanged.Invoke(newWeapon);
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
public void RemoveMainWeapon()
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
Debug.Log("Unequipping main weapon: " + currentMainWeapon);
currentMainWeapon.OnUnequipped();
currentMainWeapon = null;
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
}
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
#endregion
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
#region Support Equipment
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
public partial class EquipmentSubmodule
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
public void EquipSupportEquipment(SupportEquipmentBase newEquipment, int slotIndex)
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
if (slotIndex < 0 || slotIndex >= 4)
{
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
return;
}
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
//如果当前槽位没有足够的空间,扩展列表
if (currentSupportEquipments.Count <= slotIndex)
{
while (currentSupportEquipments.Count <= slotIndex)
{
currentSupportEquipments.Add(null);
}
}
SupportEquipmentBase currentEquipment = currentSupportEquipments[slotIndex];
if (currentEquipment != null && currentEquipment != newEquipment)
{
// 锁定装备占用槽位,不能被普通的装备替换流程移除。
if (!currentEquipment.CanUnequip)
{
Debug.LogWarning($"Cannot replace locked support equipment: {currentEquipment.name}");
return;
}
currentEquipment.OnUnequipped();
}
currentSupportEquipments[slotIndex] = newEquipment;
// 批处理 SupportEquipment 的动画 clip 替换
PlayerAnimationSubcontroller animSc = owner.player.animationSc;
animSc.BeginOverrideBatch();
newEquipment.OnEquipped();
animSc.FlushOverrideBatch();
PlayerCanvas.SupportEquipmentsUIArea.Initialize(newEquipment, slotIndex);
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
public void RemoveSupportEquipment(SupportEquipmentBase equipmentToRemove, bool force = false)
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
int slotIndex = currentSupportEquipments.IndexOf(equipmentToRemove);
if (slotIndex != -1)
{
// force 仅用于 run 清理和其它非玩家交互的生命周期流程。
if (!force && !equipmentToRemove.CanUnequip)
{
Debug.LogWarning($"Cannot remove locked support equipment: {equipmentToRemove.name}");
return;
}
equipmentToRemove.OnUnequipped();
currentSupportEquipments[slotIndex] = null;
PlayerCanvas.SupportEquipmentsUIArea.Remove(slotIndex);
}
2026-05-10 11:47:55 -04:00
}
2026-07-18 03:16:20 -04:00
public void RemoveSupportEquipment(int slotIndex, bool force = false)
2026-05-10 11:47:55 -04:00
{
2026-07-18 03:16:20 -04:00
if (slotIndex < 0 || slotIndex >= currentSupportEquipments.Count)
{
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
return;
}
2026-05-10 11:47:55 -04:00
2026-07-18 03:16:20 -04:00
SupportEquipmentBase equipmentToRemove = currentSupportEquipments[slotIndex];
if (equipmentToRemove != null)
{
// force 仅用于 run 清理和其它非玩家交互的生命周期流程。
if (!force && !equipmentToRemove.CanUnequip)
{
Debug.LogWarning($"Cannot remove locked support equipment: {equipmentToRemove.name}");
return;
}
equipmentToRemove.OnUnequipped();
currentSupportEquipments[slotIndex] = null;
PlayerCanvas.SupportEquipmentsUIArea.Remove(slotIndex);
}
2026-05-10 11:47:55 -04:00
}
}
2026-07-18 03:16:20 -04:00
#endregion
}
}