107 lines
2.5 KiB
C#
107 lines
2.5 KiB
C#
![]() |
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
|
|||
|
|
|||
|
[System.Serializable]
|
|||
|
public struct IndexValuePair<T>
|
|||
|
{
|
|||
|
[SerializeField] public int Key;
|
|||
|
[SerializeField] public T Value;
|
|||
|
|
|||
|
public IndexValuePair(int key, T value)
|
|||
|
{
|
|||
|
Key = key;
|
|||
|
Value = value;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
[System.Serializable]
|
|||
|
[CreateAssetMenu(fileName = "New Chest", menuName = "Inventory/Chest")]
|
|||
|
public class Chest
|
|||
|
{
|
|||
|
public int id;
|
|||
|
public int Id
|
|||
|
{
|
|||
|
get { return id; }
|
|||
|
set { id = value; }
|
|||
|
}
|
|||
|
|
|||
|
public string name;
|
|||
|
public string Name
|
|||
|
{
|
|||
|
get { return name; }
|
|||
|
set { name = value; }
|
|||
|
}
|
|||
|
|
|||
|
public string description;
|
|||
|
public string Description
|
|||
|
{
|
|||
|
get { return description; }
|
|||
|
set { description = value; }
|
|||
|
}
|
|||
|
|
|||
|
public GameObject chestModel;
|
|||
|
public GameObject ChestModel
|
|||
|
{
|
|||
|
get { return chestModel; }
|
|||
|
set { chestModel = value; }
|
|||
|
}
|
|||
|
|
|||
|
public ChestTypeEnum ChestType;
|
|||
|
|
|||
|
public List<IndexValuePair<Item>> Content = new List<IndexValuePair<Item>>();
|
|||
|
|
|||
|
|
|||
|
public Chest() { }
|
|||
|
|
|||
|
public Chest(Chest _chest)
|
|||
|
{
|
|||
|
this.Name = _chest.Name;
|
|||
|
this.Description = _chest.Description;
|
|||
|
this.ChestModel = _chest.ChestModel;
|
|||
|
this.ChestType = _chest.ChestType;
|
|||
|
this.Content = _chest.Content;
|
|||
|
}
|
|||
|
|
|||
|
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type)
|
|||
|
{
|
|||
|
this.Name = _name;
|
|||
|
this.Description = _description;
|
|||
|
this.ChestModel = _chestModel;
|
|||
|
this.ChestType = _type;
|
|||
|
}
|
|||
|
|
|||
|
public Chest(string _name, string _description, GameObject _chestModel, ChestTypeEnum _type, List<KeyValuePair<int, Item>> _content)
|
|||
|
{
|
|||
|
this.Name = _name;
|
|||
|
this.Description = _description;
|
|||
|
this.ChestModel = _chestModel;
|
|||
|
this.ChestType = _type;
|
|||
|
|
|||
|
SetContent(_content);
|
|||
|
}
|
|||
|
|
|||
|
public void SetContent(List<KeyValuePair<int, Item>> _content)
|
|||
|
{
|
|||
|
Content.Clear();
|
|||
|
|
|||
|
foreach (KeyValuePair<int, Item> element in _content)
|
|||
|
{
|
|||
|
Content.Add(new IndexValuePair<Item>(element.Key, element.Value));
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
public List<KeyValuePair<int, Item>> GetContent()
|
|||
|
{
|
|||
|
List<KeyValuePair<int, Item>> castedContent = new List<KeyValuePair<int, Item>>();
|
|||
|
|
|||
|
foreach (IndexValuePair<Item> element in Content)
|
|||
|
{
|
|||
|
castedContent.Add(new KeyValuePair<int, Item>(element.Key, element.Value));
|
|||
|
}
|
|||
|
|
|||
|
return castedContent;
|
|||
|
}
|
|||
|
}
|