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

View File

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

View File

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

View File

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

View File

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