132 lines
3.8 KiB
C#
132 lines
3.8 KiB
C#
using Cysharp.Threading.Tasks;
|
|
using SampleProject;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.UI;
|
|
using UVC.Factory.Component;
|
|
using UVC.Locale;
|
|
using UVC.UI.Modal;
|
|
using UVC.Util;
|
|
|
|
namespace UVC.Factory.Buttons
|
|
{
|
|
public class UISearchInput : MonoBehaviour
|
|
{
|
|
private TMP_InputField inputField;
|
|
|
|
private Button button;
|
|
private GameObject textArea;
|
|
|
|
private bool initialized = false;
|
|
|
|
private bool isClicked = false;
|
|
|
|
void Awake()
|
|
{
|
|
SceneMain.Instance.Initialized += OnSceneInitialized;
|
|
}
|
|
|
|
private void OnSceneInitialized()
|
|
{
|
|
inputField = GetComponent<TMP_InputField>();
|
|
|
|
button = GetComponentInChildren<Button>();
|
|
button.onClick.AddListener(() =>
|
|
{
|
|
isClicked = !isClicked;
|
|
if (isClicked)
|
|
{
|
|
//button.image.color = ColorUtil.FromHex("#00B0B0");
|
|
//textArea.gameObject.SetActive(true);
|
|
inputField.Select();
|
|
}
|
|
else
|
|
{
|
|
Location(inputField.text);
|
|
//button.image.color = Color.white;
|
|
//textArea.gameObject.SetActive(false);
|
|
inputField.OnDeselect(null);
|
|
}
|
|
});
|
|
textArea = transform.Find("Text Area").gameObject;
|
|
inputField.onEndEdit.AddListener(OnFindLocation);
|
|
//textArea.gameObject.SetActive(false);
|
|
|
|
Init();
|
|
}
|
|
|
|
private void OnFindLocation(string locationID)
|
|
{
|
|
if (isClicked == false)
|
|
return;
|
|
if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
|
|
{
|
|
Location(locationID);
|
|
isClicked = false;
|
|
button.image.color = Color.white;
|
|
//textArea.gameObject.SetActive(false);
|
|
inputField.OnDeselect(null);
|
|
}
|
|
}
|
|
|
|
private void Location(string locationID)
|
|
{
|
|
if (string.IsNullOrEmpty(locationID))
|
|
return;
|
|
FactoryObject? factoryObject = FactoryObjectManager.Instance.FindById(locationID);
|
|
if (factoryObject == null)
|
|
{
|
|
Alert.Show(LocalizationManager.Instance.GetString("warning"), locationID + " " +
|
|
LocalizationManager.Instance.GetString("nosearch")).Forget();
|
|
return;
|
|
}
|
|
FactoryCameraController.Instance.FocusOnTarget(factoryObject.transform.position, 15);
|
|
inputField.text = "";
|
|
}
|
|
|
|
private void Init()
|
|
{
|
|
if (!initialized)
|
|
{
|
|
inputField.placeholder.GetComponent<TextMeshProUGUI>().text = LocalizationManager.Instance.GetString("search_location");
|
|
initialized = true;
|
|
}
|
|
//textArea.gameObject.SetActive(false);
|
|
isClicked = false;
|
|
}
|
|
|
|
|
|
void OnDestroy()
|
|
{
|
|
SceneMain.Instance.Initialized -= OnSceneInitialized;
|
|
|
|
if (inputField != null)
|
|
{
|
|
inputField = null;
|
|
}
|
|
|
|
if (button != null)
|
|
{
|
|
button.onClick.RemoveAllListeners();
|
|
button = null;
|
|
}
|
|
}
|
|
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetMouseButtonDown(0))
|
|
{
|
|
if (EventSystem.current.currentSelectedGameObject != null)
|
|
return;
|
|
//textArea.gameObject.SetActive(false);
|
|
inputField.OnDeselect(null);
|
|
inputField.text = "";
|
|
button.image.color = Color.white;
|
|
isClicked = false;
|
|
}
|
|
}
|
|
}
|
|
}
|