little refactor
This commit is contained in:
@@ -140,7 +140,7 @@ Material:
|
|||||||
- _Strength: 0.2
|
- _Strength: 0.2
|
||||||
- _Surface: 1
|
- _Surface: 1
|
||||||
- _UseUIAlphaClip: 0
|
- _UseUIAlphaClip: 0
|
||||||
- _Value: 0.004
|
- _Value: 0.0021
|
||||||
- _WorkflowMode: 1
|
- _WorkflowMode: 1
|
||||||
- _ZWrite: 0
|
- _ZWrite: 0
|
||||||
m_Colors:
|
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]
|
[SerializeField]
|
||||||
private CinemachineVirtualCamera _camera;
|
private CinemachineVirtualCamera _camera;
|
||||||
|
|
||||||
private float _moveSpeed = 50f;
|
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
//transform.position = Player.Instance.transform.position;
|
//transform.position = Player.Instance.transform.position;
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public class Bed : BaseInteractableObject
|
|||||||
|
|
||||||
private void OnAnimationFinished()
|
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()
|
private void OnCancel()
|
||||||
{
|
{
|
||||||
@@ -22,12 +22,14 @@ public class Bed : BaseInteractableObject
|
|||||||
private void OnConfirm(TimeSpan time)
|
private void OnConfirm(TimeSpan time)
|
||||||
{
|
{
|
||||||
_player.SetPlayerActing(PlayerStates.Sleeping);
|
_player.SetPlayerActing(PlayerStates.Sleeping);
|
||||||
TimeManager.Instance.FastForward(time, OnFastForwardEnd);
|
TimeManager.Instance.FastForward(time);
|
||||||
|
TimeManager.Instance.OnFastForwardEnd += OnFastForwardEnd;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFastForwardEnd()
|
private void OnFastForwardEnd()
|
||||||
{
|
{
|
||||||
_player.SetPlayerActing(PlayerStates.Awake);
|
_player.SetPlayerActing(PlayerStates.Awake);
|
||||||
_player.SetPlayerAnimation(AnimationStates.Standing);
|
_player.SetPlayerAnimation(AnimationStates.Standing);
|
||||||
|
TimeManager.Instance.OnFastForwardEnd -= OnFastForwardEnd;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ public class Player : MonoBehaviour
|
|||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
TimeManager.OnMinuteChanged += UpdateStatsByClock;
|
TimeManager.Instance.OnMinuteChanged += UpdateStatsByClock;
|
||||||
_animator.applyRootMotion = true;
|
_animator.applyRootMotion = true;
|
||||||
_navAgent.updatePosition = false;
|
_navAgent.updatePosition = false;
|
||||||
Stats = PlayerStats.CreateInitialStats();
|
Stats = PlayerStats.CreateInitialStats();
|
||||||
@@ -55,7 +55,7 @@ public class Player : MonoBehaviour
|
|||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
TimeManager.OnMinuteChanged -= UpdateStatsByClock;
|
TimeManager.Instance.OnMinuteChanged -= UpdateStatsByClock;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
|
|||||||
@@ -1,14 +1,15 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class TimeManager : MonoBehaviour
|
public class TimeManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public static TimeManager Instance { get; private set; }
|
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]
|
[SerializeField]
|
||||||
private float _startHour;
|
private float _startHour;
|
||||||
@@ -32,8 +33,10 @@ public class TimeManager : MonoBehaviour
|
|||||||
private static TimeSpan _currentTime;
|
private static TimeSpan _currentTime;
|
||||||
public static TimeSpan CurrentTime => _currentTime;
|
public static TimeSpan CurrentTime => _currentTime;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private TimeSpan _timeToStop;
|
private TimeSpan _timeToStop;
|
||||||
private Action _callBackOnFastForward;
|
|
||||||
private bool _isPause = false;
|
private bool _isPause = false;
|
||||||
|
|
||||||
private void Awake()
|
private void Awake()
|
||||||
@@ -81,18 +84,17 @@ public class TimeManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
_minuteToRealTime = MINUTE_TIME;
|
_minuteToRealTime = MINUTE_TIME;
|
||||||
_timeToStop = TimeSpan.MaxValue;
|
_timeToStop = TimeSpan.MaxValue;
|
||||||
_callBackOnFastForward?.Invoke();
|
OnFastForwardEnd?.Invoke();
|
||||||
}
|
}
|
||||||
_timer = _minuteToRealTime;
|
_timer = _minuteToRealTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FastForward(TimeSpan timeToStop,Action callBack)
|
public void FastForward(TimeSpan timeToStop)
|
||||||
{
|
{
|
||||||
_isPause = false;
|
_isPause = false;
|
||||||
_timeToStop = _currentTime.Add(timeToStop);
|
_timeToStop = _currentTime.Add(timeToStop);
|
||||||
_minuteToRealTime = 0.03f;
|
_minuteToRealTime = FF_TIME;
|
||||||
_callBackOnFastForward= callBack;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RotateSun()
|
private void RotateSun()
|
||||||
|
|||||||
+18
-23
@@ -3,7 +3,7 @@ using TMPro;
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class SliderUI : MonoBehaviour
|
public class TimeSliderUI : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private TextMeshProUGUI _title;
|
private TextMeshProUGUI _title;
|
||||||
@@ -16,27 +16,12 @@ public class SliderUI : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Slider _slider;
|
private Slider _slider;
|
||||||
|
|
||||||
public static SliderUI Instance { get; private set; }
|
public void ShowTimeSliderDialog(string title, string description, Action onCancel, Action<TimeSpan> onConfirm)
|
||||||
|
|
||||||
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)
|
|
||||||
{
|
{
|
||||||
|
TimeManager.Instance.OnFastForwardEnd += CloseDialog;
|
||||||
|
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||||
TimeManager.Instance.Pause();
|
TimeManager.Instance.Pause();
|
||||||
TimeSpan retTime=TimeSpan.Zero;
|
UIManager.Instance.Freeze();
|
||||||
|
|
||||||
gameObject.SetActive(true);
|
gameObject.SetActive(true);
|
||||||
_title.text = title;
|
_title.text = title;
|
||||||
@@ -45,6 +30,7 @@ public class SliderUI : MonoBehaviour
|
|||||||
{
|
{
|
||||||
onCancel?.Invoke();
|
onCancel?.Invoke();
|
||||||
Hide();
|
Hide();
|
||||||
|
CloseDialog();
|
||||||
});
|
});
|
||||||
_btnOk.onClick.AddListener(() =>
|
_btnOk.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
@@ -52,20 +38,29 @@ public class SliderUI : MonoBehaviour
|
|||||||
Hide();
|
Hide();
|
||||||
});
|
});
|
||||||
|
|
||||||
return retTime;
|
}
|
||||||
|
|
||||||
|
private void UpdateTime()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CloseDialog()
|
||||||
|
{
|
||||||
|
UIManager.Instance.Unfreeze();
|
||||||
|
Destroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Update()
|
private void Update()
|
||||||
{
|
{
|
||||||
var time = TimeSpan.FromSeconds(_slider.value);
|
var time = TimeSpan.FromSeconds(_slider.value);
|
||||||
|
|
||||||
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
_description.text = $"{time.Hours} hours {time.Minutes} minutes";
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Hide()
|
private void Hide()
|
||||||
{
|
{
|
||||||
TimeManager.Instance.Resume();
|
|
||||||
gameObject.SetActive(false);
|
gameObject.SetActive(false);
|
||||||
|
TimeManager.Instance.Resume();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,49 @@
|
|||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class GameUIManager : MonoBehaviour
|
public class TopBarUI : MonoBehaviour
|
||||||
{
|
{
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private TextMeshProUGUI _timeText;
|
private TextMeshProUGUI _timeText;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
private TextMeshProUGUI _moneyText;
|
private TextMeshProUGUI _moneyText;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public Slider _energy;
|
public Slider _energy;
|
||||||
|
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public Slider _food;
|
public Slider _food;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
|
||||||
private void OnEnable()
|
// Start is called before the first frame update
|
||||||
{
|
private void Start()
|
||||||
TimeManager.OnMinuteChanged += UpdateTime;
|
{
|
||||||
}
|
TimeManager.Instance.OnMinuteChanged += UpdateTime;
|
||||||
|
}
|
||||||
private void OnDisable()
|
|
||||||
{
|
private void OnDisable()
|
||||||
TimeManager.OnMinuteChanged -= UpdateTime;
|
{
|
||||||
}
|
TimeManager.Instance.OnMinuteChanged -= UpdateTime;
|
||||||
|
}
|
||||||
// Update is called once per frame
|
|
||||||
void Update()
|
// Update is called once per frame
|
||||||
{
|
void Update()
|
||||||
_moneyText.text = $"${Player.Instance.Stats[StatsId.Money].Value}";
|
{
|
||||||
|
_moneyText.text = $"${Player.Instance.Stats[StatsId.Money].Value}";
|
||||||
|
|
||||||
}
|
|
||||||
|
}
|
||||||
private void UpdateTime()
|
|
||||||
{
|
private void UpdateTime()
|
||||||
if (_timeText != null)
|
{
|
||||||
{
|
if (_timeText != null)
|
||||||
_timeText.text = TimeManager.CurrentTime.ToString(@"hh\:mm");
|
{
|
||||||
}
|
_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;
|
_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