36 lines
878 B
C#
36 lines
878 B
C#
using UnityEngine;
|
|
using TMPro;
|
|
using System;
|
|
|
|
public class SplitWindowUI : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_InputField _inputField;
|
|
private int _maxAmount;
|
|
private Action<int> _onConfirm;
|
|
|
|
private void Start()
|
|
{
|
|
}
|
|
|
|
public void Open(int max, Action<int> onConfirm)
|
|
{
|
|
gameObject.SetActive(true);
|
|
_maxAmount = max;
|
|
_onConfirm = onConfirm;
|
|
_inputField.text = "1"; // 기본값
|
|
_inputField.ActivateInputField();
|
|
}
|
|
|
|
public void OnClickConfirm()
|
|
{
|
|
if (int.TryParse(_inputField.text, out int amount))
|
|
{
|
|
// 1보다 작으면 1로, 최대치보다 크면 최대치로 보정
|
|
amount = Mathf.Clamp(amount, 1, _maxAmount);
|
|
_onConfirm?.Invoke(amount);
|
|
}
|
|
Close();
|
|
}
|
|
|
|
public void Close() => gameObject.SetActive(false);
|
|
} |