79 lines
1.7 KiB
C#
79 lines
1.7 KiB
C#
using System;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
using UnityEngine;
|
|
|
|
public static class ConfigsHelper
|
|
{
|
|
private static string[] _configsList;
|
|
private static Configs _configs;
|
|
|
|
private static void LoadConfigs()
|
|
{
|
|
var configs = new Configs();
|
|
var asset = (TextAsset) Resources.Load("ext_config/configs/packed_bundle");
|
|
configs.Load(new System.IO.MemoryStream(asset.bytes));
|
|
|
|
_configs = configs;
|
|
_configsList = configs.GetList();
|
|
}
|
|
|
|
public static Configs GetConfigs()
|
|
{
|
|
if (_configs == null)
|
|
{
|
|
LoadConfigs();
|
|
}
|
|
|
|
return _configs;
|
|
}
|
|
|
|
public static string[] GetConfigsList()
|
|
{
|
|
if (_configsList == null)
|
|
{
|
|
LoadConfigs();
|
|
}
|
|
|
|
return _configsList;
|
|
}
|
|
|
|
#if UNITY_EDITOR
|
|
[MenuItem("Tools/Configs/Reload")]
|
|
public static void Reload()
|
|
{
|
|
string addInfo = "";
|
|
|
|
int oldCount = 0;
|
|
|
|
if (_configsList != null)
|
|
oldCount = _configsList.Length;
|
|
|
|
LoadConfigs();
|
|
|
|
if (_configsList != null)
|
|
{
|
|
int diff = oldCount - _configsList.Length;
|
|
|
|
if (diff < 0)
|
|
addInfo = $", {Math.Abs(diff)} new";
|
|
else if(diff > 0)
|
|
addInfo = $", {Math.Abs(diff)} deleted";
|
|
}
|
|
|
|
if (_configsList != null)
|
|
Debug.Log($"Configs reloaded. {_configsList.Length} items{addInfo}.");
|
|
}
|
|
|
|
[MenuItem("Tools/Configs/Reload")]
|
|
public static void Info()
|
|
{
|
|
if(_configsList != null)
|
|
Debug.Log($"Configs loaded. {_configsList.Length} items.");
|
|
else
|
|
Debug.Log("Configs not loaded");
|
|
}
|
|
#endif
|
|
}
|