using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; using UnityEngine.UI; using UnityEngine.EventSystems; using UnityEngine.Events; namespace Assets.Scripts.UI.Control { public class PFUIDropdown : PFUIComponentBase { private int mSelectedIndex = 0; public int SelectedIndex { get { return this.mSelectedIndex; } } //public int Value //{ // get // { // return this.GetComponent().value; // } // set // { // this.GetComponent().value = value; // } //} public string SelectedItem { get { if(this.mSelectedIndex >= 0) { return this.GetComponent().options[this.mSelectedIndex].text; } return null; } } private UnityAction mOnValueChange; public UnityAction OnValueChange { get { return mOnValueChange; } set { mOnValueChange = value; } } private Outline outline; void Awake() { //this.mSelectedIndex = //UIManager.AddEvent(this.transform.GetComponent().gameObject, EventTriggerType.Select, new UnityEngine.Events.UnityAction(OnSelect)); //UIManager.AddEvent(this.transform.GetComponent().gameObject, EventTriggerType.Deselect, new UnityEngine.Events.UnityAction(OnDeselect)); this.GetComponent().onValueChanged.AddListener(i => { mSelectedIndex = i; if (OnValueChange != null) { mOnValueChange(i); } outline.enabled = false; }); outline = transform.GetComponent(); } public void SetValidate() { outline.enabled = true; } //public void SetValidate(string s) //{ // outline.gameObject.SetActive(true); //} public void OnSelect(BaseEventData eventData) { var image = this.transform.GetComponent(); var png = Resources.Load("Images/ipt-1"); image.sprite = png; } public void OnDeselect(BaseEventData eventData) { var image = this.transform.GetComponent(); var png1 = Resources.Load("Images/ipt-0"); image.sprite = png1; } public void AddOptions(List options) { this.GetComponent().AddOptions(options); } public void AddOptions(List options) { this.GetComponent().AddOptions(options); } public void ClearOptions() { this.GetComponent().ClearOptions(); } public void SelectIndex(int index) { this.GetComponent().value = index; this.mSelectedIndex = index; } public void SelectValue(string value) { var options = this.GetComponent().options; for (int i = 0; i < options.Count; i++) { if(options[i].text == value) { SelectIndex(i); return; } } } } }