diff --git a/Editor/GuruManager/Config/EditorGuruServiceIO.cs b/Editor/GuruManager/Config/EditorGuruServiceIO.cs index bdfa485..0135915 100644 --- a/Editor/GuruManager/Config/EditorGuruServiceIO.cs +++ b/Editor/GuruManager/Config/EditorGuruServiceIO.cs @@ -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 = ""; /// /// 加载配置 @@ -23,7 +26,8 @@ namespace Guru.Editor /// 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($"--- Can't ind guru-services file"); @@ -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(p); // Debug.Log($"--- find services file:{p} \n{t.text}"); return JsonMapper.ToObject(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}"); } /// @@ -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; diff --git a/Editor/GuruManager/Helper/GuruSDKBooster.cs b/Editor/GuruManager/Helper/GuruSDKBooster.cs index 93e8669..91b824f 100644 --- a/Editor/GuruManager/Helper/GuruSDKBooster.cs +++ b/Editor/GuruManager/Helper/GuruSDKBooster.cs @@ -37,7 +37,7 @@ namespace Guru.Editor { static BoostOnLoad() { - EditorGuruServiceIO.DeployAppServiceFile(); + EditorGuruServiceIO.DeployLocalServiceFile(); } } } \ No newline at end of file diff --git a/Editor/GuruManager/Manager/GuruSDKManager.cs b/Editor/GuruManager/Manager/GuruSDKManager.cs index 545864c..3fffd13 100644 --- a/Editor/GuruManager/Manager/GuruSDKManager.cs +++ b/Editor/GuruManager/Manager/GuruSDKManager.cs @@ -473,7 +473,7 @@ namespace Guru.Editor ApplyMods(); EditorUtility.DisplayCancelableProgressBar(barTitle, "All Mods is done", 0.8f); - EditorGuruServiceIO.DeployAppServiceFile(); // 部署文件 + EditorGuruServiceIO.DeployLocalServiceFile(); // 部署文件 AssetDatabase.SaveAssets(); diff --git a/Runtime/Code/Core/GuruSDKInitConfig.cs b/Runtime/Code/Config/GuruSDKInitConfig.cs similarity index 100% rename from Runtime/Code/Core/GuruSDKInitConfig.cs rename to Runtime/Code/Config/GuruSDKInitConfig.cs diff --git a/Runtime/Code/Core/GuruSDKInitConfig.cs.meta b/Runtime/Code/Config/GuruSDKInitConfig.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDKInitConfig.cs.meta rename to Runtime/Code/Config/GuruSDKInitConfig.cs.meta diff --git a/Runtime/Code/Model/GuruSDKModel.cs b/Runtime/Code/Model/GuruSDKModel.cs index b6c0d6c..c4a930b 100644 --- a/Runtime/Code/Model/GuruSDKModel.cs +++ b/Runtime/Code/Model/GuruSDKModel.cs @@ -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 _successLevel; private BindableProperty _totalPlayed; private BindableProperty _purchasedCount; + private BindableProperty _uid; public BindableProperty PropBLevel => _successLevel; public BindableProperty PropBPlay => _totalPlayed; public BindableProperty PropBuyCount => _purchasedCount; - + public BindableProperty Uid => _uid; #region 初始化 @@ -113,6 +143,7 @@ namespace Guru _successLevel = new BindableProperty(b_level, OnLevelChanged); _totalPlayed = new BindableProperty(b_play, OnPlayedChanged); _purchasedCount = new BindableProperty(buy_count, OnPurchasedNumChanged); + _uid = new BindableProperty(uid, OnUidChanged); } /// @@ -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 配置 /// /// - 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(GuruSDK.ServicesConfigKey); + return txt?.text ?? ""; } catch (Exception e) { @@ -172,16 +209,6 @@ namespace Guru } #endregion - - - - - - - - - - } diff --git a/Runtime/Code/Core.meta b/Runtime/Code/SDK.meta similarity index 100% rename from Runtime/Code/Core.meta rename to Runtime/Code/SDK.meta diff --git a/Runtime/Code/Core/GuruSDK.Ads.cs b/Runtime/Code/SDK/GuruSDK.Ads.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.Ads.cs rename to Runtime/Code/SDK/GuruSDK.Ads.cs diff --git a/Runtime/Code/Core/GuruSDK.Ads.cs.meta b/Runtime/Code/SDK/GuruSDK.Ads.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.Ads.cs.meta rename to Runtime/Code/SDK/GuruSDK.Ads.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.Analytics.cs b/Runtime/Code/SDK/GuruSDK.Analytics.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.Analytics.cs rename to Runtime/Code/SDK/GuruSDK.Analytics.cs diff --git a/Runtime/Code/Core/GuruSDK.Analytics.cs.meta b/Runtime/Code/SDK/GuruSDK.Analytics.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.Analytics.cs.meta rename to Runtime/Code/SDK/GuruSDK.Analytics.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.Callback.cs b/Runtime/Code/SDK/GuruSDK.Callback.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.Callback.cs rename to Runtime/Code/SDK/GuruSDK.Callback.cs diff --git a/Runtime/Code/Core/GuruSDK.Callback.cs.meta b/Runtime/Code/SDK/GuruSDK.Callback.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.Callback.cs.meta rename to Runtime/Code/SDK/GuruSDK.Callback.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.IAP.cs b/Runtime/Code/SDK/GuruSDK.IAP.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.IAP.cs rename to Runtime/Code/SDK/GuruSDK.IAP.cs diff --git a/Runtime/Code/Core/GuruSDK.IAP.cs.meta b/Runtime/Code/SDK/GuruSDK.IAP.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.IAP.cs.meta rename to Runtime/Code/SDK/GuruSDK.IAP.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.Rating.cs b/Runtime/Code/SDK/GuruSDK.Rating.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.Rating.cs rename to Runtime/Code/SDK/GuruSDK.Rating.cs diff --git a/Runtime/Code/Core/GuruSDK.Rating.cs.meta b/Runtime/Code/SDK/GuruSDK.Rating.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.Rating.cs.meta rename to Runtime/Code/SDK/GuruSDK.Rating.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.Remote.cs b/Runtime/Code/SDK/GuruSDK.Remote.cs similarity index 100% rename from Runtime/Code/Core/GuruSDK.Remote.cs rename to Runtime/Code/SDK/GuruSDK.Remote.cs diff --git a/Runtime/Code/Core/GuruSDK.Remote.cs.meta b/Runtime/Code/SDK/GuruSDK.Remote.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.Remote.cs.meta rename to Runtime/Code/SDK/GuruSDK.Remote.cs.meta diff --git a/Runtime/Code/Core/GuruSDK.cs b/Runtime/Code/SDK/GuruSDK.cs similarity index 93% rename from Runtime/Code/Core/GuruSDK.cs rename to Runtime/Code/SDK/GuruSDK.cs index 8313277..20edc7d 100644 --- a/Runtime/Code/Core/GuruSDK.cs +++ b/Runtime/Code/SDK/GuruSDK.cs @@ -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; /// @@ -52,11 +51,14 @@ namespace Guru return false; } } - + + /// + /// 初始化成功标志位 + /// + 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 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 /// private Dictionary BuildDefaultRemoteData(Dictionary dict) { - string json = Model.LoadAppServicesConfigJson(); // 注入默认的Services 配置值 - if (!string.IsNullOrEmpty(json)) - { - if (dict == null) dict = new Dictionary(3); - dict[ServicesConfigKey] = json; - return dict; - } - return null; + if (dict == null) dict = new Dictionary(3); + + // 注入默认的 Services 配置值 + string json = Model.LoadDefaltServicesConfigJson(); + if (!string.IsNullOrEmpty(json)) dict[ServicesConfigKey] = json; + + return dict; } /// @@ -230,6 +232,8 @@ namespace Guru SetUserBPlay(bplay); } + public static string UID => _model?.UserId ?? ""; + #endregion #region Misc @@ -351,5 +355,6 @@ namespace Guru #endregion + } } \ No newline at end of file diff --git a/Runtime/Code/Core/GuruSDK.cs.meta b/Runtime/Code/SDK/GuruSDK.cs.meta similarity index 100% rename from Runtime/Code/Core/GuruSDK.cs.meta rename to Runtime/Code/SDK/GuruSDK.cs.meta