2022-11-24 03:03:30 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEditor;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class EquipmentDataManager : SceneBaseDataManager<IndexValuePair<int, EquippableItem>>
|
|
|
|
|
{
|
|
|
|
|
protected override string OBJECT_FOLDER_NAME { get { return "Equipment"; } }
|
|
|
|
|
protected override string OBJECT_LIST_NAME { get { return "EquipmentList"; } }
|
|
|
|
|
|
|
|
|
|
protected new SceneBaseDataLoader<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>> DataLoader { get; set; }
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
[SerializeField] public List<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>> ElementsToBuildOnSceneList = new List<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>>();
|
|
|
|
|
[SerializeField] List<IndexValuePair<int, EquippableItem>> convertedData = new List<IndexValuePair<int, EquippableItem>>();
|
|
|
|
|
|
|
|
|
|
|
2022-11-24 03:03:30 +01:00
|
|
|
|
public override void Awake()
|
|
|
|
|
{
|
|
|
|
|
if (Instance == null)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Create: " + gameObject);
|
|
|
|
|
|
|
|
|
|
Instance = this;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.Log(Instance);
|
|
|
|
|
Debug.LogError(gameObject);
|
|
|
|
|
Destroy(gameObject);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
public override void Start()
|
2022-11-24 03:03:30 +01:00
|
|
|
|
{
|
|
|
|
|
Debug.Log("Start SceneEquipmentData manager");
|
|
|
|
|
|
|
|
|
|
//TaskUIManager.FindOrCreateInstance();
|
2022-11-27 21:28:55 +01:00
|
|
|
|
UiManager = EquipmentUIManager.Instance;
|
2022-11-24 03:03:30 +01:00
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
if (UiManager == null)
|
2022-11-24 03:03:30 +01:00
|
|
|
|
throw new NullReferenceException("EquipmentUIManager not found!!!");
|
|
|
|
|
|
|
|
|
|
//StaticDataList = (new EquipmentDataListManager()).SetUiManager(ref taskManager);
|
2022-11-27 21:28:55 +01:00
|
|
|
|
DynamicDataList = (new EquipmentDataListManager()).SetUiManager(ref UiManager);
|
2022-11-24 03:03:30 +01:00
|
|
|
|
|
|
|
|
|
DataLoader = new EquipmentDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME);
|
|
|
|
|
|
|
|
|
|
((EquipmentDataListManager)DynamicDataList).InitEquipment();
|
|
|
|
|
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
base.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected SceneBaseDataManager<IndexValuePair<int, EquippableItem>> GetObjectType()
|
|
|
|
|
{
|
|
|
|
|
return GameObject.FindObjectOfType<EquipmentDataManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected SceneBaseDataManager<IndexValuePair<int, EquippableItem>> CreateInstance(ref GameObject managerGameObject)
|
|
|
|
|
{
|
|
|
|
|
return managerGameObject.AddComponent<EquipmentDataManager>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UseDefaultSettings()
|
|
|
|
|
{
|
|
|
|
|
foreach (IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset> asset in ElementsToBuildOnSceneList)
|
2022-11-24 03:03:30 +01:00
|
|
|
|
{
|
2022-11-27 21:28:55 +01:00
|
|
|
|
convertedData.Add(
|
|
|
|
|
new IndexValuePair<int, EquippableItem>((int)asset.Key, (EquippableItem)asset.Value.EquippableItem)
|
|
|
|
|
);
|
2022-11-24 03:03:30 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
DynamicDataList.SetList(convertedData);
|
2022-11-24 03:03:30 +01:00
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
UiManager.SetList(convertedData);
|
|
|
|
|
}
|
2022-11-24 03:03:30 +01:00
|
|
|
|
|
2022-11-27 21:28:55 +01:00
|
|
|
|
protected override void UseDynamicSettings()
|
|
|
|
|
{
|
|
|
|
|
LoadDynamicData();
|
|
|
|
|
|
|
|
|
|
UiManager.SetList(DynamicDataList.GetList());
|
|
|
|
|
}
|
2022-11-24 03:03:30 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#region override load & save
|
|
|
|
|
protected override bool LoadData(SceneElementTypeEnum type, ref DataListManager<IndexValuePair<int, EquippableItem>> dataListManager)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 1. Convert EquippableItemPrefabAsset to EquippableItem list
|
|
|
|
|
List<IndexValuePair<int, EquippableItem>> convertedList = new List<IndexValuePair<int, EquippableItem>>();
|
|
|
|
|
|
|
|
|
|
foreach (IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset> loadedEquippableItemPrefarbAssetElement in (List<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>>)DataLoader.LoadData(type))
|
|
|
|
|
{
|
|
|
|
|
if(loadedEquippableItemPrefarbAssetElement.Value != null)
|
|
|
|
|
convertedList.Add(new IndexValuePair<int, EquippableItem>((int)loadedEquippableItemPrefarbAssetElement.Key, (EquippableItem)loadedEquippableItemPrefarbAssetElement.Value.EquippableItem));
|
|
|
|
|
else
|
|
|
|
|
convertedList.Add(new IndexValuePair<int, EquippableItem>((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<IndexValuePair<int, EquippableItem>> _elements, SceneElementTypeEnum type)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
// 1. Convert EquippableItem to EquippableItemPrefabAsset list
|
|
|
|
|
List<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>> convertedList = new List<IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>>();
|
|
|
|
|
|
|
|
|
|
foreach (IndexValuePair<int, EquippableItem> itemElement in _elements)
|
|
|
|
|
{
|
|
|
|
|
if(itemElement.Value)
|
|
|
|
|
convertedList.Add(new IndexValuePair<EquipmentPanelSlotsTypeEnum, EquippableItemPrefabAsset>(
|
|
|
|
|
(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, EquippableItemPrefabAsset>((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
|
|
|
|
|
}
|