Player can hold shopping basket
This commit is contained in:
@@ -1,12 +0,0 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FoodObject : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private FoodObjectSO _foodObjectSO;
|
||||
|
||||
public FoodObjectSO GetFoodObjectSO()
|
||||
{
|
||||
return _foodObjectSO;
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,14 @@ public class ColaFreezer : BaseInteractableObject
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (!player.HasFoodObject())
|
||||
{
|
||||
//player.BuyObject(_sellableItemSO);
|
||||
// Spawn new object and set to player
|
||||
var transform = Instantiate(_sellableItemSO.prefab, _playerArrivePoint);
|
||||
var foodObject = transform.GetComponent<FoodObject>();
|
||||
player.SetFoodObject(foodObject);
|
||||
}
|
||||
//if (!player.IsHoldContainer())
|
||||
//{
|
||||
// //player.BuyObject(_sellableItemSO);
|
||||
// // Spawn new object and set to player
|
||||
// var transform = Instantiate(_sellableItemSO.prefab, _playerArrivePoint);
|
||||
// var foodObject = transform.GetComponent<FoodItem>();
|
||||
// player.SetFoodObject(foodObject);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,36 +9,36 @@ public class Fridge : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private ItemActionsUI _actionsMenu;
|
||||
|
||||
private List<FoodObject> _foodObjects = new List<FoodObject>();
|
||||
private List<FoodItem> _foodObjects = new List<FoodItem>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
|
||||
_actionsMenu.Show(_containerSO.Name, $"Max items:{_containerSO.MaxCapacity} current items: {_containerSO.CurrentItemsCount}");
|
||||
if (player.HasFoodObject())
|
||||
{
|
||||
if (_foodObjects.Count < _containerSO.MaxCapacity)
|
||||
{
|
||||
_foodObjects.Add(player.GetFoodObject());
|
||||
player.ClearFoodObject();
|
||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
}
|
||||
else
|
||||
Debug.Log($"Fridge is full");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Eat menu
|
||||
if (_foodObjects.Count > 0)
|
||||
{
|
||||
while (player.Stats[StatsId.Food].Value < player.Stats[StatsId.Food].MaxValue && _foodObjects.Count > 0)
|
||||
{
|
||||
_foodObjects.RemoveAt(0);
|
||||
player.Eat();
|
||||
}
|
||||
}
|
||||
}
|
||||
_containerSO.CurrentItemsCount = _foodObjects.Count;
|
||||
//if (player.IsHoldContainer())
|
||||
//{
|
||||
// if (_foodObjects.Count < _containerSO.MaxCapacity)
|
||||
// {
|
||||
// _foodObjects.Add(player.GetFoodObject());
|
||||
// player.ClearFoodObject();
|
||||
// Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
// }
|
||||
// else
|
||||
// Debug.Log($"Fridge is full");
|
||||
//}
|
||||
//else
|
||||
//{
|
||||
// //Eat menu
|
||||
// if (_foodObjects.Count > 0)
|
||||
// {
|
||||
// while (player.Stats[StatsId.Food].Value < player.Stats[StatsId.Food].MaxValue && _foodObjects.Count > 0)
|
||||
// {
|
||||
// _foodObjects.RemoveAt(0);
|
||||
// player.Eat();
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
//_containerSO.CurrentItemsCount = _foodObjects.Count;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bc223213aaee4f748bbcd9342e1d3aae
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ContainerItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
public ContainerSO GetContainerObjectSO()
|
||||
{
|
||||
return _containerSO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8e6fa409eb749c54cab3871962e90678
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class FoodItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SellableItemSO _foodObjectSO;
|
||||
|
||||
public SellableItemSO GetFoodObjectSO()
|
||||
{
|
||||
return _foodObjectSO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class SellableItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
private SellableItemSO _foodObjectSO;
|
||||
|
||||
public SellableItemSO GetFoodObjectSO()
|
||||
{
|
||||
return _foodObjectSO;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 329673eaf27345041afad67ebb166565
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,26 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class ShopingContainer : BaseInteractableObject
|
||||
{
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
[SerializeField]
|
||||
private ItemActionsUI _actionsMenu;
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (!player.IsHoldContainerItem())
|
||||
{
|
||||
var transform = Instantiate(_containerSO.prefab, _playerArrivePoint);
|
||||
var containerItem = transform.GetComponent<ContainerItem>();
|
||||
if (containerItem == null)
|
||||
{
|
||||
Debug.LogError("Container Item is null");
|
||||
return;
|
||||
}
|
||||
player.SetContainerItem(containerItem);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47d747d0dea3a1144ac061eabd85e7b8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,7 +7,7 @@ using System.Runtime.Serialization;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
public class BlockingAnimation : Attribute{}
|
||||
public class BlockingAnimation : Attribute { }
|
||||
|
||||
public class Player : MonoBehaviour
|
||||
{
|
||||
@@ -32,7 +32,7 @@ public class Player : MonoBehaviour
|
||||
|
||||
private const string WALK_VELOCITY = "WalkVelocity";
|
||||
|
||||
private FoodObject _foodObject;
|
||||
private ContainerItem _containerItem;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -116,7 +116,10 @@ public class Player : MonoBehaviour
|
||||
|
||||
private bool IsPathComplete(Vector3 destination)
|
||||
{
|
||||
if (Vector3.Distance(destination, _navAgent.transform.position) <= _navAgent.radius)
|
||||
var dest = new Vector3(destination.x, 0, destination.z);
|
||||
var pos = new Vector3(_navAgent.transform.position.x, 0, _navAgent.transform.position.z);
|
||||
|
||||
if (Vector3.Distance(dest, pos) <= _navAgent.radius)
|
||||
{
|
||||
transform.position = destination;
|
||||
if (!_navAgent.hasPath || _navAgent.velocity.sqrMagnitude < 0.2f)
|
||||
@@ -227,26 +230,26 @@ public class Player : MonoBehaviour
|
||||
return attr != null;
|
||||
}
|
||||
|
||||
public void SetFoodObject(FoodObject foodObject)
|
||||
public void SetContainerItem(ContainerItem containerItem)
|
||||
{
|
||||
foodObject.transform.parent = _holdPoint;
|
||||
foodObject.transform.localPosition = Vector3.zero;
|
||||
_foodObject = foodObject;
|
||||
Debug.Log($"player hold {foodObject.GetFoodObjectSO().name}");
|
||||
containerItem.transform.parent = _holdPoint;
|
||||
containerItem.transform.localPosition = Vector3.zero;
|
||||
_containerItem = containerItem;
|
||||
|
||||
|
||||
}
|
||||
public FoodObject GetFoodObject()
|
||||
public ContainerItem GetContainerItem()
|
||||
{
|
||||
return _foodObject;
|
||||
return _containerItem;
|
||||
}
|
||||
public void ClearFoodObject()
|
||||
public void ClearContainerItem()
|
||||
{
|
||||
Destroy(_foodObject.gameObject);
|
||||
_foodObject = null;
|
||||
Destroy(_containerItem.gameObject);
|
||||
_containerItem = null;
|
||||
}
|
||||
|
||||
public bool HasFoodObject()
|
||||
public bool IsHoldContainerItem()
|
||||
{
|
||||
return _foodObject != null;
|
||||
return _containerItem != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,4 +6,5 @@ public class ContainerSO : ScriptableObject
|
||||
public string Name;
|
||||
public int MaxCapacity;
|
||||
public int CurrentItemsCount;
|
||||
public Transform prefab;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: 570c5458f6b5110448188e51cb5becbb, type: 3}
|
||||
m_Name: ShopingBasket
|
||||
m_EditorClassIdentifier:
|
||||
Name: Shoping basket
|
||||
MaxCapacity: 5
|
||||
CurrentItemsCount: 0
|
||||
prefab: {fileID: 4771105611132447618, guid: cbfa04a0e789cc44a908f6953ea6e6a9, type: 3}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d901709f604b5a14db9f4c906051b367
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user