46 lines
1.3 KiB
C#
46 lines
1.3 KiB
C#
using UnityEngine;
|
|
|
|
public class Shelf : MonoBehaviour, IInventoryHolder, IDataPersistence<ShelfData>
|
|
{
|
|
private Inventory inventory = new Inventory(50);
|
|
|
|
public Inventory Inventory => inventory;
|
|
|
|
public string Name => type;
|
|
|
|
public string type = "shelf";
|
|
|
|
void Awake()
|
|
{
|
|
// Add("Лимонад", 5);
|
|
// Add("Тортик", 22);
|
|
// Add("Спичка", 100);
|
|
}
|
|
|
|
// private void Add(string key, int value)
|
|
// {
|
|
// int added = inventory.inventory.Add(key, value, true);
|
|
// Debug.Log($"{key}: добавлено {added} из {value}");
|
|
// if (added < value) {
|
|
// int dropped = DropToInventory.inventory.Add(key, value - added);
|
|
// Debug.Log($"{key}: брошено {dropped} из {value - added}");
|
|
// }
|
|
// }
|
|
|
|
|
|
public void LoadData(ShelfData data)
|
|
{
|
|
type = data.type;
|
|
transform.position = new Vector3(data.location.x, data.location.y, 0);
|
|
transform.rotation = Quaternion.Euler(0, 0, data.angle);
|
|
inventory.LoadData(data.inventory);
|
|
}
|
|
|
|
public void SaveData(ShelfData data)
|
|
{
|
|
data.type = type;
|
|
data.location = new Vector2(transform.position.x, transform.position.y);
|
|
data.angle = transform.rotation.z;
|
|
inventory.SaveData(data.inventory);
|
|
}
|
|
} |