start dealing with corutines
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using System.Collections;
|
||||||
|
|
||||||
public class Bed : BaseInteractableObject
|
public class Bed : BaseInteractableObject
|
||||||
{
|
{
|
||||||
@@ -8,9 +8,17 @@ public class Bed : BaseInteractableObject
|
|||||||
public override void Interact(Player player)
|
public override void Interact(Player player)
|
||||||
{
|
{
|
||||||
_player=player;
|
_player=player;
|
||||||
Debug.Log("Sitting");
|
StartCoroutine(Sleep());
|
||||||
player.SetPlayerAnimation(AnimationStates.Sitting);
|
}
|
||||||
|
|
||||||
|
private IEnumerator Sleep()
|
||||||
|
{
|
||||||
|
_player.SetPlayerAnimation(AnimationStates.Sitting);
|
||||||
|
yield return StartCoroutine(_player.IsAnimationStatePlaying(0));
|
||||||
|
print("sitting animation finished");
|
||||||
TimeManager.Instance.FastForward(TimeSpan.FromHours(8), OnFastForwardEnd);
|
TimeManager.Instance.FastForward(TimeSpan.FromHours(8), OnFastForwardEnd);
|
||||||
|
|
||||||
|
yield break;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnFastForwardEnd()
|
private void OnFastForwardEnd()
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using Assets.Scripts.Actions.Interfaces;
|
using Assets.Scripts.Actions.Interfaces;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
@@ -63,7 +64,7 @@ public class Player : MonoBehaviour
|
|||||||
{
|
{
|
||||||
if (IsBlockingAnimation(_currentAnimation))
|
if (IsBlockingAnimation(_currentAnimation))
|
||||||
{
|
{
|
||||||
if (IsAnimationStatePlaying(0, GetEnumMemberValue(_currentAnimation)))
|
StartCoroutine(IsAnimationStatePlaying(0));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -116,8 +117,6 @@ public class Player : MonoBehaviour
|
|||||||
_navAgent.isStopped = false;
|
_navAgent.isStopped = false;
|
||||||
SetPlayerAnimation(AnimationStates.Walking);
|
SetPlayerAnimation(AnimationStates.Walking);
|
||||||
|
|
||||||
//transform.position = Vector3.MoveTowards(_navAgent.transform.position, _navAgent.pathEndPosition, _navAgent.speed * Time.deltaTime);
|
|
||||||
// transform.position = _animator.(_navAgent.pathEndPosition);
|
|
||||||
_animator.SetFloat(WALK_VELOCITY, _navAgent.velocity.magnitude);
|
_animator.SetFloat(WALK_VELOCITY, _navAgent.velocity.magnitude);
|
||||||
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||||
}
|
}
|
||||||
@@ -175,13 +174,13 @@ public class Player : MonoBehaviour
|
|||||||
_currentAnimation = newState;
|
_currentAnimation = newState;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsAnimationStatePlaying(int animLayer, string stateName)
|
|
||||||
|
public IEnumerator IsAnimationStatePlaying(int animLayer)
|
||||||
{
|
{
|
||||||
if (_animator.GetCurrentAnimatorStateInfo(animLayer).IsName(stateName) &&
|
string stateName = GetEnumMemberValue(_currentAnimation);
|
||||||
_animator.GetCurrentAnimatorStateInfo(animLayer).normalizedTime < 1.0f)
|
var stateInfo = _animator.GetCurrentAnimatorStateInfo(animLayer);
|
||||||
return true;
|
yield return new WaitWhile(() => stateInfo.IsName(stateName) && stateInfo.normalizedTime < 1.0f);
|
||||||
else
|
yield break;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddTask(PlayerTasks task)
|
public void AddTask(PlayerTasks task)
|
||||||
|
|||||||
@@ -54,6 +54,7 @@ public class TimeManager : MonoBehaviour
|
|||||||
// _sunInitialIntensity = _sunLight.intensity;
|
// _sunInitialIntensity = _sunLight.intensity;
|
||||||
_timer = _minuteToRealTime;
|
_timer = _minuteToRealTime;
|
||||||
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
_currentTime = TimeSpan.Zero + TimeSpan.FromHours(_startHour);
|
||||||
|
_timeToStop = _currentTime;
|
||||||
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
_sunriseTime = TimeSpan.FromHours(_sunriseHour);
|
||||||
_sunsetTime = TimeSpan.FromHours(_sunsetHour);
|
_sunsetTime = TimeSpan.FromHours(_sunsetHour);
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@ public class TimeManager : MonoBehaviour
|
|||||||
{
|
{
|
||||||
_minuteToRealTime = MINUTE_TIME;
|
_minuteToRealTime = MINUTE_TIME;
|
||||||
_timeToStop = TimeSpan.MaxValue;
|
_timeToStop = TimeSpan.MaxValue;
|
||||||
_callBackOnFastForward.Invoke();
|
_callBackOnFastForward?.Invoke();
|
||||||
}
|
}
|
||||||
_timer = _minuteToRealTime;
|
_timer = _minuteToRealTime;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user