Files
Cielonos/Assets/Scripts/MainGame/Characters/Player/Inventory/PlayerInventorySubcontroller.cs
SoulliesOfficial 2a2aa728d5 切换主武器
2025-12-23 19:47:06 -05:00

154 lines
5.2 KiB
C#

using Cielonos.MainGame.Inventory;
using UnityEngine;
namespace Cielonos.MainGame.Characters
{
public partial class PlayerInventorySubcontroller : SubcontrollerBase<Player>, IPlayerSubcontroller
{
public Player player => owner;
private PlayerInputSubcontroller inputSc => player.inputSc;
private PlayerOperationSubcontroller operationSc => player.operationSc;
public PlayerBackpack backpack;
public PlayerEquipmentSubmodule equipmentSm;
public override void Initialize()
{
base.Initialize();
RegisterOperations();
equipmentSm ??= new PlayerEquipmentSubmodule(this);
}
}
public partial class PlayerInventorySubcontroller
{
private MainWeaponBase currentMainWeapon => equipmentSm.currentMainWeapon;
private void RegisterOperations()
{
//operationSc.OnMainWeaponSpecialPress += MainWeaponSpecialPress;
//operationSc.OnMainWeaponSpecialRelease += MainWeaponSpecialRelease;
operationSc.OnMainWeaponPrimaryPress += MainWeaponPrimaryPress;
operationSc.OnMainWeaponPrimaryRelease += MainWeaponPrimaryRelease;
operationSc.OnMainWeaponSecondaryPress += MainWeaponSecondaryPress;
operationSc.OnMainWeaponSecondaryRelease += MainWeaponSecondaryRelease;
operationSc.OnMainWeaponTertiaryPress += MainWeaponSpecialAPress;
operationSc.OnMainWeaponTertiaryRelease += MainWeaponSpecialARelease;
operationSc.OnMainWeaponQuaternaryPress += MainWeaponSpecialBPress;
operationSc.OnMainWeaponQuaternaryRelease += MainWeaponSpecialBRelease;
operationSc.OnSwitchMainWeapon += SwitchMainWeapon;
/*
operationSc.OnSwitchMainWeapon += delegate(float dir) { SwitchMainWeapon(dir > 0 ? 1 : -1); };
operationSc.OnUseSupportEquipment0Press += delegate { SupportEquipmentPress(0); };
operationSc.OnUseSupportEquipment1Press += delegate { SupportEquipmentPress(1); };
operationSc.OnUseSupportEquipment2Press += delegate { SupportEquipmentPress(2); };
operationSc.OnUseSupportEquipment3Press += delegate { SupportEquipmentPress(3); };
operationSc.OnReload += MainWeaponReload;*/
}
public virtual void Update()
{
if (inputSc.IsHoldingPrimary)
{
currentMainWeapon.OnPrimaryHold();
}
if (inputSc.IsHoldingSecondary)
{
currentMainWeapon.OnSecondaryHold();
}
if (inputSc.IsHoldingSpecialA)
{
currentMainWeapon.OnSpecialAHold();
}
if (inputSc.IsHoldingSpecialB)
{
currentMainWeapon.OnSpecialBHold();
}
}
}
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)
{
currentMainWeapon.OnPrimaryPress();
player.movementSc.isSprinting = false;
}
}
public void MainWeaponPrimaryRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnPrimaryRelease();
}
}
public void MainWeaponSecondaryPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryPress();
player.movementSc.isSprinting = false;
}
}
public void MainWeaponSecondaryRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSecondaryRelease();
}
}
public void MainWeaponSpecialAPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialAPress();
player.movementSc.isSprinting = false;
}
}
public void MainWeaponSpecialARelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialARelease();
}
}
public void MainWeaponSpecialBPress()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialBPress();
player.movementSc.isSprinting = false;
}
}
public void MainWeaponSpecialBRelease()
{
if (currentMainWeapon != null)
{
currentMainWeapon.OnSpecialBRelease();
}
}
}
}