Added sitting animation
This commit is contained in:
@@ -5,7 +5,9 @@ public class Bed : BaseInteractableObject
|
||||
{
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
Debug.Log("Interact with bed");
|
||||
Debug.Log("rotate player");
|
||||
player.Rotate(_playerArrivePoint.transform.forward);
|
||||
Debug.Log("Sitting");
|
||||
player.SetPlayerState(ActionStates.Sitting);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ public class MouseInputManager : MonoBehaviour
|
||||
private LayerMask _walkableLayerMask;
|
||||
[SerializeField]
|
||||
private Camera _camera;
|
||||
[SerializeField]
|
||||
private WaypointVisual _waypointVisual;
|
||||
|
||||
|
||||
public event EventHandler<OnSelectedObjectChangedEventArgs> OnSelectedObjectChanged;
|
||||
@@ -36,7 +38,7 @@ public class MouseInputManager : MonoBehaviour
|
||||
OnSelectedObjectChanged?.Invoke(this, new OnSelectedObjectChangedEventArgs() { SelectedObject = baseObject });
|
||||
if (Input.GetMouseButtonDown(0))
|
||||
{
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Move, baseObject._playerArrivePoint.position));
|
||||
_waypointVisual.SetWaypoint(baseObject._playerArrivePoint.position);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Interact, baseObject));
|
||||
}
|
||||
}
|
||||
@@ -52,7 +54,8 @@ public class MouseInputManager : MonoBehaviour
|
||||
{
|
||||
if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, 100f, _walkableLayerMask))
|
||||
{
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Move, hit.point));
|
||||
_waypointVisual.SetWaypoint(hit.point);
|
||||
Player.Instance.AddTask(new PlayerTasks(Tasks.Move, _waypointVisual));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+22
-15
@@ -1,5 +1,4 @@
|
||||
using Assets.Scripts.Actions.Interfaces;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
@@ -9,9 +8,6 @@ public enum TaskStatus { Waiting, InProgress, Complete };
|
||||
public enum ActionStates { Idle, Walking, Sleeping, Sitting };
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
public event EventHandler<OnPlayerMovesEventArgs> OnPlayerMoves;
|
||||
|
||||
|
||||
public static Player Instance { get; private set; }
|
||||
|
||||
[SerializeField]
|
||||
@@ -37,6 +33,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
|
||||
if (Instance != null)
|
||||
{
|
||||
Debug.Log("There's more than one player instance");
|
||||
@@ -65,15 +62,23 @@ public class Player : MonoBehaviour
|
||||
}
|
||||
if (_currentTask != null)
|
||||
{
|
||||
if (_currentTask.Status == TaskStatus.Waiting)
|
||||
Debug.Log($"Current task {_currentTask.Task}");
|
||||
switch (_currentTask.Task)
|
||||
{
|
||||
case Tasks.Move:
|
||||
OnPlayerMoves?.Invoke(this, new OnPlayerMovesEventArgs() { PointToMove = _currentTask.Position });
|
||||
_navAgent.SetDestination(_currentTask.Position);
|
||||
_navAgent.SetDestination(_currentTask.TagretObject._playerArrivePoint.position);
|
||||
_currentTask.UpdateStatus(MoveToPoint());
|
||||
break;
|
||||
case Tasks.Interact:
|
||||
_currentTask.UpdateStatus(InteractWithObject(_currentTask.Interactable));
|
||||
if (pathComplete(_currentTask.TagretObject._playerArrivePoint.position))
|
||||
_currentTask.UpdateStatus(InteractWithObject(_currentTask.TagretObject));
|
||||
else
|
||||
{
|
||||
AddTask(new PlayerTasks(Tasks.Move, _currentTask.TagretObject));
|
||||
AddTask(_currentTask);
|
||||
_currentTask = null;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -97,12 +102,17 @@ public class Player : MonoBehaviour
|
||||
_animator.SetFloat(WALK_VELOCITY, velocity.y);
|
||||
}
|
||||
|
||||
return pathComplete() ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||
return pathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||
}
|
||||
|
||||
private bool pathComplete()
|
||||
public void Rotate(Vector3 target)
|
||||
{
|
||||
if (Vector3.Distance(_navAgent.destination, _navAgent.transform.position) <= _navAgent.radius)
|
||||
Quaternion rotation = Quaternion.LookRotation(target);
|
||||
transform.rotation = rotation;
|
||||
}
|
||||
private bool pathComplete(Vector3 destination)
|
||||
{
|
||||
if (Vector3.Distance(destination, _navAgent.transform.position) <= _navAgent.radius)
|
||||
{
|
||||
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude == 0f)
|
||||
{
|
||||
@@ -126,19 +136,16 @@ public class Player : MonoBehaviour
|
||||
{
|
||||
case ActionStates.Idle:
|
||||
_animator.SetBool(WALK, false);
|
||||
break;
|
||||
case ActionStates.Walking when _currentState == ActionStates.Sitting:
|
||||
_animator.SetBool(SIT_DOWN, false);
|
||||
_animator.SetBool(SIT_DOWN, true);
|
||||
_animator.SetBool(WALK, true);
|
||||
|
||||
break;
|
||||
case ActionStates.Walking:
|
||||
_animator.SetBool(WALK, true);
|
||||
break;
|
||||
case ActionStates.Sleeping:
|
||||
break;
|
||||
break;
|
||||
case ActionStates.Sitting:
|
||||
_animator.SetBool(SIT_DOWN, true);
|
||||
break;
|
||||
}
|
||||
_currentState = newState;
|
||||
|
||||
@@ -1,25 +1,16 @@
|
||||
|
||||
using UnityEngine;
|
||||
|
||||
public class PlayerTasks
|
||||
public class PlayerTasks
|
||||
{
|
||||
public Tasks Task { get; private set; }
|
||||
public Vector3 Position { get; private set; }
|
||||
public BaseInteractableObject Interactable { get; private set; }
|
||||
public BaseInteractableObject TagretObject { get; private set; }
|
||||
public TaskStatus Status { get; private set; }
|
||||
|
||||
public PlayerTasks(Tasks task, Vector3 position)
|
||||
public PlayerTasks(Tasks task, BaseInteractableObject gameObject)
|
||||
{
|
||||
Task = task;
|
||||
Position = position;
|
||||
Status = TaskStatus.Waiting;
|
||||
}
|
||||
public PlayerTasks(Tasks task, BaseInteractableObject interactable)
|
||||
{
|
||||
Task = task;
|
||||
Interactable = interactable;
|
||||
TagretObject = gameObject;
|
||||
Status = TaskStatus.Waiting;
|
||||
}
|
||||
|
||||
public void UpdateStatus(TaskStatus status)
|
||||
{
|
||||
Status = status;
|
||||
|
||||
@@ -1,25 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class WaypointVisual : MonoBehaviour
|
||||
public class WaypointVisual : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ParticleSystem _particleSystem;
|
||||
[SerializeField]
|
||||
private Transform _wayPoint;
|
||||
|
||||
private void Start()
|
||||
public void SetWaypoint(Vector3 position)
|
||||
{
|
||||
Player.Instance.OnPlayerMoves += Instance_OnPlayerMoves;
|
||||
}
|
||||
|
||||
private void Instance_OnPlayerMoves(object sender, OnPlayerMovesEventArgs e)
|
||||
{
|
||||
_wayPoint.position = e.PointToMove;
|
||||
_wayPoint.position = position;
|
||||
_particleSystem.Play();
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
Player.Instance.OnPlayerMoves -= Instance_OnPlayerMoves;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user