create base item SO for container. still need to set container type for different item types (sellable or not)
This commit is contained in:
@@ -4273,7 +4273,7 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 963194225}
|
||||
m_LocalRotation: {x: 0.54491353, y: -0.00000002885484, z: 0.000000018751987, w: 0.8384923}
|
||||
m_LocalRotation: {x: 0.54491353, y: 0.00000002885483, z: -0.00000001875198, w: 0.8384923}
|
||||
m_LocalPosition: {x: 0.49909282, y: 3.5104675, z: -2.911191}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
@@ -12835,7 +12835,7 @@ Transform:
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 2110938951}
|
||||
m_LocalRotation: {x: 0.54491353, y: -0.00000002885484, z: 0.000000018751987, w: 0.8384923}
|
||||
m_LocalRotation: {x: 0.54491353, y: 0.00000002885483, z: -0.00000001875198, w: 0.8384923}
|
||||
m_LocalPosition: {x: 0.49909282, y: 3.5104675, z: -2.911191}
|
||||
m_LocalScale: {x: 1, y: 1, z: 1}
|
||||
m_ConstrainProportionsScale: 0
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class CashierDesk : BaseInteractableObject
|
||||
@@ -6,17 +5,18 @@ public class CashierDesk : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
player.ClearContainerItem();
|
||||
if (playerItemsList.Any())
|
||||
if (playerContainer.IsSalebleItems())
|
||||
{
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
player.ClearContainerItem();
|
||||
float finalPrice = 0;
|
||||
foreach (var item in playerItemsList)
|
||||
foreach (SellableItemSO item in playerItemsList)
|
||||
{
|
||||
finalPrice += item.Price;
|
||||
}
|
||||
@@ -29,7 +29,14 @@ public class CashierDesk : BaseInteractableObject
|
||||
return;
|
||||
}
|
||||
player.Pay(finalPrice);
|
||||
containerItem.AddItems(playerItemsList);
|
||||
foreach (var item in playerContainer.GetItems())
|
||||
{
|
||||
|
||||
var foodItemSO = ScriptableObject.CreateInstance<FoodItemSO>();
|
||||
foodItemSO.ItemName = item.ItemName;
|
||||
foodItemSO.Energy = 0;
|
||||
containerItem.AddItem(foodItemSO);
|
||||
}
|
||||
player.SetContainerItem(containerItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,23 +9,29 @@ public class Fridge : BaseInteractableObject
|
||||
[SerializeField]
|
||||
private ItemActionsUI _actionsMenu;
|
||||
|
||||
private List<FoodItem> _foodObjects = new List<FoodItem>();
|
||||
private List<FoodItemSO> _foodObjects = new List<FoodItemSO>();
|
||||
|
||||
public override void Interact(Player player)
|
||||
{
|
||||
if (player.IsHoldContainerItem())
|
||||
{
|
||||
var playerContainer = player.GetContainerItem();
|
||||
if (!playerContainer.IsSalebleItems())
|
||||
{
|
||||
if (_foodObjects.Count + playerContainer.GetItems().Count <= _containerSO.MaxCapacity)
|
||||
{
|
||||
foreach (FoodItemSO item in playerContainer.GetItems())
|
||||
{
|
||||
_foodObjects.Add(item);
|
||||
}
|
||||
|
||||
//_actionsMenu.Show(_containerSO.Name, $"Max items:{_containerSO.MaxCapacity} current items: {_containerSO.CurrentItemsCount}");
|
||||
//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");
|
||||
//}
|
||||
player.ClearContainerItem();
|
||||
Debug.Log($"Fridge have {_foodObjects.Count} pices of food");
|
||||
}
|
||||
else
|
||||
Debug.Log($"Fridge is full");
|
||||
}
|
||||
}
|
||||
//else
|
||||
//{
|
||||
// //Eat menu
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ContainerItem : MonoBehaviour
|
||||
@@ -7,19 +8,14 @@ public class ContainerItem : MonoBehaviour
|
||||
private ContainerSO _containerSO;
|
||||
|
||||
|
||||
private List<SellableItemSO> _items;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_items = new List<SellableItemSO>();
|
||||
}
|
||||
private List<BaseItemSO> _items = new List<BaseItemSO>();
|
||||
|
||||
public ContainerSO GetContainerObjectSO()
|
||||
{
|
||||
return _containerSO;
|
||||
}
|
||||
|
||||
public void AddItem(SellableItemSO item)
|
||||
public void AddItem(BaseItemSO item)
|
||||
{
|
||||
if (_items.Count < _containerSO.MaxCapacity)
|
||||
{
|
||||
@@ -32,8 +28,22 @@ public class ContainerItem : MonoBehaviour
|
||||
}
|
||||
}
|
||||
|
||||
public List<SellableItemSO> GetItems()
|
||||
public List<BaseItemSO> GetItems()
|
||||
{
|
||||
return _items;
|
||||
}
|
||||
|
||||
public bool IsSalebleItems()
|
||||
{
|
||||
return _items.Any(x => x is SellableItemSO);
|
||||
}
|
||||
|
||||
public void AddItems(List<BaseItemSO> playerItemsList)
|
||||
{
|
||||
foreach (var item in playerItemsList)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
public class FoodItem
|
||||
public class FoodItemSO : BaseItemSO
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int Energy { get; set; }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
using UnityEngine;
|
||||
|
||||
public class BaseItemSO : ScriptableObject
|
||||
{
|
||||
public string ItemName;
|
||||
public Sprite Icon;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 76f6b12a84fd9e142b92cb523db68c4c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,10 +1,8 @@
|
||||
using UnityEngine;
|
||||
|
||||
[CreateAssetMenu()]
|
||||
public class SellableItemSO : ScriptableObject
|
||||
public class SellableItemSO : BaseItemSO
|
||||
{
|
||||
public Transform Prefab;
|
||||
public string ItemName;
|
||||
public float Price;
|
||||
public Sprite Icon;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
public class ContainerItemsUI : MonoBehaviour
|
||||
@@ -23,26 +22,37 @@ public class ContainerItemsUI : MonoBehaviour
|
||||
var playerContainer = Player.Instance.GetContainerItem();
|
||||
_container.gameObject.SetActive(true);
|
||||
|
||||
if (playerContainer.GetItems().Any())
|
||||
if (playerContainer.IsSalebleItems())
|
||||
{
|
||||
foreach (Transform child in _itemsList)
|
||||
{
|
||||
if (child == _itemUITemplate) continue;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
ClearObject();
|
||||
|
||||
var playerItemsList = playerContainer.GetItems();
|
||||
for (int count = 0; count < playerItemsList.Count; count++)
|
||||
{
|
||||
var itemUI = Instantiate(_itemUITemplate, _itemsList);
|
||||
itemUI.gameObject.SetActive(true);
|
||||
itemUI.GetComponent<ItemDescriptionUI>().SetItem(playerItemsList[count]);
|
||||
itemUI.GetComponent<ItemDescriptionUI>().SetItem((SellableItemSO)playerItemsList[count]);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearObject();
|
||||
_container.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ClearObject();
|
||||
_container.gameObject.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearObject()
|
||||
{
|
||||
foreach (Transform child in _itemsList)
|
||||
{
|
||||
if (child == _itemUITemplate) continue;
|
||||
Destroy(child.gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user