refactor interact system
interact only after PopupItemMenu button clicked
This commit is contained in:
@@ -7,6 +7,7 @@ public enum PlayerStates { Awake, Sleeping, Eating,Working }
|
|||||||
public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, }
|
public enum StatsId { Money, RentAccount, Food, Energy, BankAccount, Job, }
|
||||||
public enum Tasks { Move, Interact, Rotate };
|
public enum Tasks { Move, Interact, Rotate };
|
||||||
public enum TaskStatus { Waiting, InProgress, Complete };
|
public enum TaskStatus { Waiting, InProgress, Complete };
|
||||||
|
public enum InteractionStatus { Complete, WaitForChoose, InProgress, FarFromPlayer };
|
||||||
public enum AnimationStates
|
public enum AnimationStates
|
||||||
{
|
{
|
||||||
[EnumMember(Value = "Idle")]
|
[EnumMember(Value = "Idle")]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using UnityEngine;
|
using System;
|
||||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
using System.Collections;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
public class BaseInteractableObject : MonoBehaviour
|
public class BaseInteractableObject : MonoBehaviour
|
||||||
{
|
{
|
||||||
@@ -7,15 +8,39 @@ public class BaseInteractableObject : MonoBehaviour
|
|||||||
public Transform _interactionPoint;
|
public Transform _interactionPoint;
|
||||||
[SerializeField]
|
[SerializeField]
|
||||||
public PopupItemMenu _radialMenuPrefab;
|
public PopupItemMenu _radialMenuPrefab;
|
||||||
|
|
||||||
protected Player _player;
|
protected Player _player;
|
||||||
public virtual void Interact(Player player)
|
private InteractionStatus _currentStatus=InteractionStatus.Complete;
|
||||||
|
|
||||||
|
public InteractionStatus Interact(Player player)
|
||||||
{
|
{
|
||||||
_player=player;
|
_player=player;
|
||||||
|
if (_currentStatus == InteractionStatus.Complete)
|
||||||
|
{
|
||||||
|
UIManager.Instance.ShowItemsMenu(PopupMenuCallback);
|
||||||
|
_currentStatus = InteractionStatus.WaitForChoose;
|
||||||
|
}
|
||||||
|
else if(_currentStatus!=InteractionStatus.WaitForChoose)
|
||||||
|
{
|
||||||
|
if (_player.IsPathComplete(_interactionPoint.position))
|
||||||
|
{
|
||||||
|
InteractAction();
|
||||||
|
_currentStatus = InteractionStatus.Complete;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_currentStatus = InteractionStatus.FarFromPlayer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return _currentStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SpawnMenu()
|
private void PopupMenuCallback()
|
||||||
{
|
{
|
||||||
UIManager.Instance.ShowItemsMenu();
|
_currentStatus = InteractionStatus.InProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected virtual void InteractAction()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
|
||||||
public class Bed : BaseInteractableObject
|
public class Bed : BaseInteractableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
|
||||||
_player.SetPlayerAnimation(AnimationStates.Sitting, OnAnimationFinished);
|
_player.SetPlayerAnimation(AnimationStates.Sitting, OnAnimationFinished);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnAnimationFinished()
|
private void OnAnimationFinished()
|
||||||
{
|
{
|
||||||
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
|
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
|
||||||
|
|||||||
@@ -11,16 +11,15 @@ public class CashierDesk : BaseInteractableObject
|
|||||||
private List<JobInfoSO> _jobsInfoList;
|
private List<JobInfoSO> _jobsInfoList;
|
||||||
private JobInfoSO _playerJob;
|
private JobInfoSO _playerJob;
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
if (_player.IsHoldContainerItem())
|
||||||
if (player.IsHoldContainerItem())
|
|
||||||
{
|
{
|
||||||
BuyItems();
|
BuyItems();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_playerJob = _jobsInfoList.Where(x => x.JobPosition == player.JobPosition).FirstOrDefault();
|
_playerJob = _jobsInfoList.Where(x => x.JobPosition == _player.JobPosition).FirstOrDefault();
|
||||||
print($"playerJob is {_playerJob}");
|
print($"playerJob is {_playerJob}");
|
||||||
if (_playerJob != null)
|
if (_playerJob != null)
|
||||||
{
|
{
|
||||||
@@ -31,7 +30,7 @@ public class CashierDesk : BaseInteractableObject
|
|||||||
{
|
{
|
||||||
print("You don't work here");
|
print("You don't work here");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void BuyItems()
|
private void BuyItems()
|
||||||
|
|||||||
@@ -14,11 +14,11 @@ public class Door : BaseInteractableObject
|
|||||||
print($"Player came from to {_scene}");
|
print($"Player came from to {_scene}");
|
||||||
Player.Instance.SetPosition(_interactionPoint.position);
|
Player.Instance.SetPosition(_interactionPoint.position);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
|
||||||
if (!string.IsNullOrEmpty(_exitName))
|
if (!string.IsNullOrEmpty(_exitName))
|
||||||
{
|
{
|
||||||
PlayerPrefs.SetString("lastExitName", _exitName.ToLower());
|
PlayerPrefs.SetString("lastExitName", _exitName.ToLower());
|
||||||
|
|||||||
@@ -12,12 +12,11 @@ public class Fridge : BaseInteractableObject
|
|||||||
|
|
||||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
if (_player.IsHoldContainerItem())
|
||||||
if (player.IsHoldContainerItem())
|
|
||||||
{
|
{
|
||||||
var playerContainer = player.GetContainerItem();
|
var playerContainer = _player.GetContainerItem();
|
||||||
if (!playerContainer.IsSalebleItems())
|
if (!playerContainer.IsSalebleItems())
|
||||||
{
|
{
|
||||||
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
||||||
@@ -27,7 +26,7 @@ public class Fridge : BaseInteractableObject
|
|||||||
_foodObjects.Add(item);
|
_foodObjects.Add(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
player.ClearContainerItem();
|
_player.ClearContainerItem();
|
||||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -39,7 +38,7 @@ public class Fridge : BaseInteractableObject
|
|||||||
//Eat menu
|
//Eat menu
|
||||||
if (_foodObjects.Count > 0)
|
if (_foodObjects.Count > 0)
|
||||||
{
|
{
|
||||||
var hunger = player.Stats[StatsId.Food].MaxValue - player.Stats[StatsId.Food].Value;
|
var hunger = _player.Stats[StatsId.Food].MaxValue - _player.Stats[StatsId.Food].Value;
|
||||||
var eatingItems = _foodObjects.Count < (hunger / 10) ? _foodObjects.Count : (hunger / 10);
|
var eatingItems = _foodObjects.Count < (hunger / 10) ? _foodObjects.Count : (hunger / 10);
|
||||||
StartCoroutine(EatRoutine(eatingItems));
|
StartCoroutine(EatRoutine(eatingItems));
|
||||||
_foodObjects.RemoveRange(0, (int)eatingItems);
|
_foodObjects.RemoveRange(0, (int)eatingItems);
|
||||||
|
|||||||
@@ -7,9 +7,8 @@ public class OfficeTable : BaseInteractableObject
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private JobsListSO _jobPositionsSO;
|
private JobsListSO _jobPositionsSO;
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
|
||||||
UIManager.Instance.ShowJobSelectionDialog("Job agency", null, OnConfirm);
|
UIManager.Instance.ShowJobSelectionDialog("Job agency", null, OnConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,10 +7,9 @@ public class ShopingContainer : BaseInteractableObject
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
//private ItemActionsUI _actionsMenu;
|
//private ItemActionsUI _actionsMenu;
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
if (!_player.IsHoldContainerItem())
|
||||||
if (!player.IsHoldContainerItem())
|
|
||||||
{
|
{
|
||||||
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
var transform = Instantiate(_containerSO.prefab, _interactionPoint);
|
||||||
var containerItem = transform.GetComponent<ContainerItem>();
|
var containerItem = transform.GetComponent<ContainerItem>();
|
||||||
@@ -19,9 +18,7 @@ public class ShopingContainer : BaseInteractableObject
|
|||||||
Debug.LogError("Container Item is null");
|
Debug.LogError("Container Item is null");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
player.SetContainerItem(containerItem);
|
_player.SetContainerItem(containerItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,14 @@ public class StoreContainer : BaseInteractableObject
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private SellableItemSO _sellableItemSO;
|
private SellableItemSO _sellableItemSO;
|
||||||
|
|
||||||
public override void Interact(Player player)
|
protected override void InteractAction()
|
||||||
{
|
{
|
||||||
base.Interact(player);
|
if (_player.IsHoldContainerItem())
|
||||||
if (player.IsHoldContainerItem())
|
|
||||||
{
|
{
|
||||||
var clone = Instantiate(_sellableItemSO);
|
var clone = Instantiate(_sellableItemSO);
|
||||||
|
|
||||||
var container = player.GetContainerItem();
|
var container = _player.GetContainerItem();
|
||||||
container.AddItem(clone);
|
container.AddItem(clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ public class Player : MonoBehaviour
|
|||||||
public Dictionary<StatsId, Stat> Stats;
|
public Dictionary<StatsId, Stat> Stats;
|
||||||
public JobPositions JobPosition { get; set; }
|
public JobPositions JobPosition { get; set; }
|
||||||
|
|
||||||
public EducationSkill Education { get; set; }
|
public EducationSkill Education { get; set; }
|
||||||
|
|
||||||
private readonly Queue<PlayerTasks> _tasks = new Queue<PlayerTasks>();
|
private readonly Queue<PlayerTasks> _tasks = new Queue<PlayerTasks>();
|
||||||
private PlayerTasks _currentTask;
|
private PlayerTasks _currentTask;
|
||||||
@@ -56,10 +56,10 @@ public class Player : MonoBehaviour
|
|||||||
TimeManager.Instance.OnMinuteChanged += UpdateStatsByClock;
|
TimeManager.Instance.OnMinuteChanged += UpdateStatsByClock;
|
||||||
_animator.applyRootMotion = true;
|
_animator.applyRootMotion = true;
|
||||||
_navAgent.updatePosition = false;
|
_navAgent.updatePosition = false;
|
||||||
|
|
||||||
_currentActing = PlayerStates.Awake;
|
_currentActing = PlayerStates.Awake;
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
@@ -105,18 +105,21 @@ public class Player : MonoBehaviour
|
|||||||
_currentTask.UpdateStatus(MoveToPoint());
|
_currentTask.UpdateStatus(MoveToPoint());
|
||||||
break;
|
break;
|
||||||
case Tasks.Interact:
|
case Tasks.Interact:
|
||||||
// Show interaction menu
|
var result = _currentTask.TagretObject.Interact(this);
|
||||||
_currentTask.TagretObject.SpawnMenu();
|
switch (result)
|
||||||
_currentTask = null;
|
{
|
||||||
//if (IsPathComplete(_currentTask.TagretObject._interactionPoint.position))
|
case InteractionStatus.FarFromPlayer:
|
||||||
// _currentTask.UpdateStatus(InteractWithObject(_currentTask.TagretObject));
|
AddTask(new PlayerTasks(Tasks.Move, _currentTask.TagretObject));
|
||||||
//else
|
AddTask(new PlayerTasks(Tasks.Rotate, _currentTask.TagretObject));
|
||||||
//{
|
AddTask(_currentTask);
|
||||||
// AddTask(new PlayerTasks(Tasks.Move, _currentTask.TagretObject));
|
_currentTask = null;
|
||||||
// AddTask(new PlayerTasks(Tasks.Rotate, _currentTask.TagretObject));
|
break;
|
||||||
// AddTask(_currentTask);
|
case InteractionStatus.Complete:
|
||||||
// _currentTask = null;
|
_currentTask.UpdateStatus(TaskStatus.Complete);
|
||||||
//}
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +140,7 @@ public class Player : MonoBehaviour
|
|||||||
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
return IsPathComplete(_navAgent.destination) ? TaskStatus.Complete : TaskStatus.InProgress;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsPathComplete(Vector3 destination)
|
public bool IsPathComplete(Vector3 destination)
|
||||||
{
|
{
|
||||||
var dest = new Vector3(destination.x, 0, destination.z);
|
var dest = new Vector3(destination.x, 0, destination.z);
|
||||||
var pos = new Vector3(_navAgent.transform.position.x, 0, _navAgent.transform.position.z);
|
var pos = new Vector3(_navAgent.transform.position.x, 0, _navAgent.transform.position.z);
|
||||||
@@ -174,11 +177,11 @@ public class Player : MonoBehaviour
|
|||||||
return Mathf.Abs(Quaternion.Dot(q1, q2)) >= 1 - precision;
|
return Mathf.Abs(Quaternion.Dot(q1, q2)) >= 1 - precision;
|
||||||
}
|
}
|
||||||
|
|
||||||
private TaskStatus InteractWithObject(BaseInteractableObject interactableObject)
|
//private TaskStatus InteractWithObject(BaseInteractableObject interactableObject)
|
||||||
{
|
//{
|
||||||
interactableObject.Interact(this);
|
// interactableObject.Interact(this);
|
||||||
return TaskStatus.Complete;
|
// return TaskStatus.Complete;
|
||||||
}
|
//}
|
||||||
|
|
||||||
public void SetPlayerAnimation(AnimationStates newState, Action onAnimationFinish)
|
public void SetPlayerAnimation(AnimationStates newState, Action onAnimationFinish)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
@@ -6,10 +8,27 @@ public class PopupItemMenu : MonoBehaviour
|
|||||||
[SerializeField]
|
[SerializeField]
|
||||||
private Button _popupMenuItemButtonPrefab;
|
private Button _popupMenuItemButtonPrefab;
|
||||||
|
|
||||||
public void ShowButtons()
|
public void ShowButtons(Action menuButtonClick)
|
||||||
{
|
{
|
||||||
var button=Instantiate(_popupMenuItemButtonPrefab) as Button;
|
var button=Instantiate(_popupMenuItemButtonPrefab) as Button;
|
||||||
button.transform.SetParent(transform,false);
|
button.transform.SetParent(transform,false);
|
||||||
button.transform.localPosition = new Vector3(0, 100f, 0);
|
button.transform.localPosition = new Vector3(0, 100f, 0);
|
||||||
|
|
||||||
|
button.onClick.AddListener(() =>
|
||||||
|
{
|
||||||
|
menuButtonClick?.Invoke();
|
||||||
|
Hide();
|
||||||
|
CloseDialog();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
private void CloseDialog()
|
||||||
|
{
|
||||||
|
UIManager.Instance.Unfreeze();
|
||||||
|
Destroy(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void Hide()
|
||||||
|
{
|
||||||
|
gameObject.SetActive(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,12 +40,12 @@ public class UIManager : MonoBehaviour
|
|||||||
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
jobSelector.ShowJobSelectionDialog(title, onCancel, onConfirm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowItemsMenu()
|
public void ShowItemsMenu(Action itemsMenuCallback)
|
||||||
{
|
{
|
||||||
var popupMenu = Instantiate(_itemPopupMenuPrefab) as PopupItemMenu;
|
var popupMenu = Instantiate(_itemPopupMenuPrefab) as PopupItemMenu;
|
||||||
popupMenu.transform.transform.SetParent(transform, false);
|
popupMenu.transform.transform.SetParent(transform, false);
|
||||||
popupMenu.transform.position = Input.mousePosition;
|
popupMenu.transform.position = Input.mousePosition;
|
||||||
popupMenu.ShowButtons();
|
popupMenu.ShowButtons(itemsMenuCallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Freeze()
|
public void Freeze()
|
||||||
|
|||||||
Reference in New Issue
Block a user