반응형
UI Button을 눌렀을 때 무기가 바뀌는 원리
InputManager.cs
CharacterInventory.cs
protected override void HandleInput()
{
if (!AbilityAuthorized
|| (_condition.CurrentState != CharacterStates.CharacterConditions.Normal))
{
return;
}
if (_inputManager.SwitchWeaponButton.State.CurrentState == MMInput.ButtonStates.ButtonDown)
{
SwitchWeapon ();
}
}
InputManger클래스를 참조하고 있으면서 State에 따라 함수 호출
protected virtual void SwitchWeapon()
{
// if there's no character handle weapon component, we can't switch weapon, we do nothing and exit
if ((CharacterHandleWeapon == null) || (WeaponInventory == null))
{
return;
}
FillAvailableWeaponsLists ();
// if we only have 0 or 1 weapon, there's nothing to switch, we do nothing and exit
if (_availableWeaponsIDs.Count <= 0)
{
return;
}
DetermineNextWeaponName ();
EquipWeapon (_nextWeaponID);
PlayAbilityStartFeedbacks();
PlayAbilityStartSfx();
}
public virtual void EquipWeapon(string weaponID)
{
if ((weaponID == _emptySlotWeaponName) && (CharacterHandleWeapon != null))
{
MMInventoryEvent.Trigger(MMInventoryEventType.UnEquipRequest, null, WeaponInventoryName, WeaponInventory.Content[0], 0, 0, PlayerID);
CharacterHandleWeapon.ChangeWeapon(null, _emptySlotWeaponName, false);
MMInventoryEvent.Trigger(MMInventoryEventType.Redraw, null, WeaponInventory.name, null, 0, 0, PlayerID);
return;
}
if ((weaponID == _initialSlotWeaponName) && (CharacterHandleWeapon != null))
{
MMInventoryEvent.Trigger(MMInventoryEventType.UnEquipRequest, null, WeaponInventoryName, WeaponInventory.Content[0], 0, 0, PlayerID);
CharacterHandleWeapon.ChangeWeapon(CharacterHandleWeapon.InitialWeapon, _initialSlotWeaponName, false);
MMInventoryEvent.Trigger(MMInventoryEventType.Redraw, null, WeaponInventory.name, null, 0, 0, PlayerID);
return;
}
for (int i = 0; i < MainInventory.Content.Length ; i++)
{
if (InventoryItem.IsNull(MainInventory.Content[i]))
{
continue;
}
if (MainInventory.Content[i].ItemID == weaponID)
{
MMInventoryEvent.Trigger(MMInventoryEventType.EquipRequest, null, MainInventory.name, MainInventory.Content[i], 0, i, PlayerID);
break;
}
}
}
CharacterHandleWeapon.cs
public virtual void ChangeWeapon(Weapon newWeapon, string weaponID, bool combo = false)
{
// if the character already has a weapon, we make it stop shooting
if (CurrentWeapon != null)
{
CurrentWeapon.TurnWeaponOff();
if (!combo)
{
ShootStop();
if (_weaponAim != null) { _weaponAim.RemoveReticle(); }
Destroy(CurrentWeapon.gameObject);
}
}
if (newWeapon != null)
{
InstantiateWeapon(newWeapon, weaponID, combo);
}
else
{
CurrentWeapon = null;
}
if (OnWeaponChange != null)
{
OnWeaponChange();
}
}
반응형
'Unity > TopdownEngine' 카테고리의 다른 글
카메라가 주인공을 따라가게 만들기 (1) | 2023.02.01 |
---|---|
DialogBox가 납작하게 나올 때 표시 (0) | 2023.01.30 |
Inventory에 아이템 집어넣기 & 초기 Weapon 설정 (0) | 2023.01.29 |
MMEvnet 예제 (0) | 2023.01.29 |
MMEvent 동작 원리 (0) | 2023.01.29 |