using System; using System.Collections.Generic; using UnityEditor; using UnityEngine; public class EquipmentDataManager : SceneBaseDataManager> { protected override string OBJECT_FOLDER_NAME { get { return "Equipment"; } } protected override string OBJECT_LIST_NAME { get { return "EquipmentList"; } } protected new SceneBaseDataLoader> DataLoader { get; set; } [SerializeField] public List> ElementsToBuildOnSceneList = new List>(); [SerializeField] List> convertedData = new List>(); public override void Awake() { if (Instance == null) { Debug.Log("Create: " + gameObject); Instance = this; } else { Debug.Log(Instance); Debug.LogError(gameObject); Destroy(gameObject); } } public override void Start() { Debug.Log("Start SceneEquipmentData manager"); //TaskUIManager.FindOrCreateInstance(); UiManager = EquipmentUIManager.Instance; if (UiManager == null) throw new NullReferenceException("EquipmentUIManager not found!!!"); //StaticDataList = (new EquipmentDataListManager()).SetUiManager(ref taskManager); DynamicDataList = (new EquipmentDataListManager()).SetUiManager(ref UiManager); DataLoader = new EquipmentDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); ((EquipmentDataListManager)DynamicDataList).InitEquipment(); base.Start(); } protected SceneBaseDataManager> GetObjectType() { return GameObject.FindObjectOfType(); } protected SceneBaseDataManager> CreateInstance(ref GameObject managerGameObject) { return managerGameObject.AddComponent(); } protected override void UseDefaultSettings() { foreach (IndexValuePair asset in ElementsToBuildOnSceneList) { convertedData.Add( new IndexValuePair((int)asset.Key, (EquippableItem)asset.Value.EquippableItem) ); } DynamicDataList.SetList(convertedData); UiManager.SetList(convertedData); } protected override void UseDynamicSettings() { LoadDynamicData(); UiManager.SetList(DynamicDataList.GetList()); } #region override load & save protected override bool LoadData(SceneElementTypeEnum type, ref DataListManager> dataListManager) { try { // 1. Convert EquippableItemPrefabAsset to EquippableItem list List> convertedList = new List>(); foreach (IndexValuePair loadedEquippableItemPrefarbAssetElement in (List>)DataLoader.LoadData(type)) { if(loadedEquippableItemPrefarbAssetElement.Value != null) convertedList.Add(new IndexValuePair((int)loadedEquippableItemPrefarbAssetElement.Key, (EquippableItem)loadedEquippableItemPrefarbAssetElement.Value.EquippableItem)); else convertedList.Add(new IndexValuePair((int)loadedEquippableItemPrefarbAssetElement.Key, null)); } // 2. Pass loaded list to InventoryDataManager dataListManager.SetList(convertedList); return true; } catch (Exception e) { Debug.LogError(e.Message); } return false; } protected override bool SaveData(List> _elements, SceneElementTypeEnum type) { try { // 1. Convert EquippableItem to EquippableItemPrefabAsset list List> convertedList = new List>(); foreach (IndexValuePair itemElement in _elements) { if(itemElement.Value) convertedList.Add(new IndexValuePair( (EquipmentPanelSlotsTypeEnum)itemElement.Key, new EquippableItemPrefabAsset( itemElement.Value.Name, itemElement.Value.ItemModel.name, new Vector3(0, 0, 0), itemElement.Value ) )); else convertedList.Add(new IndexValuePair((EquipmentPanelSlotsTypeEnum)itemElement.Key, null)); } // 2. Pass loaded list to InventoryDataManager DataLoader.SaveData(convertedList, type); return true; } catch (Exception e) { Debug.LogError(e.Message); } return false; } #endregion }