using System; using TMPro; using UnityEngine; using UnityEngine.UI; /// /// UIButton은 버튼이라는 오브젝트를 위한 클래스 /// /// /// 1. GameScene과 같은 Scene에서 UIManager의 UIList에 "Button_Attack"과 같이 사용할 버튼의 이름을 추가 /// /// Manager.UI.UIList = new List<string> { "Button_Attack" }; /// /// 2. GameScene과 같은 Scene에서 UI 호출하게 되면 다음과 같이 버튼을 설정 /// /// UIButton atkbtn = Manager.UI.SwitchOnObject<UIButton>("Button_Attack", true); /// if (atkbtn != null) /// { /// atkbtn.SetButtonContents(null,"공", false, true); /// atkbtn.SetButtonRect("Button_Attack", new Vector2(50, 150)); /// // 아래 코드는 버튼이 클릭 되었을 경우 InputManager의 OnClicked 함수를 호출 /// atkbtn.OnButtonClicked += Manager.Input.OnClicked; /// } /// /// 3. 만약에 해당 버튼을 사용하는 오브젝트(예: PlayerController)에서 버튼 클릭 이벤트를 받고 싶다면 Start에 다음 같이 설정 /// /// void Start() /// { /// Manager.Input.RegisterAction("Button_Attack", OnAttack); /// } /// /// private void OnAttack() /// { /// if (!_isAttack) /// { /// _isAttack = true; /// Behavior = PlayerBehavior.Attack; /// } /// } /// /// public class UIButton: MonoBehaviour { private string _name; public string Name { get { return _name; } private set { _name = value; _button.gameObject.name = _name; } } public event Action OnButtonClicked; private Button _button; // 모든 버튼의 백그라운드 동작은 항상 private Image _background; private GameObject _stackView; private Image _image; private TextMeshProUGUI _text; public enum Button_Objects { Button, BackGround, Stack, Image, Text, }; private void Awake() { if (_button == null) { _button = GetComponent