80 lines
1.8 KiB
C#
80 lines
1.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
#if UNITY_EDITOR
|
|
using UnityEditor;
|
|
#endif
|
|
using UnityEngine;
|
|
|
|
public static class ConfigsHelper
|
|
{
|
|
private static Dictionary<string, Type> _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 Dictionary<string, Type> 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.Count;
|
|
|
|
LoadConfigs();
|
|
|
|
if (_configsList != null)
|
|
{
|
|
int diff = oldCount - _configsList.Count;
|
|
|
|
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.Count} items{addInfo}.");
|
|
}
|
|
|
|
[MenuItem("Tools/Configs/Info")]
|
|
public static void Info()
|
|
{
|
|
if(_configsList != null)
|
|
Debug.Log($"Configs loaded. {_configsList.Count} items.");
|
|
else
|
|
Debug.Log("Configs not loaded");
|
|
}
|
|
#endif
|
|
}
|