93 lines
2.7 KiB
C#
93 lines
2.7 KiB
C#
using UnityEngine;
|
|
using Guru;
|
|
using NUnit.Framework;
|
|
|
|
namespace Guru.Editor
|
|
{
|
|
using System.IO;
|
|
using UnityEditor;
|
|
using Guru.LitJson;
|
|
|
|
public class EditorGuruServiceIO
|
|
{
|
|
private static readonly string DefaultFileName = "guru-service";
|
|
|
|
private static string DefaultFilePath =
|
|
Path.GetFullPath(Path.Combine(Application.dataPath, $"{DefaultFileName}.json"));
|
|
|
|
private static string _selectedFilePath = "";
|
|
|
|
/// <summary>
|
|
/// 加载配置
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
public static GuruServiceConfig LoadConfig()
|
|
{
|
|
var a = AssetDatabase.FindAssets($"*{DefaultFileName}* t:TextAsset");
|
|
if (a == null || a.Length == 0)
|
|
{
|
|
Debug.Log($"<color=orange>--- Can't ind guru-services file</color>");
|
|
}
|
|
else
|
|
{
|
|
var p = AssetDatabase.GUIDToAssetPath(a[0]);
|
|
var fp = Path.GetFullPath(p);
|
|
if (File.Exists(fp)) _selectedFilePath = fp;
|
|
var t = AssetDatabase.LoadAssetAtPath<TextAsset>(p);
|
|
// Debug.Log($"<color=#88ff00>--- find services file:{p} \n{t.text}</color>");
|
|
return JsonMapper.ToObject<GuruServiceConfig>(t.text);
|
|
}
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 保存配置
|
|
/// </summary>
|
|
/// <param name="config"></param>
|
|
internal static void SaveConfig(GuruServiceConfig config = null)
|
|
{
|
|
if (config == null)
|
|
{
|
|
config = new GuruServiceConfig();
|
|
}
|
|
|
|
var jw = new JsonWriter()
|
|
{
|
|
PrettyPrint = true,
|
|
};
|
|
JsonMapper.ToJson(config, jw);
|
|
|
|
var json = jw.ToString();
|
|
|
|
if (string.IsNullOrEmpty(_selectedFilePath)) _selectedFilePath = DefaultFilePath;
|
|
File.WriteAllText(_selectedFilePath, json);
|
|
Debug.Log($"Save config to {_selectedFilePath}");
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建空配置
|
|
/// </summary>
|
|
/// <returns></returns>
|
|
internal static GuruServiceConfig CreateEmpty()
|
|
{
|
|
var cfg = new GuruServiceConfig();
|
|
cfg.version = GuruSDK.Version;
|
|
cfg.app_settings = new GuruAppSettings();
|
|
cfg.ad_settings = new GuruAdSettings();
|
|
cfg.adjust_settings = new GuruAdjustSettings();
|
|
cfg.fb_settings = new GuruFbSettings();
|
|
return cfg;
|
|
}
|
|
|
|
|
|
[Test]
|
|
public static void Test_SaveConfig()
|
|
{
|
|
var cfg = CreateEmpty();
|
|
SaveConfig(cfg);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
} |