2026-03-26 인벤토리
This commit is contained in:
37
Assets/02_Scripts/UI/_Shared/SplitWindowUI.cs
Normal file
37
Assets/02_Scripts/UI/_Shared/SplitWindowUI.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
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()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
Reference in New Issue
Block a user