Cute_demon_attacks/meng_yao/Assets/script/Manager/InputUI.cs

45 lines
1.2 KiB
C#
Raw Normal View History

2024-10-31 16:50:35 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class InputUI : MonoBehaviour
{
public InputField inputField;
private void Start()
{
EventTrigger trigger = inputField.gameObject.AddComponent<EventTrigger>();
// <20><><EFBFBD>ӵ<EFBFBD><D3B5><EFBFBD><EFBFBD>¼<EFBFBD>
EventTrigger.Entry clickEntry = new EventTrigger.Entry();
clickEntry.eventID = EventTriggerType.PointerClick;
clickEntry.callback.AddListener((data) => { HidePlaceholder(); });
trigger.triggers.Add(clickEntry);
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD>
EventTrigger.Entry exitEntry = new EventTrigger.Entry();
exitEntry.eventID = EventTriggerType.PointerExit;
exitEntry.callback.AddListener((data) => { ShowPlaceholder(); });
trigger.triggers.Add(exitEntry);
}
private void HidePlaceholder()
{
if (inputField.placeholder != null)
{
inputField.placeholder.gameObject.SetActive(false);
}
}
private void ShowPlaceholder()
{
if (inputField.placeholder != null && string.IsNullOrEmpty(inputField.text))
{
inputField.placeholder.gameObject.SetActive(true);
}
}
}