using System; using System.Collections.Generic; using System.Linq; using UnityEngine; [Serializable] public class SceneChestDataManager : SceneBaseDataManager { protected override string OBJECT_FOLDER_NAME { get { return "Chest"; } } protected override string OBJECT_LIST_NAME { get { return "ChestList"; } } //protected new SceneBaseDataLoader DataLoader { get; set; } protected SceneChestBuilder ChestBuilder { get; set; } [SerializeField] Chest CurrentChest; [SerializeField] protected new ChestUIManager UiManager; [SerializeField] public List ElementsToBuildOnSceneList = new List(); [SerializeField] List convertedData = new List(); public override void Awake() { if (Instance == null) { Instance = this; } else { Destroy(gameObject); } } public override void Start() { Debug.Log("Start SceneChestData manager"); //TaskUIManager.FindOrCreateInstance(); UiManager = ChestUIManager.Instance; if (UiManager == null) throw new NullReferenceException("ChestUIManager not found!!!"); DynamicDataList = (new ChestDataListManager()).SetUiManager(ref UiManager); DataLoader = new SceneChestDataLoader(OBJECT_LIST_NAME, OBJECT_FOLDER_NAME); ChestBuilder = new SceneChestBuilder(); base.Start(); } // TODO - save ChestPrefabAsset (we need to save coords...) but in manager handle Chest data.. // protected SceneBaseDataManager GetObjectType() { return GameObject.FindObjectOfType(); } protected SceneBaseDataManager CreateInstance(ref GameObject managerGameObject) { return managerGameObject.AddComponent(); } protected override void UseDefaultSettings() { foreach (ChestPrefabAssetData asset in ElementsToBuildOnSceneList) { convertedData.Add((ChestPrefabAsset)asset.MapDataToPrefabAssetModel()); } ChestBuilder.ElementsToBuildOnSceneList = convertedData; ChestBuilder.BuildList(); DynamicDataList.SetList(convertedData); List tmp = new List(); foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); } UiManager.SetList(tmp); } protected override void UseDynamicSettings() { // BuildList(); // when chest detect player in near arrea and player press "c" // open panel -> chest controller handle Open panel in Scene Chest Manager passing info about what Chest Palyer want to open // Manager Build panel and pass info about chest content LoadDynamicData(); // VERy VERY provisional SOLUTION if (DynamicDataList.GetList().Count == 0) { UseDefaultSettings(); return; } ChestBuilder.ElementsToBuildOnSceneList = DynamicDataList.GetList(); ChestBuilder.BuildList(); List tmp = new List(); foreach (ChestPrefabAsset asset in ChestBuilder.ElementsToBuildOnSceneList) { tmp.Add(asset.Chest); } UiManager.SetList(tmp); } // TODO manager api // open panel extend function // close panel extend function // TODO chest api // add to chest - find chest by its name np // remove from chest - select chest by its name - // chesk item in chest - check chest by tis name public override bool SaveDynamicData() { // TODO // how to get list // 1. List in UI manager should be synchronized with list in this manager foreach (Chest chest in UiManager.GetList()) { DynamicDataList.GetList().Where(el => el.Name == chest.Name).ToList().ForEach(slot => slot.Chest = chest); } //DynamicDataList.SetList(tmp); // approach: // 1. get from outside, update local list && us it // 2. Handle list synchronized all the time & pass local list return SaveData(DynamicDataList.GetList(), SceneElementTypeEnum.Dynamic); } }