the ability to switch weapons
This commit is contained in:
parent
0722053b84
commit
533f137c48
12 changed files with 928 additions and 15 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
|
@ -21,12 +22,20 @@ public class ActionUIHandler : MonoBehaviour
|
|||
private PlayerEntity selectedEntity;
|
||||
private RangedWeapon possibleRanged;
|
||||
public bool opened;
|
||||
[Header("UI")]
|
||||
[Header("Main UI")]
|
||||
[SerializeField] private Vector3 offset;
|
||||
[SerializeField] private GameObject actionUI;
|
||||
[Header("Action Buttons")]
|
||||
[SerializeField] private Button moveButton;
|
||||
[SerializeField] private Button attackButton;
|
||||
[SerializeField] private Button reloadButton;
|
||||
[SerializeField] private Button switchButton;
|
||||
|
||||
[Header("Weapon Switcher")]
|
||||
[SerializeField] private RectTransform weaponUIPanel;
|
||||
[SerializeField] private Button templateWeaponButton;
|
||||
[SerializeField] private float templateButtonHeight;
|
||||
|
||||
//500 if statements in this script lol
|
||||
public void ShowUI(PlayerEntity target)
|
||||
{
|
||||
|
|
@ -48,27 +57,25 @@ public class ActionUIHandler : MonoBehaviour
|
|||
}
|
||||
if (!isRanged || !isRanged.fired)
|
||||
{
|
||||
reloadButton.gameObject.SetActive(false);
|
||||
attackButton.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
reloadButton.gameObject.SetActive(true);
|
||||
attackButton.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
reloadButton.gameObject.SetActive(false);
|
||||
attackButton.gameObject.SetActive(false);
|
||||
}
|
||||
if (!selectedEntity.hasMoved || !selectedEntity.hasAttacked)
|
||||
{
|
||||
moveButton.gameObject.SetActive(true);
|
||||
switchButton.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
moveButton.gameObject.SetActive(false);
|
||||
reloadButton.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
if (selectedEntity.hasAttacked && selectedEntity.hasMoved)
|
||||
|
|
@ -80,13 +87,14 @@ public class ActionUIHandler : MonoBehaviour
|
|||
{
|
||||
opened = false;
|
||||
actionUI.SetActive(false);
|
||||
weaponUIPanel.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void ReloadGun()
|
||||
{
|
||||
possibleRanged.Reload();
|
||||
selectedEntity.hasAttacked = true;
|
||||
UpdateUI();
|
||||
HideUI();
|
||||
}
|
||||
|
||||
public void Attack()
|
||||
|
|
@ -105,4 +113,56 @@ public class ActionUIHandler : MonoBehaviour
|
|||
HideUI();
|
||||
PlayerEntityMovement.instance.SelectEntity(selectedEntity);
|
||||
}
|
||||
|
||||
public void ShowWeaponList()
|
||||
{
|
||||
foreach (Transform oldButton in weaponUIPanel)
|
||||
{
|
||||
Destroy(oldButton.gameObject);
|
||||
}
|
||||
if (weaponUIPanel.gameObject.activeSelf)
|
||||
{
|
||||
HideWeaponList();
|
||||
return;
|
||||
}
|
||||
weaponUIPanel.gameObject.SetActive(true);
|
||||
weaponUIPanel.sizeDelta = new Vector2(weaponUIPanel.sizeDelta.x, templateButtonHeight * selectedEntity.weaponInstances.Count);
|
||||
foreach (Weapon weapon in selectedEntity.weaponInstances)
|
||||
{
|
||||
Button newButton = Instantiate(templateWeaponButton, weaponUIPanel);
|
||||
newButton.gameObject.SetActive(true);
|
||||
if (weapon != selectedEntity.currentWeapon)
|
||||
{
|
||||
newButton.onClick.AddListener(() => SelectWeapon(weapon));
|
||||
newButton.GetComponentInChildren<TextMeshProUGUI>().text = weapon.weaponName;
|
||||
}
|
||||
else
|
||||
{
|
||||
newButton.GetComponentInChildren<TextMeshProUGUI>().text = $"{weapon.weaponName} (Equipped)";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SelectWeapon(Weapon weaponSelected)
|
||||
{
|
||||
MoveAction();
|
||||
selectedEntity.currentWeapon = weaponSelected;
|
||||
UpdateUI();
|
||||
}
|
||||
|
||||
private void HideWeaponList()
|
||||
{
|
||||
weaponUIPanel.gameObject.SetActive(false);
|
||||
}
|
||||
private void MoveAction()
|
||||
{
|
||||
if (!selectedEntity.hasMoved)
|
||||
{
|
||||
selectedEntity.hasMoved = true;
|
||||
}
|
||||
else if (!selectedEntity.hasAttacked)
|
||||
{
|
||||
selectedEntity.hasAttacked = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
using UnityEngine;
|
||||
|
||||
public class MeleeWeapon : MonoBehaviour
|
||||
public class MeleeWeapon : Weapon
|
||||
{
|
||||
|
||||
public virtual void AttackEffects()
|
||||
protected override void AttackEffects()
|
||||
{
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ public class PlayerEntity : Entity
|
|||
public bool hasAttacked = false;
|
||||
[Header("Weaponry")]
|
||||
[SerializeField] private Weapon[] weapons;
|
||||
private List<Weapon> weaponInstances = new();
|
||||
[HideInInspector] public List<Weapon> weaponInstances = new();
|
||||
public Weapon currentWeapon;
|
||||
[Header("UI")]
|
||||
[SerializeField] private Transform hpBar;
|
||||
|
|
@ -51,9 +51,9 @@ public class PlayerEntity : Entity
|
|||
currentWeapon.TryAttack();
|
||||
}
|
||||
|
||||
public void SwitchWeapon()
|
||||
public void SwitchWeapon(Weapon requestedWeapon)
|
||||
{
|
||||
|
||||
currentWeapon = requestedWeapon;
|
||||
}
|
||||
|
||||
protected override void FinishedMovement()
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ using UnityEngine;
|
|||
|
||||
public class Weapon : MonoBehaviour
|
||||
{
|
||||
public string weaponName;
|
||||
public PlayerEntity thisEntity;
|
||||
public virtual void TryAttack()
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue