159 lines
4.7 KiB
C#
159 lines
4.7 KiB
C#
using HxGame.Data;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Events;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIMonsterItem_old : MonoBehaviour
|
|
{
|
|
public InputField txtID; //怪物ID
|
|
public Dropdown dropType; //刷怪类型
|
|
public InputField txtPos; //中心点坐标
|
|
public InputField txtRadius; //半径
|
|
public InputField txtNum; //刷怪数量
|
|
public InputField txtTime; //刷怪时间(毫秒)
|
|
public Dropdown dropPatrol; //巡逻类型
|
|
public InputField txtPath; //NPC路径
|
|
|
|
public Button btnDel; //删除
|
|
public List<string> paths;
|
|
public int itemIdx;
|
|
public int pathIdx;
|
|
|
|
// Start is called before the first frame update
|
|
void Awake()
|
|
{
|
|
AddInputNameClickEvent(txtPos);
|
|
AddInputNameClickEvent(txtPath, true);
|
|
btnDel.onClick.AddListener(RemoveSelf);
|
|
itemIdx = 0;
|
|
paths = new List<string>();
|
|
}
|
|
|
|
private void AddInputNameClickEvent(InputField input, bool isPath = false) //可以在Awake中调用
|
|
{
|
|
var eventTrigger = input.gameObject.AddComponent<EventTrigger>();
|
|
UnityAction<BaseEventData> selectEvent = null;
|
|
if (isPath)
|
|
selectEvent = OnPathInputFieldClicked;
|
|
else
|
|
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(txtID.text))
|
|
return;
|
|
if (string.IsNullOrEmpty(txtRadius.text))
|
|
return;
|
|
if (string.IsNullOrEmpty(txtNum.text))
|
|
return;
|
|
|
|
//UIWindow.Instance.uiMonstersPanel_old.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
|
MapManager.Instance.SetMonsterPoint(itemIdx, Convert.ToInt32(txtRadius.text), Convert.ToInt32(txtID.text), Convert.ToInt32(txtNum.text));
|
|
MapManager.Instance.SetEditCellType(MapManager.EditCellType.MonsterArea);
|
|
}
|
|
|
|
private void OnPathInputFieldClicked(BaseEventData data)
|
|
{
|
|
//UIWindow.Instance.uiMonstersPanel_old.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
|
//UIWindow.Instance.uiMonstersPanel_old.curActiveList = paths;
|
|
MapManager.Instance.SetCurMonsterPathIdx(pathIdx);
|
|
MapManager.Instance.SetEditCellType(MapManager.EditCellType.MonsterPath);
|
|
}
|
|
|
|
private void RemoveSelf()
|
|
{
|
|
DestroyImmediate(gameObject);
|
|
MapManager.Instance.RemoveMonsterPoint(itemIdx);
|
|
}
|
|
|
|
public bool CheckValid()
|
|
{
|
|
if (string.IsNullOrEmpty(txtID.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写怪物ID");
|
|
return false;
|
|
}
|
|
if (string.IsNullOrEmpty(txtPos.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写刷怪坐标");
|
|
return false;
|
|
}
|
|
if (string.IsNullOrEmpty(txtRadius.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写刷怪半径");
|
|
return false;
|
|
}
|
|
if (string.IsNullOrEmpty(txtNum.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写刷怪数量");
|
|
return false;
|
|
}
|
|
|
|
if (string.IsNullOrEmpty(txtTime.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("请填写刷怪时间");
|
|
return false;
|
|
}
|
|
|
|
if (dropType.value == (int)CreateMonsterMode.Death)
|
|
{
|
|
if(!APIs.IsUInt(txtTime.text))
|
|
{
|
|
UIWindow.Instance.ShowMessage("刷怪时间请输入正整数");
|
|
return false;
|
|
}
|
|
}
|
|
else if(dropType.value == (int)CreateMonsterMode.FixedTime)
|
|
{
|
|
string[] tmp = txtTime.text.Split(',');
|
|
if (tmp.Length != 2)
|
|
{
|
|
UIWindow.Instance.ShowMessage("刷怪时间用,隔开天数与时间");
|
|
return false;
|
|
}
|
|
|
|
if(!APIs.IsUInt(tmp[0]))
|
|
{
|
|
UIWindow.Instance.ShowMessage("刷怪时间-天数请输入正整数");
|
|
return false;
|
|
}
|
|
|
|
string[] strTime = tmp[1].Split(':');
|
|
if (strTime.Length != 2)
|
|
{
|
|
UIWindow.Instance.ShowMessage("刷怪时间-时间格式错误");
|
|
return false;
|
|
}
|
|
|
|
|
|
for (int i = 0; i < strTime.Length; i++)
|
|
{
|
|
if (!APIs.IsUInt(strTime[i]))
|
|
{
|
|
UIWindow.Instance.ShowMessage("刷怪时间-时间格式错误");
|
|
return false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
}
|
|
}
|