切换主武器
This commit is contained in:
@@ -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>();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b2c6ef7e33fccdf41848bc44e0432c59
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user