sleeping ui dialog
This commit is contained in:
+1729
-26
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 108151baa6db03042b0bcf80b1a30a66
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@@ -11,9 +11,20 @@ public class Bed : BaseInteractableObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void OnAnimationFinished()
|
private void OnAnimationFinished()
|
||||||
|
{
|
||||||
|
TimeManager.Instance.Pause();
|
||||||
|
SliderUI.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel,OnConfirm);
|
||||||
|
}
|
||||||
|
private void OnCancel()
|
||||||
|
{
|
||||||
|
TimeManager.Instance.Resume();
|
||||||
|
OnFastForwardEnd();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConfirm(TimeSpan time)
|
||||||
{
|
{
|
||||||
_player.SetPlayerActing(PlayerStates.Sleeping);
|
_player.SetPlayerActing(PlayerStates.Sleeping);
|
||||||
TimeManager.Instance.FastForward(TimeSpan.FromHours(8), OnFastForwardEnd);
|
TimeManager.Instance.FastForward(time, OnFastForwardEnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFastForwardEnd()
|
private void OnFastForwardEnd()
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class TimeManager : MonoBehaviour
|
|||||||
|
|
||||||
private TimeSpan _timeToStop;
|
private TimeSpan _timeToStop;
|
||||||
private Action _callBackOnFastForward;
|
private Action _callBackOnFastForward;
|
||||||
|
private bool _isPause = false;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
{
|
{
|
||||||
@@ -62,8 +62,11 @@ public class TimeManager : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
UpdateTime();
|
if (!_isPause)
|
||||||
RotateSun();
|
{
|
||||||
|
UpdateTime();
|
||||||
|
RotateSun();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateTime()
|
private void UpdateTime()
|
||||||
@@ -86,6 +89,7 @@ public class TimeManager : MonoBehaviour
|
|||||||
|
|
||||||
public void FastForward(TimeSpan timeToStop,Action callBack)
|
public void FastForward(TimeSpan timeToStop,Action callBack)
|
||||||
{
|
{
|
||||||
|
_isPause = false;
|
||||||
_timeToStop = _currentTime.Add(timeToStop);
|
_timeToStop = _currentTime.Add(timeToStop);
|
||||||
_minuteToRealTime = 0.03f;
|
_minuteToRealTime = 0.03f;
|
||||||
_callBackOnFastForward= callBack;
|
_callBackOnFastForward= callBack;
|
||||||
@@ -120,4 +124,14 @@ public class TimeManager : MonoBehaviour
|
|||||||
|
|
||||||
return diff;
|
return diff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Pause()
|
||||||
|
{
|
||||||
|
_isPause = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
internal void Resume()
|
||||||
|
{
|
||||||
|
_isPause = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user