sleeping ui dialog
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SliderUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _description;
|
||||
[SerializeField]
|
||||
private Button _btnCancel;
|
||||
[SerializeField]
|
||||
private Button _btnOk;
|
||||
[SerializeField]
|
||||
private Slider _slider;
|
||||
|
||||
public static SliderUI Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
Hide();
|
||||
}
|
||||
|
||||
public TimeSpan ShowTimeSliderDialog(string title,string description,Action onCancel,Action<TimeSpan> onConfirm)
|
||||
{
|
||||
TimeSpan retTime=TimeSpan.Zero;
|
||||
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
_description.text = description;
|
||||
_btnCancel.onClick.AddListener(() =>
|
||||
{
|
||||
onCancel?.Invoke();
|
||||
Hide();
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
onConfirm?.Invoke(TimeSpan.FromSeconds(_slider.value));
|
||||
Hide();
|
||||
});
|
||||
|
||||
return retTime;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
var time = TimeSpan.FromSeconds(_slider.value);
|
||||
|
||||
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
||||
}
|
||||
|
||||
private void Hide()
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user