little refactor
This commit is contained in:
@@ -140,7 +140,7 @@ Material:
|
||||
- _Strength: 0.2
|
||||
- _Surface: 1
|
||||
- _UseUIAlphaClip: 0
|
||||
- _Value: 0.004
|
||||
- _Value: 0.0021
|
||||
- _WorkflowMode: 1
|
||||
- _ZWrite: 0
|
||||
m_Colors:
|
||||
|
||||
+56
-1938
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15f8d2a34d602b04c9694f4eea8948d3
|
||||
PrefabImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -6,8 +6,6 @@ public class CameraSystem : MonoBehaviour
|
||||
[SerializeField]
|
||||
private CinemachineVirtualCamera _camera;
|
||||
|
||||
private float _moveSpeed = 50f;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
//transform.position = Player.Instance.transform.position;
|
||||
|
||||
@@ -12,7 +12,7 @@ public class Bed : BaseInteractableObject
|
||||
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
SliderUI.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel,OnConfirm);
|
||||
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
|
||||
}
|
||||
private void OnCancel()
|
||||
{
|
||||
@@ -22,12 +22,14 @@ public class Bed : BaseInteractableObject
|
||||
private void OnConfirm(TimeSpan time)
|
||||
{
|
||||
_player.SetPlayerActing(PlayerStates.Sleeping);
|
||||
TimeManager.Instance.FastForward(time, OnFastForwardEnd);
|
||||
TimeManager.Instance.FastForward(time);
|
||||
TimeManager.Instance.OnFastForwardEnd += OnFastForwardEnd;
|
||||
}
|
||||
|
||||
private void OnFastForwardEnd()
|
||||
{
|
||||
_player.SetPlayerActing(PlayerStates.Awake);
|
||||
_player.SetPlayerAnimation(AnimationStates.Standing);
|
||||
TimeManager.Instance.OnFastForwardEnd -= OnFastForwardEnd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
TimeManager.OnMinuteChanged += UpdateStatsByClock;
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateStatsByClock;
|
||||
_animator.applyRootMotion = true;
|
||||
_navAgent.updatePosition = false;
|
||||
Stats = PlayerStats.CreateInitialStats();
|
||||
@@ -55,7 +55,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
TimeManager.OnMinuteChanged -= UpdateStatsByClock;
|
||||
TimeManager.Instance.OnMinuteChanged -= UpdateStatsByClock;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class TimeManager : MonoBehaviour
|
||||
{
|
||||
public static TimeManager Instance { get; private set; }
|
||||
|
||||
private const float MINUTE_TIME = 0.5f;
|
||||
private const float MINUTE_TIME = 1f;
|
||||
private const float FF_TIME = 0.003f;
|
||||
|
||||
public static Action OnMinuteChanged;
|
||||
public Action OnMinuteChanged;
|
||||
public Action OnFastForwardEnd;
|
||||
|
||||
[SerializeField]
|
||||
private float _startHour;
|
||||
@@ -32,8 +33,10 @@ public class TimeManager : MonoBehaviour
|
||||
private static TimeSpan _currentTime;
|
||||
public static TimeSpan CurrentTime => _currentTime;
|
||||
|
||||
|
||||
|
||||
private TimeSpan _timeToStop;
|
||||
private Action _callBackOnFastForward;
|
||||
|
||||
private bool _isPause = false;
|
||||
|
||||
private void Awake()
|
||||
@@ -81,18 +84,17 @@ public class TimeManager : MonoBehaviour
|
||||
{
|
||||
_minuteToRealTime = MINUTE_TIME;
|
||||
_timeToStop = TimeSpan.MaxValue;
|
||||
_callBackOnFastForward?.Invoke();
|
||||
OnFastForwardEnd?.Invoke();
|
||||
}
|
||||
_timer = _minuteToRealTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void FastForward(TimeSpan timeToStop,Action callBack)
|
||||
public void FastForward(TimeSpan timeToStop)
|
||||
{
|
||||
_isPause = false;
|
||||
_timeToStop = _currentTime.Add(timeToStop);
|
||||
_minuteToRealTime = 0.03f;
|
||||
_callBackOnFastForward= callBack;
|
||||
_minuteToRealTime = FF_TIME;
|
||||
}
|
||||
|
||||
private void RotateSun()
|
||||
|
||||
+18
-23
@@ -3,7 +3,7 @@ using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SliderUI : MonoBehaviour
|
||||
public class TimeSliderUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _title;
|
||||
@@ -16,27 +16,12 @@ public class SliderUI : MonoBehaviour
|
||||
[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)
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
TimeManager.Instance.OnFastForwardEnd += CloseDialog;
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||
TimeManager.Instance.Pause();
|
||||
TimeSpan retTime=TimeSpan.Zero;
|
||||
UIManager.Instance.Freeze();
|
||||
|
||||
gameObject.SetActive(true);
|
||||
_title.text = title;
|
||||
@@ -45,6 +30,7 @@ public class SliderUI : MonoBehaviour
|
||||
{
|
||||
onCancel?.Invoke();
|
||||
Hide();
|
||||
CloseDialog();
|
||||
});
|
||||
_btnOk.onClick.AddListener(() =>
|
||||
{
|
||||
@@ -52,20 +38,29 @@ public class SliderUI : MonoBehaviour
|
||||
Hide();
|
||||
});
|
||||
|
||||
return retTime;
|
||||
}
|
||||
|
||||
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()
|
||||
{
|
||||
TimeManager.Instance.Resume();
|
||||
gameObject.SetActive(false);
|
||||
TimeManager.Instance.Resume();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,48 +1,49 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class GameUIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _timeText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _moneyText;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _energy;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _food;
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void OnEnable()
|
||||
{
|
||||
TimeManager.OnMinuteChanged += UpdateTime;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
TimeManager.OnMinuteChanged -= UpdateTime;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_moneyText.text = $"${Player.Instance.Stats[StatsId.Money].Value}";
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
if (_timeText != null)
|
||||
{
|
||||
_timeText.text = TimeManager.CurrentTime.ToString(@"hh\:mm");
|
||||
}
|
||||
|
||||
_energy.value = (float)Player.Instance.Stats[StatsId.Energy].Value;
|
||||
_food.value = (float)Player.Instance.Stats[StatsId.Food].Value;
|
||||
}
|
||||
}
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class TopBarUI : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _timeText;
|
||||
|
||||
[SerializeField]
|
||||
private TextMeshProUGUI _moneyText;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _energy;
|
||||
|
||||
[SerializeField]
|
||||
public Slider _food;
|
||||
|
||||
|
||||
// Start is called before the first frame update
|
||||
private void Start()
|
||||
{
|
||||
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
TimeManager.Instance.OnMinuteChanged -= UpdateTime;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
_moneyText.text = $"${Player.Instance.Stats[StatsId.Money].Value}";
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void UpdateTime()
|
||||
{
|
||||
if (_timeText != null)
|
||||
{
|
||||
_timeText.text = TimeManager.CurrentTime.ToString(@"hh\:mm");
|
||||
}
|
||||
|
||||
_energy.value = (float)Player.Instance.Stats[StatsId.Energy].Value;
|
||||
_food.value = (float)Player.Instance.Stats[StatsId.Food].Value;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class UIManager : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
public TimeSliderUI _timeSliderPrefab;
|
||||
[SerializeField]
|
||||
public GameObject _blurOverlay;
|
||||
|
||||
public static UIManager Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_blurOverlay.SetActive(false);
|
||||
}
|
||||
|
||||
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||
{
|
||||
var timeSlider = Instantiate(_timeSliderPrefab, transform);
|
||||
timeSlider.ShowTimeSliderDialog(title, description, onCancel, onConfirm);
|
||||
}
|
||||
|
||||
public void Freeze()
|
||||
{
|
||||
_blurOverlay.SetActive(true);
|
||||
}
|
||||
|
||||
public void Unfreeze()
|
||||
{
|
||||
_blurOverlay.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 152bb7481f494844aa5ddb27a421f8b4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user