Scriptum/Assets/Scripts/SceneManager/SaveChest/ChestPrefarbAssetData.cs

55 lines
2.0 KiB
C#
Raw Normal View History

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.Linq;
[System.Serializable]
public class ChestPrefarbAssetData
{
public string name;
public string prefarbAssetName;
public float[] position;
public Dictionary<int, EquippableItemPrefarbAssetData> content = new Dictionary<int, EquippableItemPrefarbAssetData>();
public ChestPrefarbAssetData(ChestPrefarbAsset chestPrefarbAsset)
{
name = chestPrefarbAsset.name;
prefarbAssetName = chestPrefarbAsset.prefarbAssetName;
position = new float[3];
position[0] = chestPrefarbAsset.position.x;
position[1] = chestPrefarbAsset.position.y;
position[2] = chestPrefarbAsset.position.z;
Debug.Log("ChestPrefarbAsset to ChestPrefarbAssetData - " + chestPrefarbAsset.name);
foreach(KeyValuePair<int, EquippableItemPrefarbAsset> itemEntry in chestPrefarbAsset.content)
{
Debug.Log("Slot nr " + itemEntry.Key);
this.content[itemEntry.Key] = this.EquippableItemPrefarbAssetToData(itemEntry.Value);
}
}
public EquippableItemPrefarbAssetData EquippableItemPrefarbAssetToData(EquippableItemPrefarbAsset equippableItemPrefarbAsset)
{
return new EquippableItemPrefarbAssetData(equippableItemPrefarbAsset);
}
public ChestPrefarbAsset MapDataToChestPrefarbAsset()
{
ChestPrefarbAsset chestPrefarbAsset = new ChestPrefarbAsset();
chestPrefarbAsset.name = this.name;
chestPrefarbAsset.prefarbAssetName = this.prefarbAssetName;
chestPrefarbAsset.position = new Vector3(this.position[0], this.position[1], this.position[2]);
foreach(KeyValuePair<int, EquippableItemPrefarbAssetData> equippableItemPrefarbAssetDataEntry in this.content)
{
chestPrefarbAsset.content[equippableItemPrefarbAssetDataEntry.Key] = equippableItemPrefarbAssetDataEntry.Value.MapDataToEquippableItemPrefarbAsset();
}
return chestPrefarbAsset;
}
}