little refactor
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TimeSliderUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _description;
|
||||
[SerializeField]
|
||||
private Button _btnCancel;
|
||||
[SerializeField]
|
||||
private Button _btnOk;
|
||||
[SerializeField]
|
||||
private Slider _slider;
|
||||
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
TimeManager.Instance.OnFastForwardEnd += CloseDialog;
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||
TimeManager.Instance.Pause();
|
||||
UIManager.Instance.Freeze();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
_description.text = description;
|
||||
_btnCancel.onClick.AddListener(() =>
|
||||
{
|
||||
onCancel?.Invoke();
|
||||
Hide();
|
||||
CloseDialog();
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke(TimeSpan.FromSeconds(_slider.value));
|
||||
Hide();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
}
|
||||
|
||||
private void CloseDialog()
|
||||
{
|
||||
UIManager.Instance.Unfreeze();
|
||||
Destroy(this);
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = TimeSpan.FromSeconds(_slider.value);
|
||||
|
||||
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
TimeManager.Instance.Resume();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user