45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
|
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);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|