Scriptum/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs
2022-11-28 00:52:47 +01:00

91 lines
2.2 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public abstract class SceneBaseDataLoader<T> : SceneDataLoaderInterface<T>
{
protected SaveModelSystem<T> SaveModelSystem;
protected PathBuilder PathBuilder;
protected string CurrentMap;
protected SceneBaseDataLoader()
{
PathBuilder = new PathBuilder();
CurrentMap = SceneManager.GetActiveScene().name;
}
public List<T> LoadData(SceneElementTypeEnum type)
{
switch (type)
{
case SceneElementTypeEnum.None:
{
return LoadGenericData();
}
/* case SceneElementTypeEnum.Static:
{
return LoadStaticData();
}*/
case SceneElementTypeEnum.Dynamic:
{
return LoadDynamicData();
}
default: // for SceneElementTypeEnum.All
{
Debug.Log("Handle All case...");
return new List<T>();
}
}
}
public bool SaveData(List<T> _elements, SceneElementTypeEnum type)
{
switch (type)
{
case SceneElementTypeEnum.None:
{
return SaveGenericData(_elements);
}
/* case SceneElementTypeEnum.Static:
{
return SaveStaticData(_elements);
}*/
case SceneElementTypeEnum.Dynamic:
{
return SaveDynamicData(_elements);
}
default: // for SceneElementTypeEnum.All
{
Debug.Log("Handle All case...");
return true;
}
}
}
protected abstract List<T> LoadDynamicData();
protected abstract List<T> LoadGenericData();
protected virtual bool SaveDynamicData(List<T> _elements)
{
Debug.Log(SaveModelSystem.Path);
try
{
SaveModelSystem.SaveModelList(_elements);
return true;
}
catch (Exception e) { Debug.LogError(e.Message); }
return false;
}
protected abstract bool SaveGenericData(List<T> _elements);
}