time to bed
This commit is contained in:
@@ -2,8 +2,17 @@ using UnityEngine;
|
||||
|
||||
public class DontDestroy : MonoBehaviour
|
||||
{
|
||||
public static DontDestroy Instance { get; private set; }
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
DontDestroyOnLoad(gameObject);
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
public class Bed : BaseInteractableObject
|
||||
{
|
||||
private Player _player;
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
_player=player;
|
||||
Debug.Log("Sitting");
|
||||
player.SetPlayerAnimation(AnimationStates.Sitting);
|
||||
TimeManager.Instance.FastForward(TimeSpan.FromHours(8), OnFastForwardEnd);
|
||||
}
|
||||
|
||||
private void OnFastForwardEnd()
|
||||
{
|
||||
_player.SetPlayerAnimation(AnimationStates.Standing);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ public class MouseInputManager : MonoBehaviour
|
||||
private WaypointVisual _waypointVisual;
|
||||
|
||||
|
||||
public event EventHandler<OnSelectedObjectChangedEventArgs> OnSelectedObjectChanged;
|
||||
public static event EventHandler<OnSelectedObjectChangedEventArgs> OnSelectedObjectChanged;
|
||||
|
||||
public static MouseInputManager Instance { get; private set; }
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ public class SelectedVisual : MonoBehaviour
|
||||
|
||||
private void Start()
|
||||
{
|
||||
MouseInputManager.Instance.OnSelectedObjectChanged += Mouse_OnSelectedObjectChanged;
|
||||
MouseInputManager.OnSelectedObjectChanged += Mouse_OnSelectedObjectChanged;
|
||||
print($"{_selectedObject.name} is subscribed to OnSelectedObjectChanged");
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
MouseInputManager.Instance.OnSelectedObjectChanged -= Mouse_OnSelectedObjectChanged;
|
||||
MouseInputManager.OnSelectedObjectChanged -= Mouse_OnSelectedObjectChanged;
|
||||
print($"{_selectedObject.name} is Unsubscribed to OnSelectedObjectChanged");
|
||||
}
|
||||
|
||||
private void Mouse_OnSelectedObjectChanged(object sender, OnSelectedObjectChangedEventArgs e)
|
||||
|
||||
@@ -1,8 +1,13 @@
|
||||
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;
|
||||
|
||||
public static Action OnMinuteChanged;
|
||||
|
||||
[SerializeField]
|
||||
@@ -22,16 +27,31 @@ public class TimeManager : MonoBehaviour
|
||||
private float _timer;
|
||||
private float _sunInitialIntensity;
|
||||
|
||||
[SerializeField]
|
||||
private float _minuteToRealTime = 0.05f;
|
||||
private float _minuteToRealTime;
|
||||
|
||||
private static TimeSpan _currentTime;
|
||||
public static TimeSpan CurrentTime => _currentTime;
|
||||
|
||||
private TimeSpan _timeToStop;
|
||||
private Action _callBackOnFastForward;
|
||||
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
if (Instance == null)
|
||||
{
|
||||
Instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
else
|
||||
Destroy(gameObject);
|
||||
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// _sunInitialIntensity = _sunLight.intensity;
|
||||
// _sunInitialIntensity = _sunLight.intensity;
|
||||
_timer = _minuteToRealTime;
|
||||
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
||||
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
||||
@@ -53,10 +73,23 @@ public class TimeManager : MonoBehaviour
|
||||
_currentTime = _currentTime.Add(TimeSpan.FromMinutes(1));
|
||||
OnMinuteChanged?.Invoke();
|
||||
|
||||
if (_currentTime.TotalMinutes >= _timeToStop.TotalMinutes)
|
||||
{
|
||||
_minuteToRealTime = MINUTE_TIME;
|
||||
_timeToStop = TimeSpan.MaxValue;
|
||||
_callBackOnFastForward.Invoke();
|
||||
}
|
||||
_timer = _minuteToRealTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void FastForward(TimeSpan timeToStop,Action callBack)
|
||||
{
|
||||
_timeToStop = _currentTime.Add(timeToStop);
|
||||
_minuteToRealTime = 0.03f;
|
||||
_callBackOnFastForward= callBack;
|
||||
}
|
||||
|
||||
private void RotateSun()
|
||||
{
|
||||
float intensityMultiplier = 1;
|
||||
@@ -73,7 +106,7 @@ public class TimeManager : MonoBehaviour
|
||||
{
|
||||
intensityMultiplier = 0;
|
||||
}
|
||||
// _sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
|
||||
// _sunLight.intensity = _sunInitialIntensity * intensityMultiplier;
|
||||
}
|
||||
|
||||
private TimeSpan CalculateTimeDifference(TimeSpan from, TimeSpan to)
|
||||
|
||||
Reference in New Issue
Block a user