92 lines
2.7 KiB
C#
92 lines
2.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UITeleportItem : UIBaseItem
|
|
{
|
|
public InputField txtPos; //传送点坐标
|
|
public InputField txtNextMapID; //下级地图ID
|
|
public InputField txtNextMapPos; //下级地图坐标
|
|
public Button btnDel; //删除
|
|
public int itemIdx;
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
AddInputNameClickEvent(txtPos);
|
|
//AddInputNameClickEvent(txtNextMapPos);
|
|
btnDel.onClick.AddListener(RemoveSelf);
|
|
txtNextMapID.onEndEdit.AddListener((string value) =>
|
|
{
|
|
sceneArea?.RefSAreaInfo();
|
|
});
|
|
txtNextMapPos.onEndEdit.AddListener((string value) =>
|
|
{
|
|
if (!UtilityClass.IsPosValidFormat(value))
|
|
{
|
|
UIWindow.Instance.ShowMessage("传送坐标格式错误");
|
|
return;
|
|
}
|
|
});
|
|
itemIdx = 0;
|
|
}
|
|
|
|
private void AddInputNameClickEvent(InputField input) //可以在Awake中调用
|
|
{
|
|
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
|
|
UnityAction<BaseEventData> 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<InputField>();
|
|
MapManager.Instance.SetCurTeleportPointIdx(itemIdx);
|
|
MapManager.Instance.SetEditCellType(MapManager.EditCellType.TeleportCell);
|
|
}
|
|
|
|
private void RemoveSelf()
|
|
{
|
|
DestroyImmediate(gameObject);
|
|
MapManager.Instance.RemoveTeleportPointSize(itemIdx);
|
|
}
|
|
public override void SetItemPos(Vector2Int pos)
|
|
{
|
|
base.SetItemPos(pos);
|
|
txtPos.text = pos.ToString();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (sceneArea == null) return;
|
|
Destroy(sceneArea.gameObject);
|
|
}
|
|
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;
|
|
}
|
|
}
|