using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnityEngine; [Serializable] public class ChestBuildModel { [SerializeField] public string ChestName; [SerializeField] public GameObject ChestPrefab; [SerializeField] public Vector3 Position; [SerializeField] public List> Content = new List>(); public ChestBuildModel(ChestPrefabAsset chestPrefabAsset) { ChestName = chestPrefabAsset.Chest.Name; ChestPrefab = chestPrefabAsset.Chest.ChestModel; Position = chestPrefabAsset.Position; Content.Clear(); foreach (IndexValuePair item in chestPrefabAsset.Chest.Content) { Content.Add( new IndexValuePair(item.Key, item.Value) ); } } public ChestPrefabAsset MapBuildModelToPrefabAssetModel() { ChestPrefabAsset chestPrefabAsset = new ChestPrefabAsset( ChestName, ChestPrefab.gameObject.name, Position ); chestPrefabAsset.Chest = new Chest(ChestPrefab.GetComponent().Chest); chestPrefabAsset.Chest.ChestModel = ChestPrefab; chestPrefabAsset.Chest.Name = ChestName; chestPrefabAsset.Chest.Content = new List>(); foreach (var ChestElement in Content) { var castedObject = ChestElement.Value as EquippableItem; if (castedObject == null) chestPrefabAsset.Chest.Content.Add( new IndexValuePair(ChestElement.Key, new EquippableItem(ChestElement.Value)) ); else chestPrefabAsset.Chest.Content.Add( new IndexValuePair(ChestElement.Key, castedObject) ); } return chestPrefabAsset; } public static List ConvertPrefabAssetListToBuildModelList(List chestPrefabAssetList) { List convertedList = new List(); foreach(var element in chestPrefabAssetList) { convertedList.Add(ChestBuildModel.ConvertPrefabAssetModelToBuildModel(element)); } return convertedList; } public static ChestBuildModel ConvertPrefabAssetModelToBuildModel(ChestPrefabAsset chestPrefabAsset) { return new ChestBuildModel(chestPrefabAsset); } }