Scriptum/Assets/Scripts/REFACTORING/Application/Shared/Manager/Panel/SceneBaseDataLoader.cs

89 lines
2.1 KiB
C#
Raw Normal View History

2022-10-22 18:04:21 +02:00
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();
}
2022-11-27 21:28:55 +01:00
/* case SceneElementTypeEnum.Static:
2022-10-22 18:04:21 +02:00
{
return LoadStaticData();
2022-11-27 21:28:55 +01:00
}*/
2022-10-22 18:04:21 +02:00
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);
}
2022-11-27 21:28:55 +01:00
/* case SceneElementTypeEnum.Static:
2022-10-22 18:04:21 +02:00
{
return SaveStaticData(_elements);
2022-11-27 21:28:55 +01:00
}*/
2022-10-22 18:04:21 +02:00
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();
2022-11-27 21:28:55 +01:00
protected virtual bool SaveDynamicData(List<T> _elements)
{
try
{
SaveModelSystem.SaveModelList(_elements);
return true;
}
catch (Exception e) { Debug.LogError(e.Message); }
return false;
}
2022-10-22 18:04:21 +02:00
protected abstract bool SaveGenericData(List<T> _elements);
}