refactor interact system
interact only after PopupItemMenu button clicked
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using UnityEngine;
|
||||
using static UnityEditor.Experimental.GraphView.GraphView;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseInteractableObject : MonoBehaviour
|
||||
{
|
||||
@@ -7,15 +8,39 @@ public class BaseInteractableObject : MonoBehaviour
|
||||
public Transform _interactionPoint;
|
||||
[SerializeField]
|
||||
public PopupItemMenu _radialMenuPrefab;
|
||||
|
||||
protected Player _player;
|
||||
public virtual void Interact(Player player)
|
||||
private InteractionStatus _currentStatus=InteractionStatus.Complete;
|
||||
|
||||
public InteractionStatus Interact(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.Collections;
|
||||
|
||||
public class Bed : BaseInteractableObject
|
||||
{
|
||||
|
||||
public override void Interact(Player player)
|
||||
protected override void InteractAction()
|
||||
{
|
||||
base.Interact(player);
|
||||
_player.SetPlayerAnimation(AnimationStates.Sitting, OnAnimationFinished);
|
||||
}
|
||||
|
||||
private void OnAnimationFinished()
|
||||
{
|
||||
UIManager.Instance.ShowTimeSliderDialog("Go to sleep", "Sleep until", OnCancel, OnConfirm);
|
||||
|
||||
@@ -11,16 +11,15 @@ public class CashierDesk : BaseInteractableObject
|
||||
private List<JobInfoSO> _jobsInfoList;
|
||||
private JobInfoSO _playerJob;
|
||||
|
||||
public override void Interact(Player player)
|
||||
protected override void InteractAction()
|
||||
{
|
||||
base.Interact(player);
|
||||
if (player.IsHoldContainerItem())
|
||||
if (_player.IsHoldContainerItem())
|
||||
{
|
||||
BuyItems();
|
||||
}
|
||||
else
|
||||
{
|
||||
_playerJob = _jobsInfoList.Where(x => x.JobPosition == player.JobPosition).FirstOrDefault();
|
||||
_playerJob = _jobsInfoList.Where(x => x.JobPosition == _player.JobPosition).FirstOrDefault();
|
||||
print($"playerJob is {_playerJob}");
|
||||
if (_playerJob != null)
|
||||
{
|
||||
@@ -31,7 +30,7 @@ public class CashierDesk : BaseInteractableObject
|
||||
{
|
||||
print("You don't work here");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BuyItems()
|
||||
|
||||
@@ -14,11 +14,11 @@ public class Door : BaseInteractableObject
|
||||
print($"Player came from to {_scene}");
|
||||
Player.Instance.SetPosition(_interactionPoint.position);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
base.Interact(player);
|
||||
protected override void InteractAction()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_exitName))
|
||||
{
|
||||
PlayerPrefs.SetString("lastExitName", _exitName.ToLower());
|
||||
|
||||
@@ -12,12 +12,11 @@ public class Fridge : BaseInteractableObject
|
||||
|
||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
base.Interact(player);
|
||||
if (player.IsHoldContainerItem())
|
||||
protected override void InteractAction()
|
||||
{
|
||||
if (_player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
var playerContainer = _player.GetContainerItem();
|
||||
if (!playerContainer.IsSalebleItems())
|
||||
{
|
||||
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
||||
@@ -27,7 +26,7 @@ public class Fridge : BaseInteractableObject
|
||||
_foodObjects.Add(item);
|
||||
}
|
||||
|
||||
player.ClearContainerItem();
|
||||
_player.ClearContainerItem();
|
||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
}
|
||||
else
|
||||
@@ -39,7 +38,7 @@ public class Fridge : BaseInteractableObject
|
||||
//Eat menu
|
||||
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);
|
||||
StartCoroutine(EatRoutine(eatingItems));
|
||||
_foodObjects.RemoveRange(0, (int)eatingItems);
|
||||
|
||||
@@ -7,9 +7,8 @@ public class OfficeTable : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private JobsListSO _jobPositionsSO;
|
||||
|
||||
public override void Interact(Player player)
|
||||
protected override void InteractAction()
|
||||
{
|
||||
base.Interact(player);
|
||||
UIManager.Instance.ShowJobSelectionDialog("Job agency", null, OnConfirm);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,10 +7,9 @@ public class ShopingContainer : BaseInteractableObject
|
||||
[SerializeField]
|
||||
//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 containerItem = transform.GetComponent<ContainerItem>();
|
||||
@@ -19,9 +18,7 @@ public class ShopingContainer : BaseInteractableObject
|
||||
Debug.LogError("Container Item is null");
|
||||
return;
|
||||
}
|
||||
player.SetContainerItem(containerItem);
|
||||
_player.SetContainerItem(containerItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -6,16 +6,14 @@ public class StoreContainer : BaseInteractableObject
|
||||
[SerializeField]
|
||||
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 container = player.GetContainerItem();
|
||||
var container = _player.GetContainerItem();
|
||||
container.AddItem(clone);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user