89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIReliveItem : UIBaseItem
|
|
{
|
|
public Dropdown dropType;
|
|
public InputField txtMapId; //地图ID
|
|
public InputField txtPos; //中心点坐标
|
|
public InputField txtRadius; //半径
|
|
|
|
public Button btnDel; //删除
|
|
public int reliveIdx;
|
|
|
|
// Start is called before the first frame update
|
|
protected override void Awake()
|
|
{
|
|
base.Awake();
|
|
AddInputNameClickEvent(txtPos);
|
|
btnDel.onClick.AddListener(RemoveSelf);
|
|
reliveIdx = 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)
|
|
{
|
|
if (string.IsNullOrEmpty(txtRadius.text))
|
|
return;
|
|
|
|
UIWindow.Instance.uiRelivesPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
|
MapManager.Instance.SetReliveCenterPoint(reliveIdx, Convert.ToInt32(txtRadius.text));
|
|
MapManager.Instance.SetEditCellType(MapManager.EditCellType.ReliveCell);
|
|
}
|
|
|
|
private void RemoveSelf()
|
|
{
|
|
DestroyImmediate(gameObject);
|
|
MapManager.Instance.RemoveReliveCenterPoint(reliveIdx);
|
|
}
|
|
public override void SetItemPos(Vector2Int pos)
|
|
{
|
|
base.SetItemPos(pos);
|
|
txtPos.text = pos.ToString();
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
if (sceneArea == null) return;
|
|
DestroyImmediate(sceneArea.gameObject);
|
|
}
|
|
public bool CheckValid()
|
|
{
|
|
if (string.IsNullOrEmpty(txtMapId.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写复活地图");
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(txtPos.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写复活点坐标");
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(txtRadius.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写复活点半径");
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|