using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; public class UITeleportItem : MonoBehaviour { public InputField txtPos; //传送点坐标 public InputField txtNextMapID; //下级地图ID public InputField txtNextMapPos; //下级地图坐标 public Button btnDel; //删除 public int itemIdx; private void Awake() { AddInputNameClickEvent(txtPos); //AddInputNameClickEvent(txtNextMapPos); btnDel.onClick.AddListener(RemoveSelf); itemIdx = 0; } private void AddInputNameClickEvent(InputField input) //可以在Awake中调用 { var eventTrigger = input.gameObject.AddComponent(); UnityAction selectEvent = OnInputFieldClicked; EventTrigger.Entry onClick = new EventTrigger.Entry() { eventID = EventTriggerType.PointerClick }; onClick.callback.AddListener(selectEvent); eventTrigger.triggers.Add(onClick); } private void OnInputFieldClicked(BaseEventData data) { UIWindow.Instance.uiTeleportPanel.curActiveInput = data.selectedObject.GetComponent(); MapManager.Instance.SetCurTeleportPointIdx(itemIdx); MapManager.Instance.SetEditCellType(MapManager.EditCellType.TeleportCell); } private void RemoveSelf() { DestroyImmediate(gameObject); MapManager.Instance.RemoveTeleportPointSize(itemIdx); } public bool CheckValid() { if (string.IsNullOrEmpty(txtPos.text)) { UIWindow.Instance.ShowMessage("请填写传送坐标"); return false; } if (string.IsNullOrEmpty(txtNextMapID.text)) { UIWindow.Instance.ShowMessage("请填写传送下级地图ID"); return false; } if (string.IsNullOrEmpty(txtNextMapPos.text)) { UIWindow.Instance.ShowMessage("请填写传送下级地图坐标"); return false; } return true; } }