第一次提交
This commit is contained in:
87
Assets/Scripts/UI/UINpcItem.cs
Normal file
87
Assets/Scripts/UI/UINpcItem.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using HxGame;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class UINpcItem : MonoBehaviour
|
||||
{
|
||||
public InputField txtPos; //NPC<50><43><EFBFBD><EFBFBD>
|
||||
public InputField txtID; //NPCID
|
||||
public Dropdown dropDir; //Npc<70><63><EFBFBD><EFBFBD>
|
||||
public InputField txtPath; //NPC·<43><C2B7>
|
||||
public InputField txtName; //NPC<50><43><EFBFBD><EFBFBD>
|
||||
public Button btnDel; //ɾ<><C9BE>
|
||||
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) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Awake<6B>е<EFBFBD><D0B5><EFBFBD>
|
||||
{
|
||||
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)
|
||||
{
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
|
||||
MapManager.Instance.SetCurNpcPointIdx(itemIdx);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.NpcCell);
|
||||
}
|
||||
|
||||
private void OnPathInputFieldClicked(BaseEventData data)
|
||||
{
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveInput = data.selectedObject.GetComponent<InputField>();
|
||||
UIWindow.Instance.uiNpcsPanel.curActiveList = paths;
|
||||
MapManager.Instance.SetCurNpcPathIdx(pathIdx);
|
||||
MapManager.Instance.SetEditCellType(MapManager.EditCellType.NpcPath);
|
||||
}
|
||||
|
||||
|
||||
private void RemoveSelf()
|
||||
{
|
||||
DestroyImmediate(gameObject);
|
||||
MapManager.Instance.RemoveNpcPointSize(itemIdx);
|
||||
}
|
||||
|
||||
public bool CheckValid()
|
||||
{
|
||||
if (string.IsNullOrEmpty(txtID.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дNpcID");
|
||||
return false;
|
||||
}
|
||||
if (string.IsNullOrEmpty(txtPos.text))
|
||||
{
|
||||
UIWindow.Instance.ShowMessage("<22><><EFBFBD><EFBFBD>дNpc<70><63><EFBFBD><EFBFBD>");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user