141 lines
5.2 KiB
C#
141 lines
5.2 KiB
C#
using System.Collections.Generic;
|
||
using Cielonos.MainGame.Inventory;
|
||
using Cielonos.MainGame.UI;
|
||
using SLSUtilities.General;
|
||
using SLSUtilities.FunctionalAnimation;
|
||
using UnityEngine;
|
||
|
||
namespace Cielonos.MainGame.Characters
|
||
{
|
||
public partial class PlayerInventorySubcontroller
|
||
{
|
||
public partial class EquipmentSubmodule : SubmoduleBase<PlayerInventorySubcontroller>
|
||
{
|
||
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 };
|
||
}
|
||
}
|
||
|
||
#region Main Weapon
|
||
|
||
public partial class EquipmentSubmodule
|
||
{
|
||
public void PrepareMainWeapon(MainWeaponBase weaponToPrepare)
|
||
{
|
||
if (!preparedMainWeapons.Contains(weaponToPrepare))
|
||
{
|
||
preparedMainWeapons.Add(weaponToPrepare);
|
||
}
|
||
}
|
||
|
||
public void EquipMainWeapon(MainWeaponBase newWeapon)
|
||
{
|
||
PlayerAnimationSubcontroller animSc = owner.player.animationSc;
|
||
// 停止当前动画到 Empty,确保后续 Rebind 发生在无动画播放的安全状态
|
||
animSc.fullBodyFuncAnimSm.Stop(DisruptionType.Must, 0f);
|
||
|
||
currentMainWeapon = newWeapon;
|
||
|
||
// 开启批处理——后续所有 clip 替换积压到缓冲区
|
||
animSc.BeginOverrideBatch();
|
||
|
||
// 注册武器动画 clip(全部进入缓冲区,不触发 Rebind)
|
||
// OnEquipped:含 SetUp(同样进入缓冲区),内部调用 FlushOverrideBatch 关闭内层
|
||
currentMainWeapon.OnEquipped();
|
||
|
||
// 兜底 Flush:若 OnEquipped 未调用 Flush(如 Yasha 不调 base),在此统一提交
|
||
animSc.FlushOverrideBatch();
|
||
|
||
PlayerCanvas.MainWeaponUIArea.Initialize(newWeapon);
|
||
(owner.player.eventSm as PlayerEventSubmodule)?.onMainWeaponChanged.Invoke(newWeapon);
|
||
}
|
||
|
||
public void RemoveMainWeapon()
|
||
{
|
||
Debug.Log("Unequipping main weapon: " + currentMainWeapon);
|
||
currentMainWeapon.OnUnequipped();
|
||
currentMainWeapon = null;
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
|
||
#region Support Equipment
|
||
|
||
public partial class EquipmentSubmodule
|
||
{
|
||
public void EquipSupportEquipment(SupportEquipmentBase newEquipment, int slotIndex)
|
||
{
|
||
if (slotIndex < 0 || slotIndex >= 4)
|
||
{
|
||
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
|
||
return;
|
||
}
|
||
|
||
//如果当前槽位没有足够的空间,扩展列表
|
||
if (currentSupportEquipments.Count <= slotIndex)
|
||
{
|
||
while (currentSupportEquipments.Count <= slotIndex)
|
||
{
|
||
currentSupportEquipments.Add(null);
|
||
}
|
||
}
|
||
|
||
//卸下当前装备(如果有的话)
|
||
if (currentSupportEquipments[slotIndex] != null)
|
||
{
|
||
currentSupportEquipments[slotIndex].OnUnequipped();
|
||
}
|
||
|
||
currentSupportEquipments[slotIndex] = newEquipment;
|
||
|
||
// 批处理 SupportEquipment 的动画 clip 替换
|
||
PlayerAnimationSubcontroller animSc = owner.player.animationSc;
|
||
animSc.BeginOverrideBatch();
|
||
newEquipment.OnEquipped();
|
||
animSc.FlushOverrideBatch();
|
||
|
||
PlayerCanvas.SupportEquipmentsUIArea.Initialize(newEquipment, slotIndex);
|
||
}
|
||
|
||
public void RemoveSupportEquipment(SupportEquipmentBase equipmentToRemove)
|
||
{
|
||
int slotIndex = currentSupportEquipments.IndexOf(equipmentToRemove);
|
||
|
||
if (slotIndex != -1)
|
||
{
|
||
equipmentToRemove.OnUnequipped();
|
||
currentSupportEquipments[slotIndex] = null;
|
||
|
||
PlayerCanvas.SupportEquipmentsUIArea.Remove(slotIndex);
|
||
}
|
||
}
|
||
|
||
public void RemoveSupportEquipment(int slotIndex)
|
||
{
|
||
if (slotIndex < 0 || slotIndex >= currentSupportEquipments.Count)
|
||
{
|
||
Debug.LogWarning("Invalid support equipment slot index: " + slotIndex);
|
||
return;
|
||
}
|
||
|
||
SupportEquipmentBase equipmentToRemove = currentSupportEquipments[slotIndex];
|
||
if (equipmentToRemove != null)
|
||
{
|
||
equipmentToRemove.OnUnequipped();
|
||
currentSupportEquipments[slotIndex] = null;
|
||
|
||
PlayerCanvas.SupportEquipmentsUIArea.Remove(slotIndex);
|
||
}
|
||
}
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
} |