update: 更新API

feature/item_system
huyufei 2024-01-07 22:59:02 +08:00
parent 5bc24e3443
commit 74acbe841b
21 changed files with 83 additions and 47 deletions

View File

@ -10,12 +10,15 @@ namespace Guru.Editor
public class EditorGuruServiceIO
{
private static readonly string DefaultFileName = "guru-service";
private static readonly string SourceConfigFileName = "guru-service";
private const string LocalServicesConfigPath = "Guru/Resoures";
private const string SourceConfigExtension = ".json";
private const string LocalConfigExtension = ".txt";
private static string DefaultFilePath =
Path.GetFullPath(Path.Combine(Application.dataPath, $"{DefaultFileName}.json"));
Path.GetFullPath(Path.Combine(Application.dataPath, $"{SourceConfigFileName}{SourceConfigExtension}"));
internal static string EmbededServiceFilePath = "";
internal static string SourceServiceFilePath = "";
/// <summary>
/// 加载配置
@ -23,7 +26,8 @@ namespace Guru.Editor
/// <returns></returns>
public static GuruServicesConfig LoadConfig()
{
var a = AssetDatabase.FindAssets($"*{DefaultFileName}* t:TextAsset");
var a = AssetDatabase.FindAssets($"*{SourceConfigFileName}* t:TextAsset",
new string[] { Application.dataPath });
if (a == null || a.Length == 0)
{
Debug.Log($"<color=orange>--- Can't ind guru-services file</color>");
@ -32,7 +36,7 @@ namespace Guru.Editor
{
var p = AssetDatabase.GUIDToAssetPath(a[0]);
var fp = Path.GetFullPath(p);
if (File.Exists(fp)) EmbededServiceFilePath = fp;
if (File.Exists(fp)) SourceServiceFilePath = fp;
var t = AssetDatabase.LoadAssetAtPath<TextAsset>(p);
// Debug.Log($"<color=#88ff00>--- find services file:{p} \n{t.text}</color>");
return JsonMapper.ToObject<GuruServicesConfig>(t.text);
@ -59,9 +63,9 @@ namespace Guru.Editor
var json = jw.ToString();
if (string.IsNullOrEmpty(EmbededServiceFilePath)) EmbededServiceFilePath = DefaultFilePath;
File.WriteAllText(EmbededServiceFilePath, json);
Debug.Log($"Save config to {EmbededServiceFilePath}");
if (string.IsNullOrEmpty(SourceServiceFilePath)) SourceServiceFilePath = DefaultFilePath;
File.WriteAllText(SourceServiceFilePath, json);
Debug.Log($"Save config to {SourceServiceFilePath}");
}
/// <summary>
@ -88,14 +92,14 @@ namespace Guru.Editor
}
public static void DeployAppServiceFile()
public static void DeployLocalServiceFile()
{
var streamingPath = Application.streamingAssetsPath;
if(!Directory.Exists(streamingPath)) Directory.CreateDirectory(streamingPath);
var path = Path.Combine(streamingPath, $"{GuruSDK.ServicesConfigKey}.{GuruSDK.ServicesConfigExtension}");
var deployPath = Path.Combine(Application.dataPath, LocalServicesConfigPath);
if(!Directory.Exists(deployPath)) Directory.CreateDirectory(deployPath);
var path = Path.Combine(deployPath, $"{GuruSDK.ServicesConfigKey}.{LocalConfigExtension}");
var config = LoadConfig();
var from = EmbededServiceFilePath;
var from = SourceServiceFilePath;
if (string.IsNullOrEmpty(from) || !File.Exists(from)) // 文件不存在
{
return;

View File

@ -37,7 +37,7 @@ namespace Guru.Editor
{
static BoostOnLoad()
{
EditorGuruServiceIO.DeployAppServiceFile();
EditorGuruServiceIO.DeployLocalServiceFile();
}
}
}

View File

@ -473,7 +473,7 @@ namespace Guru.Editor
ApplyMods();
EditorUtility.DisplayCancelableProgressBar(barTitle, "All Mods is done", 0.8f);
EditorGuruServiceIO.DeployAppServiceFile(); // 部署文件
EditorGuruServiceIO.DeployLocalServiceFile(); // 部署文件
AssetDatabase.SaveAssets();

View File

@ -1,4 +1,6 @@
using UnityEngine.Networking;
namespace Guru
{
using System;
@ -24,6 +26,7 @@ namespace Guru
}
//-------------- data ---------------
public string uid = "";
public int b_level = 0;
public int b_play = 0;
public int buy_count = 0;
@ -38,7 +41,11 @@ namespace Guru
if(_successLevel == null) InitProperties();
return _successLevel.Value;
}
set => _successLevel.Value = value;
set
{
if(_successLevel == null) InitProperties();
_successLevel.Value = value;
}
}
public int TotalPlayedCount
@ -48,7 +55,11 @@ namespace Guru
if(_totalPlayed == null) InitProperties();
return _totalPlayed.Value;
}
set => _totalPlayed.Value = value;
set
{
if(_totalPlayed == null) InitProperties();
_totalPlayed.Value = value;
}
}
public int PurchasedCount
@ -58,7 +69,25 @@ namespace Guru
if(_purchasedCount == null) InitProperties();
return _purchasedCount.Value;
}
set => _purchasedCount.Value = value;
set
{
if(_purchasedCount == null) InitProperties();
_purchasedCount.Value = value;
}
}
public string UserId
{
get
{
if(_uid == null) InitProperties();
return _uid.Value;
}
set
{
if(_uid == null) InitProperties();
_uid.Value = value;
}
}
public bool IsIAPUser => PurchasedCount > 0;
@ -67,11 +96,12 @@ namespace Guru
private BindableProperty<int> _successLevel;
private BindableProperty<int> _totalPlayed;
private BindableProperty<int> _purchasedCount;
private BindableProperty<string> _uid;
public BindableProperty<int> PropBLevel => _successLevel;
public BindableProperty<int> PropBPlay => _totalPlayed;
public BindableProperty<int> PropBuyCount => _purchasedCount;
public BindableProperty<string> Uid => _uid;
#region 初始化
@ -113,6 +143,7 @@ namespace Guru
_successLevel = new BindableProperty<int>(b_level, OnLevelChanged);
_totalPlayed = new BindableProperty<int>(b_play, OnPlayedChanged);
_purchasedCount = new BindableProperty<int>(buy_count, OnPurchasedNumChanged);
_uid = new BindableProperty<string>(uid, OnUidChanged);
}
/// <summary>
@ -149,6 +180,12 @@ namespace Guru
buy_count = value;
Save();
}
private void OnUidChanged(string value)
{
uid = value;
Save();
}
#endregion
#region 启动配置
@ -157,12 +194,12 @@ namespace Guru
/// 从 Streaming 加载 AppServices 配置
/// </summary>
/// <returns></returns>
public string LoadAppServicesConfigJson()
public string LoadDefaltServicesConfigJson()
{
try
{
string path = Path.Combine(Application.streamingAssetsPath, $"{GuruSDK.ServicesConfigKey}.{GuruSDK.ServicesConfigExtension}");
return File.ReadAllText(path);
var txt = Resources.Load<TextAsset>(GuruSDK.ServicesConfigKey);
return txt?.text ?? "";
}
catch (Exception e)
{
@ -172,16 +209,6 @@ namespace Guru
}
#endregion
}

View File

@ -11,7 +11,6 @@ namespace Guru
public const string Version = "1.0.0";
public const string Tag = "[Guru]";
public const string ServicesConfigKey = "guru_services";
public const string ServicesConfigExtension = "cfg";
private static GuruSDK _instance;
/// <summary>
@ -52,11 +51,14 @@ namespace Guru
return false;
}
}
/// <summary>
/// 初始化成功标志位
/// </summary>
public static bool IsInitialSuccess { get; private set; } = false;
#region 初始化
private static GuruSDK CreateInstance()
{
var go = new GameObject(nameof(GuruSDK));
@ -87,8 +89,7 @@ namespace Guru
public static void Init(GuruSDKInitConfig config, Action<bool> onComplete)
{
LogI($"---- Guru SDK init ----");
LogI(config.ToString());
LogI($"---- Guru SDK init ----\n{config.ToString()}");
Instance.StartWithConfig(config, onComplete);
}
@ -105,6 +106,7 @@ namespace Guru
_initConfig = config;
_onCompleteCallback = onComplete;
IsInitialSuccess = false;
//---------- Start Firebase ------------
FirebaseUtil.InitFirebase(OnFirebaseReady);
@ -134,7 +136,8 @@ namespace Guru
// 根据上次的云控配置来初始化参数
SetupServicesConfig();
IsInitialSuccess = true;
_onCompleteCallback?.Invoke(true);
}
@ -145,14 +148,13 @@ namespace Guru
/// <returns></returns>
private Dictionary<string, object> BuildDefaultRemoteData(Dictionary<string, object> dict)
{
string json = Model.LoadAppServicesConfigJson(); // 注入默认的Services 配置值
if (!string.IsNullOrEmpty(json))
{
if (dict == null) dict = new Dictionary<string, object>(3);
dict[ServicesConfigKey] = json;
return dict;
}
return null;
if (dict == null) dict = new Dictionary<string, object>(3);
// 注入默认的 Services 配置值
string json = Model.LoadDefaltServicesConfigJson();
if (!string.IsNullOrEmpty(json)) dict[ServicesConfigKey] = json;
return dict;
}
/// <summary>
@ -230,6 +232,8 @@ namespace Guru
SetUserBPlay(bplay);
}
public static string UID => _model?.UserId ?? "";
#endregion
#region Misc
@ -351,5 +355,6 @@ namespace Guru
#endregion
}
}