CharacterEntryUI.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. using UnityEngine;
  2. using UnityEngine.UI;
  3. public class CharacterEntryUI : MonoBehaviour
  4. {
  5. public Dropdown weaponDropdown;
  6. public Button removeButton;
  7. private bool isPlayer;
  8. private System.Action<GameObject, bool> onRemove;
  9. private System.Action onChanged;
  10. public void Setup(bool isPlayer, System.Action<GameObject, bool> onRemove, System.Action onChanged)
  11. {
  12. this.isPlayer = isPlayer;
  13. this.onRemove = onRemove;
  14. this.onChanged = onChanged;
  15. removeButton.onClick.AddListener(() => onRemove(gameObject, isPlayer));
  16. weaponDropdown.ClearOptions();
  17. weaponDropdown.AddOptions(new System.Collections.Generic.List<string> { "Sword", "Bow" }); // TODO needs to be collected amongst available weapons
  18. weaponDropdown.onValueChanged.AddListener(_ => onChanged());
  19. }
  20. public CharacterSelection GetSelection()
  21. {
  22. return new CharacterSelection
  23. {
  24. characterName = isPlayer ? "Player" : "Enemy",
  25. weaponType = weaponDropdown.options[weaponDropdown.value].text
  26. };
  27. }
  28. }