diff --git a/Assets/Huawei/Dlls/HuaweiMobileServices.dll b/Assets/Huawei/Dlls/HuaweiMobileServices.dll index fc442e90..09d7becd 100644 Binary files a/Assets/Huawei/Dlls/HuaweiMobileServices.dll and b/Assets/Huawei/Dlls/HuaweiMobileServices.dll differ diff --git a/Assets/Huawei/Editor/Extensions/StringExtensions.cs b/Assets/Huawei/Editor/Extensions/StringExtensions.cs index 76c6477c..f8be9cca 100644 --- a/Assets/Huawei/Editor/Extensions/StringExtensions.cs +++ b/Assets/Huawei/Editor/Extensions/StringExtensions.cs @@ -103,5 +103,20 @@ public static string RemoveAfter(this string value, char toRemove) index = index == 0 ? value.Length : index; return value.Substring(0, index); } + + public static string ToCamelCase(this string s) + { + var x = s.Replace("_", ""); + if (x.Length == 0) return "null"; + x = Regex.Replace(x, "([A-Z])([A-Z]+)($|[A-Z])", + m => m.Groups[1].Value + m.Groups[2].Value.ToLower() + m.Groups[3].Value); + return char.ToLower(x[0]) + x.Substring(1); + } + + public static string ToPascalCase(this string s) + { + var x = ToCamelCase(s); + return char.ToUpper(x[0]) + x.Substring(1); + } } } diff --git a/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs b/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs new file mode 100644 index 00000000..daf68fe3 --- /dev/null +++ b/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace HmsPlugin +{ + [InitializeOnLoad] + public class HMSPackageChecker + { + static HMSPackageChecker() + { + AssetDatabase.importPackageCompleted += OnImportPackageCompleted; + } + + private static void OnImportPackageCompleted(string packageName) + { + if (packageName.Contains("HMSUnityPackage")) + { + var enabledEditors = HMSMainKitsTabFactory.GetEnabledEditors(); + if (enabledEditors != null && enabledEditors.Count > 0) + { + enabledEditors.ForEach(c => c.DestroyManagers()); + enabledEditors.ForEach(f => f.CreateManagers()); + } + } + } + } +} \ No newline at end of file diff --git a/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs.meta b/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs.meta new file mode 100644 index 00000000..6644b8e1 --- /dev/null +++ b/Assets/Huawei/Editor/Utils/HMSPackageChecker.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4374717c2dd7f4e4cb6ae8b88e7f3fc5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Huawei/Editor/View/CloudDBTab.meta b/Assets/Huawei/Editor/View/CloudDBTab.meta new file mode 100644 index 00000000..d45de3f5 --- /dev/null +++ b/Assets/Huawei/Editor/View/CloudDBTab.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9c6ac8f9f635f214a91e7877fd7c157a +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs new file mode 100644 index 00000000..07151eea --- /dev/null +++ b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs @@ -0,0 +1,222 @@ +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEditor; +using UnityEngine; + +namespace HmsPlugin +{ + public class HMSCloudDBSettingsDrawer : VerticalSequenceDrawer + { + private TextField.TextField packageNameTextField; + private Label.Label jsonPathLabel; + + private Root rootJson; + + public HMSCloudDBSettingsDrawer() + { + packageNameTextField = new TextField.TextField("Java Package Name: ", "", OnPackageNameChanged); //TODO: reference wiki page to how to obtain java package name. + jsonPathLabel = new Label.Label(); + SetupSequence(); + } + + private void OnPackageNameChanged(string value) + { + + } + + private void OnJsonFileSelected() + { + string path = EditorUtility.OpenFilePanel("Choose a json File", "", "json"); + if (!string.IsNullOrEmpty(path)) + { + rootJson = JsonUtility.FromJson(File.ReadAllText(path)); + jsonPathLabel.SetText(Path.GetFileName(path)); + } + } + + private void SetupSequence() + { + AddDrawer(new HorizontalSequenceDrawer(new HorizontalLine(), new Label.Label("Creating C# Model").SetBold(true), new HorizontalLine())); + AddDrawer(new Space(3)); + AddDrawer(packageNameTextField); + AddDrawer(new Space(3)); + AddDrawer(new HorizontalSequenceDrawer(new Label.Label("Select Json File"), new Space(3), new Button.Button("Select", OnJsonFileSelected).SetWidth(100), jsonPathLabel)); + AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new Button.Button("Generate C# Models", OnGenerateButton).SetWidth(250), new Spacer())); + AddDrawer(new HorizontalLine()); + AddDrawer(new Space(5)); + } + + private void OnGenerateButton() + { + if (rootJson != null && !string.IsNullOrEmpty(packageNameTextField.GetCurrentText())) + { + foreach (var item in rootJson.objectTypes) + { + using (var file = File.CreateText(Application.dataPath + "/Huawei/Scripts/CloudDB/" + item.objectTypeName + ".cs")) + { + file.WriteLine("using HuaweiMobileServices.CloudDB;"); + file.WriteLine("using HuaweiMobileServices.Utils;"); + file.WriteLine("using UnityEngine;\n"); + file.WriteLine("using System;\n"); + file.WriteLine("namespace HmsPlugin\n{"); + file.WriteLine("\tpublic class " + item.objectTypeName + " : JavaObjectWrapper, ICloudDBZoneObject\n\t{"); + file.WriteLine("\t\tpublic " + item.objectTypeName + "() : base(\"" + packageNameTextField.GetCurrentText() + "\") { }"); + file.WriteLine("\t\tpublic " + item.objectTypeName + "(AndroidJavaObject javaObject) : base(javaObject) { }"); + foreach (var field in item.fields) + { + file.WriteLine("\t\tprivate " + GetFieldType(field.fieldType) + " " + field.fieldName + ";"); + } + file.WriteLine(""); + + foreach (var field in item.fields) + { + file.WriteLine(WriteProperty(field)); + } + + file.WriteLine("\t\tpublic AndroidJavaObject GetObj() => base.JavaObject;"); + file.WriteLine("\t\tpublic void SetObj(AndroidJavaObject arg0) => base.JavaObject = arg0;"); + file.WriteLine("\t}\n}"); + } + } + + AssetDatabase.Refresh(); + } + } + + private string WriteProperty(Field field) + { + StringBuilder builder = new StringBuilder(); + builder.AppendLine("\t\tpublic " + GetFieldType(field.fieldType) + " " + field.fieldName.ToPascalCase() + "\n\t\t{"); + switch (field.fieldType) + { + case "String": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", value); }"); + break; + case "Boolean": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", value); }"); + break; + case "Short": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"shortValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Short\", value)); }"); + break; + case "Byte": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"byteValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Byte\", value)); }"); + break; + case "Integer": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"intValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Integer\", value)); }"); + break; + case "Long": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"longValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Long\", value)); }"); + break; + case "Float": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"floatValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Float\", value)); }"); + break; + case "Double": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"doubleValue\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.lang.Double\", value)); }"); + break; + case "ByteArray": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", value); }"); + break; + case "Text": + builder.AppendLine("\t\t\tget { return Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"get\"); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"com.huawei.agconnect.cloud.database.Text\", value)); }"); + break; + case "Date": + builder.AppendLine("\t\t\tget { return new DateTime(Call(\"get" + field.fieldName.ToPascalCase() + "\").Call(\"getTime\")); }"); + builder.AppendLine("\t\t\tset { Call(\"set" + field.fieldName.ToPascalCase() + "\", new AndroidJavaObject(\"java.util.Date\", value.Ticks)); }"); + break; + default: + break; + } + builder.AppendLine("\t\t}"); + return builder.ToString(); + } + + private string GetFieldType(string fieldType) + { + switch (fieldType) + { + case "String": + return "string"; + case "Boolean": + return "bool"; + case "Short": + return "short"; + case "Byte": + return "byte"; + case "Integer": + return "int"; + case "Long": + return "long"; + case "Float": + return "float"; + case "Double": + return "double"; + case "ByteArray": + return "byte[]"; + case "Text": + return "string"; + case "Date": + return "DateTime"; + default: + break; + } + return ""; + } + + [System.Serializable] + private class Permission + { + public string role; + public List rights; + } + [System.Serializable] + private class Index + { + public string indexName; + public List indexList; + } + [System.Serializable] + private class Field + { + public bool isNeedEncrypt; + public string fieldName; + public bool notNull; + public bool belongPrimaryKey; + public string fieldType; + public string defaultValue; + } + [System.Serializable] + private class ObjectType + { + public List indexes; + public string objectTypeName; + public List fields; + } + [System.Serializable] + private class Root + { + public int schemaVersion; + public List permissions; + public List objectTypes; + } + [System.Serializable] + private class PermissionRoot + { + public List permissions; + public string objectTypeName; + } + } +} diff --git a/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs.meta b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs.meta new file mode 100644 index 00000000..12051735 --- /dev/null +++ b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBSettingsDrawer.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f605df43949110b4a8d6a4c85d2f02d4 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs new file mode 100644 index 00000000..f1a41f5f --- /dev/null +++ b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HmsPlugin +{ + public class HMSCloudDBTabFactory + { + public static TabView CreateTab(string title) + { + var tabView = new TabView(title); + tabView.AddDrawer(new HMSCloudDBSettingsDrawer()); + + return tabView; + } + } +} diff --git a/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs.meta b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs.meta new file mode 100644 index 00000000..6d585933 --- /dev/null +++ b/Assets/Huawei/Editor/View/CloudDBTab/HMSCloudDBTabFactory.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0dcd03fdb0f208c47a4736d28ffa8813 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Huawei/Editor/View/MainWindow/AccountToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/AccountToggleEditor.cs index 601ec082..727c4590 100644 --- a/Assets/Huawei/Editor/View/MainWindow/AccountToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/AccountToggleEditor.cs @@ -6,7 +6,7 @@ namespace HmsPlugin { - public class AccountToggleEditor : IDrawer, IDependentToggle + public class AccountToggleEditor : ToggleEditor, IDrawer, IDependentToggle { private Toggle.Toggle _toggle; @@ -22,7 +22,7 @@ private void OnStateChanged(bool value) { if (value) { - CreateManagerObject(); + CreateManagers(); } else { @@ -33,14 +33,7 @@ private void OnStateChanged(bool value) return; } - var accountManagers = GameObject.FindObjectsOfType(); - if (accountManagers.Length > 0) - { - for (int i = 0; i < accountManagers.Length; i++) - { - GameObject.DestroyImmediate(accountManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(AccountKitEnabled, value); } @@ -54,10 +47,10 @@ public void SetToggle() { _toggle.SetChecked(true); HMSMainEditorSettings.Instance.Settings.SetBool(AccountKitEnabled, true); - CreateManagerObject(); + CreateManagers(); } - private void CreateManagerObject() + public override void CreateManagers() { if (GameObject.FindObjectOfType() == null) { @@ -65,6 +58,20 @@ private void CreateManagerObject() obj.AddComponent(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } + Enabled = true; + } + + public override void DestroyManagers() + { + var accountManagers = GameObject.FindObjectsOfType(); + if (accountManagers.Length > 0) + { + for (int i = 0; i < accountManagers.Length; i++) + { + GameObject.DestroyImmediate(accountManagers[i].gameObject); + } + } + Enabled = false; } } } \ No newline at end of file diff --git a/Assets/Huawei/Editor/View/MainWindow/AdsToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/AdsToggleEditor.cs index 60e40206..5cb12b9d 100644 --- a/Assets/Huawei/Editor/View/MainWindow/AdsToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/AdsToggleEditor.cs @@ -6,7 +6,7 @@ namespace HmsPlugin { - public class AdsToggleEditor : IDrawer + public class AdsToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; private TabBar _tabBar; @@ -27,24 +27,12 @@ private void OnStateChanged(bool value) if (value) { _tabBar.AddTab(_tabView); - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSAdsKitManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); } else { - var adsKitManagers = GameObject.FindObjectsOfType(); - if (adsKitManagers.Length > 0) - { - for (int i = 0; i < adsKitManagers.Length; i++) - { - GameObject.DestroyImmediate(adsKitManagers[i].gameObject); - } - } _tabBar.RemoveTab(_tabView); + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(AdsKitEnabled, value); } @@ -53,5 +41,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSAdsKitManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var adsKitManagers = GameObject.FindObjectsOfType(); + if (adsKitManagers.Length > 0) + { + for (int i = 0; i < adsKitManagers.Length; i++) + { + GameObject.DestroyImmediate(adsKitManagers[i].gameObject); + } + } + Enabled = false; + } } } \ No newline at end of file diff --git a/Assets/Huawei/Editor/View/MainWindow/AnalyticsToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/AnalyticsToggleEditor.cs index 34b4bd62..df7df44a 100644 --- a/Assets/Huawei/Editor/View/MainWindow/AnalyticsToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/AnalyticsToggleEditor.cs @@ -6,7 +6,7 @@ namespace HmsPlugin { - public class AnalyticsToggleEditor : IDrawer, IDependentToggle + public class AnalyticsToggleEditor : ToggleEditor, IDrawer, IDependentToggle { private Toggle.Toggle _toggle; @@ -22,7 +22,7 @@ private void OnStateChanged(bool value) { if (value) { - CreateManagerObject(); + CreateManagers(); } else { @@ -40,20 +40,25 @@ private void OnStateChanged(bool value) return; } - var analyticManagers = GameObject.FindObjectsOfType(); - if (analyticManagers.Length > 0) - { - for (int i = 0; i < analyticManagers.Length; i++) - { - GameObject.DestroyImmediate(analyticManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(AnalyticsKitEnabled, value); } - private void CreateManagerObject() + public void Draw() + { + _toggle.Draw(); + } + + public void SetToggle() + { + _toggle.SetChecked(true); + HMSMainEditorSettings.Instance.Settings.SetBool(AnalyticsKitEnabled, true); + CreateManagers(); + } + + public override void CreateManagers() { if (GameObject.FindObjectOfType() == null) { @@ -61,18 +66,20 @@ private void CreateManagerObject() obj.AddComponent(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } + Enabled = true; } - public void Draw() - { - _toggle.Draw(); - } - - public void SetToggle() + public override void DestroyManagers() { - _toggle.SetChecked(true); - HMSMainEditorSettings.Instance.Settings.SetBool(AnalyticsKitEnabled, true); - CreateManagerObject(); + var analyticManagers = GameObject.FindObjectsOfType(); + if (analyticManagers.Length > 0) + { + for (int i = 0; i < analyticManagers.Length; i++) + { + GameObject.DestroyImmediate(analyticManagers[i].gameObject); + } + } + Enabled = false; } } diff --git a/Assets/Huawei/Editor/View/MainWindow/AppMessagingToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/AppMessagingToggleEditor.cs index 04679a13..e1a9f871 100644 --- a/Assets/Huawei/Editor/View/MainWindow/AppMessagingToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/AppMessagingToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class AppMessagingToggleEditor : IDrawer + public class AppMessagingToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; @@ -24,23 +24,11 @@ private void OnStateChanged(bool value) { if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSAppMessagingManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); } else { - var appMessagingManagers = GameObject.FindObjectsOfType(); - if (appMessagingManagers.Length > 0) - { - for (int i = 0; i < appMessagingManagers.Length; i++) - { - GameObject.DestroyImmediate(appMessagingManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(AppMessagingEnabled, value); } @@ -49,5 +37,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSAppMessagingManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var appMessagingManagers = GameObject.FindObjectsOfType(); + if (appMessagingManagers.Length > 0) + { + for (int i = 0; i < appMessagingManagers.Length; i++) + { + GameObject.DestroyImmediate(appMessagingManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/AuthToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/AuthToggleEditor.cs index d8046606..4b439370 100644 --- a/Assets/Huawei/Editor/View/MainWindow/AuthToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/AuthToggleEditor.cs @@ -9,7 +9,7 @@ namespace HmsPlugin { - internal class AuthToggleEditor : IDrawer, IDependentToggle + internal class AuthToggleEditor : ToggleEditor, IDrawer, IDependentToggle { private Toggle.Toggle _toggle; @@ -25,7 +25,7 @@ private void OnStateChanged(bool value) { if (value) { - CreateManagerObject(); + CreateManagers(); } else { @@ -35,19 +35,24 @@ private void OnStateChanged(bool value) _toggle.SetChecked(true); return; } - var authManagers = GameObject.FindObjectsOfType(); - if (authManagers.Length > 0) - { - for (int i = 0; i < authManagers.Length; i++) - { - GameObject.DestroyImmediate(authManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(AuthEnabled, value); } - private void CreateManagerObject() + public void Draw() + { + _toggle.Draw(); + } + + public void SetToggle() + { + _toggle.SetChecked(true); + HMSMainEditorSettings.Instance.Settings.SetBool(AuthEnabled, true); + CreateManagers(); + } + + public override void CreateManagers() { if (GameObject.FindObjectOfType() == null) { @@ -55,18 +60,20 @@ private void CreateManagerObject() obj.AddComponent(); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); } + Enabled = true; } - public void Draw() - { - _toggle.Draw(); - } - - public void SetToggle() + public override void DestroyManagers() { - _toggle.SetChecked(true); - HMSMainEditorSettings.Instance.Settings.SetBool(AuthEnabled, true); - CreateManagerObject(); + var authManagers = GameObject.FindObjectsOfType(); + if (authManagers.Length > 0) + { + for (int i = 0; i < authManagers.Length; i++) + { + GameObject.DestroyImmediate(authManagers[i].gameObject); + } + } + Enabled = false; } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/CloudDBToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/CloudDBToggleEditor.cs index 35b2d723..bb0f1630 100644 --- a/Assets/Huawei/Editor/View/MainWindow/CloudDBToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/CloudDBToggleEditor.cs @@ -8,16 +8,21 @@ namespace HmsPlugin { - public class CloudDBToggleEditor : IDrawer + public class CloudDBToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; + private TabBar _tabBar; + private TabView _tabView; private IDependentToggle _dependentToggle; public const string CloudDBEnabled = "CloudDB"; - public CloudDBToggleEditor(IDependentToggle dependentToggle) + public CloudDBToggleEditor(TabBar tabBar, IDependentToggle dependentToggle) { _dependentToggle = dependentToggle; + _tabView = HMSCloudDBTabFactory.CreateTab("Cloud DB"); + _tabBar = tabBar; + bool enabled = HMSMainEditorSettings.Instance.Settings.GetBool(CloudDBEnabled); _toggle = new Toggle.Toggle("Cloud DB*", enabled, OnStateChanged, true).SetTooltip("CloudDB is dependent on Auth Service."); } @@ -26,24 +31,14 @@ private void OnStateChanged(bool value) { if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSCloudDBManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); _dependentToggle.SetToggle(); + _tabBar.AddTab(_tabView); } else { - var cloudDBManagers = GameObject.FindObjectsOfType(); - if (cloudDBManagers.Length > 0) - { - for (int i = 0; i < cloudDBManagers.Length; i++) - { - GameObject.DestroyImmediate(cloudDBManagers[i].gameObject); - } - } + DestroyManagers(); + _tabBar.RemoveTab(_tabView); } HMSMainEditorSettings.Instance.Settings.SetBool(CloudDBEnabled, value); } @@ -52,5 +47,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSCloudDBManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var cloudDBManagers = GameObject.FindObjectsOfType(); + if (cloudDBManagers.Length > 0) + { + for (int i = 0; i < cloudDBManagers.Length; i++) + { + GameObject.DestroyImmediate(cloudDBManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/CrashToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/CrashToggleEditor.cs index 25f88f77..5fa92dbc 100644 --- a/Assets/Huawei/Editor/View/MainWindow/CrashToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/CrashToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class CrashToggleEditor : IDrawer + public class CrashToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; private IDependentToggle _dependentToggle; @@ -26,24 +26,12 @@ private void OnStateChanged(bool value) { if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSCrashManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); _dependentToggle.SetToggle(); } else { - var crashManagers = GameObject.FindObjectsOfType(); - if (crashManagers.Length > 0) - { - for (int i = 0; i < crashManagers.Length; i++) - { - GameObject.DestroyImmediate(crashManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(CrashKitEnabled, value); } @@ -52,5 +40,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSCrashManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var crashManagers = GameObject.FindObjectsOfType(); + if (crashManagers.Length > 0) + { + for (int i = 0; i < crashManagers.Length; i++) + { + GameObject.DestroyImmediate(crashManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/DriveKitToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/DriveKitToggleEditor.cs index df8ac630..b57afb27 100644 --- a/Assets/Huawei/Editor/View/MainWindow/DriveKitToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/DriveKitToggleEditor.cs @@ -6,7 +6,7 @@ namespace HmsPlugin { - public class DriveKitToggleEditor : IDrawer + public class DriveKitToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; @@ -48,5 +48,15 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + //throw new NotImplementedException(); + } + + public override void DestroyManagers() + { + //throw new NotImplementedException(); + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/GameServiceToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/GameServiceToggleEditor.cs index bf857be1..8cbb7e1e 100644 --- a/Assets/Huawei/Editor/View/MainWindow/GameServiceToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/GameServiceToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class GameServiceToggleEditor : IDrawer + public class GameServiceToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; private TabBar _tabBar; @@ -31,27 +31,12 @@ private void OnStateChanged(bool value) if (value) { _tabBar.AddTab(_tabView); - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSGameManager"); - obj.AddComponent(); - obj.AddComponent(); - obj.AddComponent(); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); _dependentToggle.SetToggle(); } else { - var gameKitManagers = GameObject.FindObjectsOfType(); - if (gameKitManagers.Length > 0) - { - for (int i = 0; i < gameKitManagers.Length; i++) - { - GameObject.DestroyImmediate(gameKitManagers[i].gameObject); - } - } + DestroyManagers(); _tabBar.RemoveTab(_tabView); } HMSMainEditorSettings.Instance.Settings.SetBool(GameServiceEnabled, value); @@ -61,5 +46,32 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSGameManager"); + obj.AddComponent(); + obj.AddComponent(); + obj.AddComponent(); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var gameKitManagers = GameObject.FindObjectsOfType(); + if (gameKitManagers.Length > 0) + { + for (int i = 0; i < gameKitManagers.Length; i++) + { + GameObject.DestroyImmediate(gameKitManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/HMSMainKitsTabFactory.cs b/Assets/Huawei/Editor/View/MainWindow/HMSMainKitsTabFactory.cs index d5ccc47e..63c50066 100644 --- a/Assets/Huawei/Editor/View/MainWindow/HMSMainKitsTabFactory.cs +++ b/Assets/Huawei/Editor/View/MainWindow/HMSMainKitsTabFactory.cs @@ -15,39 +15,73 @@ internal class HMSMainKitsTabFactory { private static string versionInfo = ""; + + private static List toggleEditors; + static HMSMainKitsTabFactory() { versionInfo = File.ReadAllText(Application.dataPath + "/Huawei/VERSION"); + toggleEditors = new List(); } public static TabView CreateTab(TabBar tabBar) { + toggleEditors.Clear(); var tab = new TabView("Kits"); tabBar.AddTab(tab); + var adsToggleEditor = new AdsToggleEditor(tabBar); + var accountEditor = new AccountToggleEditor(); + var gameServiceToggleEditor = new GameServiceToggleEditor(tabBar, accountEditor); + var pushToggleEditor = new PushToggleEditor(); var analyticsEditor = new AnalyticsToggleEditor(); var authEditor = new AuthToggleEditor(); - var accountEditor = new AccountToggleEditor(); + var iapToggleEditor = new IAPToggleEditor(tabBar); + var remoteConfigToggleEditor = new RemoteConfigToggleEditor(tabBar, analyticsEditor); + var crashToggleEditor = new CrashToggleEditor(analyticsEditor); + var cloudDBToggleEditor = new CloudDBToggleEditor(tabBar, authEditor); + var driveToggleEditor = new DriveKitToggleEditor(); + var nearbyServiceToggleEditor = new NearbyServiceToggleEditor(); + var appMessagingToggleEditor = new AppMessagingToggleEditor(); tab.AddDrawer(new HorizontalLine()); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new AdsToggleEditor(tabBar), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new GameServiceToggleEditor(tabBar, accountEditor), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new PushToggleEditor(), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new IAPToggleEditor(tabBar), new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), adsToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), gameServiceToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), pushToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), iapToggleEditor, new Spacer())); tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), accountEditor, new Spacer())); tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), analyticsEditor, new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new RemoteConfigToggleEditor(tabBar, analyticsEditor), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new CrashToggleEditor(analyticsEditor), new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), remoteConfigToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), crashToggleEditor, new Spacer())); tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), authEditor, new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new CloudDBToggleEditor(authEditor), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new DriveKitToggleEditor(), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new NearbyServiceToggleEditor(), new Spacer())); - tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), new AppMessagingToggleEditor(), new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), cloudDBToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), driveToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), nearbyServiceToggleEditor, new Spacer())); + tab.AddDrawer(new HorizontalSequenceDrawer(new Spacer(), appMessagingToggleEditor, new Spacer())); tab.AddDrawer(new HorizontalLine()); tab.AddDrawer(new Spacer()); - tab.AddDrawer(new Clickable(new Label("HMS Unity Plugin v" + versionInfo).SetBold(true), () => { Application.OpenURL("https://github.com/EvilMindDevs/hms-unity-plugin/tree/2.0"); })); + tab.AddDrawer(new Clickable(new Label("HMS Unity Plugin v" + versionInfo).SetBold(true), () => { Application.OpenURL("https://github.com/EvilMindDevs/hms-unity-plugin/"); })); tab.AddDrawer(new HelpboxAGConnectFile()); + toggleEditors.Add(adsToggleEditor); + toggleEditors.Add(accountEditor); + toggleEditors.Add(gameServiceToggleEditor); + toggleEditors.Add(pushToggleEditor); + toggleEditors.Add(analyticsEditor); + toggleEditors.Add(authEditor); + toggleEditors.Add(iapToggleEditor); + toggleEditors.Add(remoteConfigToggleEditor); + toggleEditors.Add(crashToggleEditor); + toggleEditors.Add(cloudDBToggleEditor); + toggleEditors.Add(driveToggleEditor); + toggleEditors.Add(nearbyServiceToggleEditor); + toggleEditors.Add(appMessagingToggleEditor); + return tab; } + + public static List GetEnabledEditors() + { + return toggleEditors.FindAll(c => c.Enabled); + } } \ No newline at end of file diff --git a/Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs b/Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs index c8a89a89..cdc79d7b 100644 --- a/Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs +++ b/Assets/Huawei/Editor/View/MainWindow/HMSMainWindow.cs @@ -1,8 +1,5 @@  using HmsPlugin; -using HmsPlugin.HelpBox; -using HmsPlugin.Label; -using HmsPlugin.TextField; using HmsPlugin.Window; using UnityEditor; @@ -20,7 +17,6 @@ public static void CheckForUpdates() HMSPluginUpdater.Request(true); } - public override IDrawer CreateDrawer() { var tabBar = new TabBar(); diff --git a/Assets/Huawei/Editor/View/MainWindow/IAPToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/IAPToggleEditor.cs index 891cf698..8a8b8b91 100644 --- a/Assets/Huawei/Editor/View/MainWindow/IAPToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/IAPToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class IAPToggleEditor : IDrawer + public class IAPToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; private TabBar _tabBar; @@ -29,23 +29,11 @@ private void OnStateChanged(bool value) if (value) { _tabBar.AddTab(_tabView); - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSIAPManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); } else { - var iapManagers = GameObject.FindObjectsOfType(); - if (iapManagers.Length > 0) - { - for (int i = 0; i < iapManagers.Length; i++) - { - GameObject.DestroyImmediate(iapManagers[i].gameObject); - } - } + DestroyManagers(); _tabBar.RemoveTab(_tabView); } HMSMainEditorSettings.Instance.Settings.SetBool(IAPKitEnabled, value); @@ -55,5 +43,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSIAPManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var iapManagers = GameObject.FindObjectsOfType(); + if (iapManagers.Length > 0) + { + for (int i = 0; i < iapManagers.Length; i++) + { + GameObject.DestroyImmediate(iapManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/NearbyServiceToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/NearbyServiceToggleEditor.cs index 363f9c8f..230b12b3 100644 --- a/Assets/Huawei/Editor/View/MainWindow/NearbyServiceToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/NearbyServiceToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class NearbyServiceToggleEditor : IDrawer + public class NearbyServiceToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; @@ -24,23 +24,11 @@ private void OnStateChanged(bool value) { if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSNearbyServiceManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); } else { - var nearbyServiceManagers = GameObject.FindObjectsOfType(); - if (nearbyServiceManagers.Length > 0) - { - for (int i = 0; i < nearbyServiceManagers.Length; i++) - { - GameObject.DestroyImmediate(nearbyServiceManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(NearbyServiceEnabled, value); } @@ -49,5 +37,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSNearbyServiceManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var nearbyServiceManagers = GameObject.FindObjectsOfType(); + if (nearbyServiceManagers.Length > 0) + { + for (int i = 0; i < nearbyServiceManagers.Length; i++) + { + GameObject.DestroyImmediate(nearbyServiceManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/PushToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/PushToggleEditor.cs index 12fff2fa..4c86a5fd 100644 --- a/Assets/Huawei/Editor/View/MainWindow/PushToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/PushToggleEditor.cs @@ -6,7 +6,7 @@ namespace HmsPlugin { - public class PushToggleEditor : IDrawer + public class PushToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; @@ -20,25 +20,13 @@ public PushToggleEditor() private void OnStateChanged(bool value) { - if(value) + if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSPushKitManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); } else { - var pushManagers = GameObject.FindObjectsOfType(); - if (pushManagers.Length > 0) - { - for (int i = 0; i < pushManagers.Length; i++) - { - GameObject.DestroyImmediate(pushManagers[i].gameObject); - } - } + DestroyManagers(); } HMSMainEditorSettings.Instance.Settings.SetBool(PushKitEnabled, value); } @@ -47,5 +35,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSPushKitManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var pushManagers = GameObject.FindObjectsOfType(); + if (pushManagers.Length > 0) + { + for (int i = 0; i < pushManagers.Length; i++) + { + GameObject.DestroyImmediate(pushManagers[i].gameObject); + } + } + Enabled = false; + } } } \ No newline at end of file diff --git a/Assets/Huawei/Editor/View/MainWindow/RemoteConfigToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/RemoteConfigToggleEditor.cs index 30ec4b6d..509239eb 100644 --- a/Assets/Huawei/Editor/View/MainWindow/RemoteConfigToggleEditor.cs +++ b/Assets/Huawei/Editor/View/MainWindow/RemoteConfigToggleEditor.cs @@ -8,7 +8,7 @@ namespace HmsPlugin { - public class RemoteConfigToggleEditor : IDrawer + public class RemoteConfigToggleEditor : ToggleEditor, IDrawer { private Toggle.Toggle _toggle; private TabBar _tabBar; @@ -31,25 +31,13 @@ private void OnStateChanged(bool value) HMSMainEditorSettings.Instance.Settings.SetBool(RemoteConfigEnabled, value); if (value) { - if (GameObject.FindObjectOfType() == null) - { - GameObject obj = new GameObject("HMSRemoteConfigManager"); - obj.AddComponent(); - EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); - } + CreateManagers(); _dependentToggle.SetToggle(); _tabBar.AddTab(_tabView); } else { - var remoteConfigManagers = GameObject.FindObjectsOfType(); - if (remoteConfigManagers.Length > 0) - { - for (int i = 0; i < remoteConfigManagers.Length; i++) - { - GameObject.DestroyImmediate(remoteConfigManagers[i].gameObject); - } - } + DestroyManagers(); _tabBar.RemoveTab(_tabView); } } @@ -58,5 +46,29 @@ public void Draw() { _toggle.Draw(); } + + public override void CreateManagers() + { + if (GameObject.FindObjectOfType() == null) + { + GameObject obj = new GameObject("HMSRemoteConfigManager"); + obj.AddComponent(); + EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); + } + Enabled = true; + } + + public override void DestroyManagers() + { + var remoteConfigManagers = GameObject.FindObjectsOfType(); + if (remoteConfigManagers.Length > 0) + { + for (int i = 0; i < remoteConfigManagers.Length; i++) + { + GameObject.DestroyImmediate(remoteConfigManagers[i].gameObject); + } + } + Enabled = false; + } } } diff --git a/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs b/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs new file mode 100644 index 00000000..c6c8b9bf --- /dev/null +++ b/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace HmsPlugin +{ + public abstract class ToggleEditor + { + public bool Enabled { get; set; } + public abstract void CreateManagers(); + public abstract void DestroyManagers(); + } +} diff --git a/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs.meta b/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs.meta new file mode 100644 index 00000000..312c19e8 --- /dev/null +++ b/Assets/Huawei/Editor/View/MainWindow/ToggleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 03e7bb15123052940841fc34eebeec45 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Huawei/Scripts/Account/HMSAccountManager.cs b/Assets/Huawei/Scripts/Account/HMSAccountManager.cs index 14b683f6..5a8ad792 100644 --- a/Assets/Huawei/Scripts/Account/HMSAccountManager.cs +++ b/Assets/Huawei/Scripts/Account/HMSAccountManager.cs @@ -84,6 +84,7 @@ public void SignIn() }, (error) => { HuaweiId = null; + Debug.LogError("[HMSAccountManager]: Sign in failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSignInFailed?.Invoke(error); }); } @@ -98,6 +99,7 @@ public void SignInDrive() }, (error) => { HuaweiId = null; + Debug.LogError("[HMSAccountManager]: Sign in Drive failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSignInFailed?.Invoke(error); }); } @@ -112,6 +114,7 @@ public void SilentSignIn() }).AddOnFailureListener((exception) => { HuaweiId = null; + Debug.LogError("[HMSAccountManager]: Silent Sign in failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnSignInFailed?.Invoke(exception); }); } @@ -129,6 +132,7 @@ public void CancelAuthorization() Debug.Log("[HMS]: CancelAuthorization onSuccess "); }).AddOnFailureListener((exception) => { + Debug.LogError("[HMSAccountManager]: Cancel Authorization failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnSignInFailed?.Invoke(exception); }); } diff --git a/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs b/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs index e0277909..869996e9 100644 --- a/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs +++ b/Assets/Huawei/Scripts/Ads/HMSAdsKitManager.cs @@ -285,6 +285,16 @@ public void ShowRewardedAd() } } + public bool IsRewardedAdLoaded + { + get + { + if (rewardedView == null) + return false; + return rewardedView.Loaded; + } + } + #endregion #region LISTENERS diff --git a/Assets/Huawei/Scripts/AuthService/HMSAuthServiceManager.cs b/Assets/Huawei/Scripts/AuthService/HMSAuthServiceManager.cs index 6e92e908..16284497 100644 --- a/Assets/Huawei/Scripts/AuthService/HMSAuthServiceManager.cs +++ b/Assets/Huawei/Scripts/AuthService/HMSAuthServiceManager.cs @@ -38,6 +38,7 @@ public void SignIn(AGConnectAuthCredential paramAGConnectAuthCredential) }) .AddOnFailureListener((error) => { + Debug.LogError("[HMSAuthServiceManager]: Sign in failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSignInFailed?.Invoke(error); }); } @@ -52,6 +53,7 @@ public void SignInAnonymously() }) .AddOnFailureListener((error) => { + Debug.LogError("[HMSAuthServiceManager]: Sign in Anonymously failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSignInFailed?.Invoke(error); }); } @@ -82,6 +84,7 @@ public void CreateUser(EmailUser emailUser) OnCreateUserSuccess?.Invoke(signInResult); }) .AddOnFailureListener(error => { + Debug.LogError("[HMSAuthServiceManager]: Create User failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnCreateUserFailed?.Invoke(error); }); } @@ -95,6 +98,7 @@ public void CreateUser(PhoneUser phoneUser) OnCreateUserSuccess?.Invoke(signInResult); }) .AddOnFailureListener(error => { + Debug.LogError("[HMSAuthServiceManager]: Create User failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnCreateUserFailed?.Invoke(error); }); } @@ -107,7 +111,8 @@ public void ResetPassword(string email, string newPassword, string verifyCode) OnResetPasswordSuccess?.Invoke(true); }) .AddOnFailureListener(error => { - OnSignInFailed?.Invoke(error); + Debug.LogError("[HMSAuthServiceManager]: Reset Password failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); + OnResetPasswordFailed?.Invoke(error); }); } @@ -119,7 +124,8 @@ public void ResetPassword(string countryCode, string phoneNumber, string newPass OnResetPasswordSuccess?.Invoke(true); }) .AddOnFailureListener(error => { - OnSignInFailed?.Invoke(error); + Debug.LogError("[HMSAuthServiceManager]: Reset Password failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); + OnResetPasswordFailed?.Invoke(error); }); } } diff --git a/Assets/Huawei/Scripts/CloudDB/BookInfo.cs b/Assets/Huawei/Scripts/CloudDB/BookInfo.cs index 4cf50b33..d24a3e27 100644 --- a/Assets/Huawei/Scripts/CloudDB/BookInfo.cs +++ b/Assets/Huawei/Scripts/CloudDB/BookInfo.cs @@ -1,45 +1,44 @@ -using HuaweiMobileServices.CloudDB; +using HuaweiMobileServices.CloudDB; using HuaweiMobileServices.Utils; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; using UnityEngine; +using System; + namespace HmsPlugin { - public class BookInfo : JavaObjectWrapper, ICloudDBZoneObject + public class BookInfo : JavaObjectWrapper, ICloudDBZoneObject { - public BookInfo() : base("com.clouddbdemo.kb.huawei.BookInfo") { } + public BookInfo() : base("selam") { } public BookInfo(AndroidJavaObject javaObject) : base(javaObject) { } - - private int _id; - private string _bookName; - private string _author; - private double _price; - private string _publisher; - private Date _publishTime; - private bool _shadowFlag = true; + private int id; + private string bookName; + private string author; + private double price; + private string publisher; + private DateTime publishTime; + private bool shadowFlag; public int Id { get { return Call("getId").Call("intValue"); } set { Call("setId", new AndroidJavaObject("java.lang.Integer", value)); } } + public string BookName { get { return Call("getBookName"); } set { Call("setBookName", value); } } + public string Author { get { return Call("getAuthor"); } set { Call("setAuthor", value); } } + public double Price { - get { return Call("getPrice").Call("doubleValue"); } + get { return Call("getPrice").Call("doubleValue"); } set { Call("setPrice", new AndroidJavaObject("java.lang.Double", value)); } } @@ -49,10 +48,10 @@ public string Publisher set { Call("setPublisher", value); } } - public Date PublishTime + public DateTime PublishTime { - get { return Call("getPublishTime"); } - set { Call("setPublishTime", value); } + get { return new DateTime(Call("getPublishTime").Call("getTime")); } + set { Call("setPublishTime", new AndroidJavaObject("java.util.Date", value.Ticks)); } } public bool ShadowFlag @@ -61,8 +60,7 @@ public bool ShadowFlag set { Call("setShadowFlag", value); } } - public AndroidJavaObject GetObj() => base.JavaObject; - public void SetObj(AndroidJavaObject arg0) => base.JavaObject = arg0; - - } + public AndroidJavaObject GetObj() => base.JavaObject; + public void SetObj(AndroidJavaObject arg0) => base.JavaObject = arg0; + } } diff --git a/Assets/Huawei/Scripts/CloudDB/HMSCloudDBManager.cs b/Assets/Huawei/Scripts/CloudDB/HMSCloudDBManager.cs index 3edfd091..f4b28cda 100644 --- a/Assets/Huawei/Scripts/CloudDB/HMSCloudDBManager.cs +++ b/Assets/Huawei/Scripts/CloudDB/HMSCloudDBManager.cs @@ -8,10 +8,11 @@ namespace HmsPlugin { public class HMSCloudDBManager : HMSSingleton { - string TAG = "CloudDB Manager"; + string TAG = "HMSCloudDBManager"; AGConnectCloudDB mCloudDB = null; CloudDBZoneConfig mConfig = null; CloudDBZone mCloudDBZone = null; + ListenerHandler mRegister = null; public Action OnOpenCloudDBZone2Success { get; set; } public Action OnOpenCloudDBZone2Failed { get; set; } @@ -43,6 +44,9 @@ public class HMSCloudDBManager : HMSSingleton public Action> OnExecuteQueryUnsyncedSuccess { get; set; } public Action OnExecuteQueryUnsyncedFailed { get; set; } + public Action> OnCloudDBZoneSnapshot { get; set; } + public Action OnCloudDBZoneSnapshotException { get; set; } + public void Initialize() { AGConnectCloudDB.Initialize(); @@ -78,7 +82,7 @@ public void OpenCloudDBZone(string CloudDBZoneName, CloudDBZoneConfig.CloudDBZon } catch (Exception e) { - Debug.Log($"[{TAG}]: CloudDBZoneConfig() exception " + e.Message); + Debug.LogError($"[{TAG}]: CloudDBZoneConfig() exception " + e.Message); } Debug.Log($"[{TAG}]: OpenCloudDBZone"); @@ -390,16 +394,17 @@ public void ExecuteQueryUnsynced(CloudDBZoneQuery query) }); } - public void SubscribeSnapshot(CloudDBZoneQuery cloudDBZoneQuery, CloudDBZoneQuery.CloudDBZoneQueryPolicy cloudDBZoneQueryPolicy, OnSnapshotListener listener) + public void SubscribeSnapshot(CloudDBZoneQuery cloudDBZoneQuery, CloudDBZoneQuery.CloudDBZoneQueryPolicy cloudDBZoneQueryPolicy) { if (mCloudDBZone == null) { - Debug.Log($"[{TAG}]: CloudDBZone is null, try re-open it"); + Debug.LogError($"[{TAG}]: CloudDBZone is null, try re-open it"); return; } - mCloudDBZone.SubscribeSnapshot(cloudDBZoneQuery, cloudDBZoneQueryPolicy, listener); + + mRegister = mCloudDBZone.SubscribeSnapshot(cloudDBZoneQuery, cloudDBZoneQueryPolicy, OnCloudDBZoneSnapshot, OnCloudDBZoneSnapshotException); + Debug.Log($"[{TAG}]: SubscribeSnaphot()"); } - } } \ No newline at end of file diff --git a/Assets/Huawei/Scripts/Game/HMSAchievementsManager.cs b/Assets/Huawei/Scripts/Game/HMSAchievementsManager.cs index 5c107829..3ff70367 100644 --- a/Assets/Huawei/Scripts/Game/HMSAchievementsManager.cs +++ b/Assets/Huawei/Scripts/Game/HMSAchievementsManager.cs @@ -40,7 +40,7 @@ public void ShowAchievements() OnShowAchievementsSuccess?.Invoke(); }, (exception) => { - Debug.Log("[HMS GAMES:] ShowAchievements ERROR"); + Debug.LogError("[HMSAchievementsManager]: Show Achievements failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnShowAchievementsFailure?.Invoke(exception); }); } @@ -55,7 +55,7 @@ public void GetAchievementsList() OnGetAchievementsListSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] GetAchievementsList ERROR"); + Debug.LogError("[HMSAchievementsManager]: GetAchievementsList failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnGetAchievementsListFailure?.Invoke(exception); }); } @@ -71,7 +71,7 @@ public void RevealAchievement(string achievementId) }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] RevealAchievement ERROR"); + Debug.LogError("[HMSAchievementsManager]: RevealAchievement failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnRevealAchievementFailure?.Invoke(exception); }); } @@ -86,11 +86,16 @@ public void IncreaseStepAchievement(string achievementId, int stepIncrement) }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] IncreaseStepAchievement ERROR"); + Debug.LogError("[HMSAchievementsManager]: IncreaseStepAchievement failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnIncreaseStepAchievementFailure?.Invoke(exception); }); } + public void Grow(string achievementId, int stepIncrement) + { + achievementsClient.Grow(achievementId, stepIncrement); + } + public void SetStepAchievement(string achievementId, int stepsNum) { ITask task = achievementsClient.MakeStepsWithResult(achievementId, stepsNum); @@ -101,7 +106,7 @@ public void SetStepAchievement(string achievementId, int stepsNum) }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] SetStepAchievement ERROR"); + Debug.LogError("[HMSAchievementsManager]: SetStepAchievement failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnSetStepAchievementFailure?.Invoke(exception); }); } @@ -116,7 +121,7 @@ public void UnlockAchievement(string achievementId) }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] UnlockAchievements ERROR"); + Debug.LogError("[HMSAchievementsManager]: UnlockAchievement failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnUnlockAchievementFailure?.Invoke(exception); }); } diff --git a/Assets/Huawei/Scripts/Game/HMSGameManager.cs b/Assets/Huawei/Scripts/Game/HMSGameManager.cs index f09f4991..1ef1a6a2 100644 --- a/Assets/Huawei/Scripts/Game/HMSGameManager.cs +++ b/Assets/Huawei/Scripts/Game/HMSGameManager.cs @@ -11,10 +11,17 @@ public class HMSGameManager : HMSSingleton { public Action OnGetPlayerInfoSuccess { get; set; } public Action OnGetPlayerInfoFailure { get; set; } + public Action OnSubmitPlayerEventSuccess { get; set; } + public Action OnSubmitPlayerEventFailure { get; set; } + public Action OnGetPlayerExtraInfoSuccess { get; set; } + public Action OnGetPlayerExtraInfoFailure { get; set; } public Action SignInSuccess { get; set; } public Action SignInFailure { get; set; } private AccountAuthService authService; + private IBuoyClient buoyClient; + private IPlayersClient playersClient; + private IArchivesClient archivesClient; public void Start() { @@ -42,6 +49,7 @@ public void Init() }).AddOnFailureListener((exception) => { + Debug.Log("HMS GAMES: The app has not been authorized"); authService.StartSignIn(SignInSuccess, SignInFailure); InitGameManagers(); @@ -50,32 +58,75 @@ public void Init() public void InitGameManagers() { - //SavedGame Initilize HMSSaveGameManager.Instance.SavedGameAuth(); - HMSSaveGameManager.Instance.GetArchivesClient(); - //Leaderboard Initilize HMSLeaderboardManager.Instance.rankingsClient = Games.GetRankingsClient(); - //Achievements Initilize HMSAchievementsManager.Instance.achievementsClient = Games.GetAchievementsClient(); + + playersClient = Games.GetPlayersClient(); + archivesClient = Games.GetArchiveClient(); + buoyClient = Games.GetBuoyClient(); + } + + public void ShowFloatWindow() + { + buoyClient.ShowFloatWindow(); + } + + public void HideFloatWindow() + { + buoyClient.HideFloatWindow(); } public void GetPlayerInfo() { if (HMSAccountManager.Instance.HuaweiId != null) { - IPlayersClient playersClient = Games.GetPlayersClient(); ITask task = playersClient.CurrentPlayer; task.AddOnSuccessListener((result) => { - Debug.Log("[HMSP:] GetPlayerInfo Success"); + Debug.Log("[HMSGameManager] GetPlayerInfo Success"); OnGetPlayerInfoSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMSP:] GetPlayerInfo Failed"); + Debug.LogError("[HMSGameManager]: GetPlayerInfo failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnGetPlayerInfoFailure?.Invoke(exception); }); } } + + public void SubmitPlayerEvent(string playerId, string eventId, string eventType) + { + if (HMSAccountManager.Instance.HuaweiId != null) + { + var task = playersClient.SubmitPlayerEvent(playerId, eventId, eventType); + task.AddOnSuccessListener((result) => + { + Debug.Log("[HMSGameManager] SubmitPlayerEvent Success"); + OnSubmitPlayerEventSuccess?.Invoke(result); + }).AddOnFailureListener((exception) => + { + Debug.LogError("[HMSGameManager]: SubmitPlayerEvent failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); + OnSubmitPlayerEventFailure?.Invoke(exception); + }); + } + } + + public void GetPlayerExtraInfo(string transactionId) + { + if (HMSAccountManager.Instance.HuaweiId != null) + { + var task = playersClient.GetPlayerExtraInfo(transactionId); + task.AddOnSuccessListener((result) => + { + Debug.Log("[HMSGameManager] GetPlayerExtraInfo Success"); + OnGetPlayerExtraInfoSuccess?.Invoke(result); + }).AddOnFailureListener((exception) => + { + Debug.LogError("[HMSGameManager]: GetPlayerExtraInfo failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); + OnGetPlayerExtraInfoFailure?.Invoke(exception); + }); + } + } } } \ No newline at end of file diff --git a/Assets/Huawei/Scripts/Game/HMSLeaderboardManager.cs b/Assets/Huawei/Scripts/Game/HMSLeaderboardManager.cs index 6a741337..842bd7dd 100644 --- a/Assets/Huawei/Scripts/Game/HMSLeaderboardManager.cs +++ b/Assets/Huawei/Scripts/Game/HMSLeaderboardManager.cs @@ -38,12 +38,12 @@ public void IsUserScoreShownOnLeaderboards() ITask task = rankingsClient.GetRankingSwitchStatus(); task.AddOnSuccessListener((result) => { - Debug.Log("[HMS GAMES] isUserScoreShownOnLeaderboards SUCCESS" + result); + Debug.Log("[HMSLeaderboardManager] isUserScoreShownOnLeaderboards SUCCESS" + result); OnIsUserScoreShownOnLeaderboardsSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] isUserScoreShownOnLeaderboards ERROR"); + Debug.LogError("[HMSLeaderboardManager]: IsUserScoreShownOnLeaderboards failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnIsUserScoreShownOnLeaderboardsFailure?.Invoke(exception); }); @@ -54,12 +54,12 @@ public void SetUserScoreShownOnLeaderboards(int active) ITask task = rankingsClient.SetRankingSwitchStatus(active); task.AddOnSuccessListener((result) => { - Debug.Log("[HMS GAMES] SetUserScoreShownOnLeaderboards SUCCESS" + result); + Debug.Log("[HMSLeaderboardManager] SetUserScoreShownOnLeaderboards SUCCESS" + result); OnSetUserScoreShownOnLeaderboardsSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] SetUserScoreShownOnLeaderboards ERROR"); + Debug.LogError("[HMSLeaderboardManager]: SetUserScoreShownOnLeaderboards failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnSetUserScoreShownOnLeaderboardsFailure?.Invoke(exception); }); } @@ -69,9 +69,11 @@ public void SubmitScore(string leaderboardId, long score) ITask task = rankingsClient.SubmitScoreWithResult(leaderboardId, score); task.AddOnSuccessListener((scoreInfo) => { + Debug.Log("[HMSLeaderboardManager] SubmitScore SUCCESS"); OnSubmitScoreSuccess?.Invoke(scoreInfo); }).AddOnFailureListener((error) => { + Debug.LogError("[HMSLeaderboardManager]: SubmitScore failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSubmitScoreFailure?.Invoke(error); }); } @@ -81,9 +83,11 @@ public void SubmitScore(string leaderboardId, long score, string scoreTips) ITask task = rankingsClient.SubmitScoreWithResult(leaderboardId, score, scoreTips); task.AddOnSuccessListener((scoreInfo) => { + Debug.Log("[HMSLeaderboardManager] SubmitScore SUCCESS"); OnSubmitScoreSuccess?.Invoke(scoreInfo); }).AddOnFailureListener((error) => { + Debug.LogError("[HMSLeaderboardManager]: SubmitScore failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); OnSubmitScoreFailure?.Invoke(error); }); } @@ -92,12 +96,12 @@ public void ShowLeaderboards() { rankingsClient.ShowTotalRankings(() => { - Debug.Log("[HMS GAMES] ShowLeaderboards SUCCESS"); + Debug.Log("[HMSLeaderboardManager] ShowLeaderboards SUCCESS"); OnShowLeaderboardsSuccess?.Invoke(); }, (exception) => { - Debug.Log("[HMS GAMES] ShowLeaderboards ERROR"); + Debug.LogError("[HMSLeaderboardManager]: ShowLeaderboards failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnShowLeaderboardsFailure?.Invoke(exception); }); } @@ -107,11 +111,11 @@ public void GetLeaderboardsData() ITask> task = rankingsClient.GetRankingSummary(true); task.AddOnSuccessListener((result) => { - Debug.Log("[HMS GAMES] GetLeaderboardsData SUCCESS"); + Debug.Log("[HMSLeaderboardManager] GetLeaderboardsData SUCCESS"); OnGetLeaderboardsDataSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] GetLeaderboardsData ERROR"); + Debug.LogError("[HMSLeaderboardManager]: GetLeaderboardsData failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnGetLeaderboardsDataFailure?.Invoke(exception); }); } @@ -121,12 +125,12 @@ public void GetLeaderboardData(string leaderboardId) ITask task = rankingsClient.GetRankingSummary(leaderboardId, true); task.AddOnSuccessListener((result) => { - Debug.Log("[HMS GAMES] GetLeaderboardsData SUCCESS"); + Debug.Log("[HMSLeaderboardManager] GetLeaderboardsData SUCCESS"); OnGetLeaderboardDataSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] GetLeaderboardsData ERROR"); + Debug.LogError("[HMSLeaderboardManager]: GetLeaderboardData failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnGetLeaderboardDataFailure?.Invoke(exception); }); } @@ -139,12 +143,12 @@ public void GetScoresFromLeaderboard(string leaderboardId, int timeDimension, in task.AddOnSuccessListener((result) => { - Debug.Log("[HMS GAMES] GetScoresFromLeaderboard SUCCESS"); + Debug.Log("[HMSLeaderboardManager] GetScoresFromLeaderboard SUCCESS"); OnGetScoresFromLeaderboardSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("[HMS GAMES] GetScoresFromLeaderboard ERROR"); + Debug.LogError("[HMSLeaderboardManager]: GetScoresFromLeaderboard failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnGetScoresFromLeaderboardFailure?.Invoke(exception); }); } diff --git a/Assets/Huawei/Scripts/IAP/HMSIAPManager.cs b/Assets/Huawei/Scripts/IAP/HMSIAPManager.cs index 75fdd1d7..ca9bef82 100644 --- a/Assets/Huawei/Scripts/IAP/HMSIAPManager.cs +++ b/Assets/Huawei/Scripts/IAP/HMSIAPManager.cs @@ -11,7 +11,7 @@ namespace HmsPlugin { public class HMSIAPManager : HMSSingleton { - private static readonly HMSException IAP_NOT_AVAILABLE = new HMSException("IAP not available"); + private static readonly HMSException IAP_NOT_AVAILABLE = new HMSException("[HMSIAPManager] IAP not available"); public Action OnCheckIapAvailabilitySuccess { get; set; } public Action OnCheckIapAvailabilityFailure { get; set; } @@ -31,6 +31,12 @@ public class HMSIAPManager : HMSSingleton public Action OnObtainOwnedPurchasesSuccess { get; set; } public Action OnObtainOwnedPurchasesFailure { get; set; } + public Action OnObtainOwnedPurchaseRecordSuccess { get; set; } + public Action OnObtainOwnedPurchaseRecordFailure { get; set; } + + public Action OnIsSandboxActivatedSuccess { get; set; } + public Action OnIsSandboxActivatedFailure { get; set; } + private IIapClient iapClient; private bool? iapAvailable = null; private List productInfoList = new List(); @@ -47,7 +53,7 @@ public void CheckIapAvailability() ITask task = iapClient.EnvReady; task.AddOnSuccessListener((result) => { - Debug.Log("HMSP: checkIapAvailabity SUCCESS"); + Debug.Log("[HMSIAPManager] checkIapAvailabity SUCCESS"); iapAvailable = true; OnCheckIapAvailabilitySuccess?.Invoke(); ObtainProductInfo(HMSIAPProductListSettings.Instance.GetProductIdentifiersByType(HMSIAPProductType.Consumable), @@ -57,13 +63,13 @@ public void CheckIapAvailability() }).AddOnFailureListener((exception) => { - Debug.Log("[HMSPlugin]: Error on EnvReady"); + Debug.LogError("[HMSIAPManager]: Error on EnvReady"); IapApiException iapEx = exception.AsIapApiException(); iapEx.Status.StartResolutionForResult ( (intent) => { - Debug.Log("[HMSPlugin]: Success on iapEx Resolution"); + Debug.Log("[HMSIAPManager]: Success on iapEx Resolution"); OnCheckIapAvailabilitySuccess?.Invoke(); ObtainProductInfo(HMSIAPProductListSettings.Instance.GetProductIdentifiersByType(HMSIAPProductType.Consumable), HMSIAPProductListSettings.Instance.GetProductIdentifiersByType(HMSIAPProductType.NonConsumable), @@ -74,7 +80,7 @@ public void CheckIapAvailability() iapClient = null; iapAvailable = false; - Debug.Log("[HMSPlugin]: ERROR on StartResolutionForResult: " + ex.WrappedCauseMessage + " " + ex.WrappedExceptionMessage); + Debug.LogError("[HMSIAPManager]: ERROR on StartResolutionForResult: " + ex.WrappedCauseMessage + " " + ex.WrappedExceptionMessage); OnCheckIapAvailabilityFailure?.Invoke(exception); } ); @@ -121,20 +127,20 @@ private void ObtainProductInfo(IList productIdNonConsumablesList, PriceT iapClient.ObtainProductInfo(productInfoReq).AddOnSuccessListener((type) => { - Debug.Log("[HMSPlugin]:" + type.ErrMsg + type.ReturnCode.ToString()); - Debug.Log("[HMSPlugin]: {0=Consumable} {1=Non-Consumable} {2=Subscription}"); - Debug.Log("[HMSPlugin]: Found " + type.ProductInfoList.Count + " type of " + priceType.Value + " products"); + Debug.Log("[HMSIAPManager]:" + type.ErrMsg + type.ReturnCode.ToString()); + Debug.Log("[HMSIAPManager]: {0=Consumable} {1=Non-Consumable} {2=Subscription}"); + Debug.Log("[HMSIAPManager]: Found " + type.ProductInfoList.Count + " type of " + priceType.Value + " products"); foreach (var productInfo in type.ProductInfoList) { if (!productInfoList.Exists(c => c.ProductId == productInfo.ProductId)) productInfoList.Add(productInfo); - Debug.Log("[HMSPlugin]: ProductId: " + productInfo.ProductId + ", ProductName: " + productInfo.ProductName + ", Price: " + productInfo.Price); + Debug.Log("[HMSIAPManager]: ProductId: " + productInfo.ProductId + ", ProductName: " + productInfo.ProductName + ", Price: " + productInfo.Price); } OnObtainProductInfoSuccess?.Invoke(new List { type }); }).AddOnFailureListener((exception) => { - Debug.Log("[HMSPlugin]: ERROR non Consumable ObtainInfo" + exception.Message); + Debug.LogError("[HMSIAPManager]: ObtainProductInfo failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnObtainProductInfoFailure?.Invoke(exception); }); } @@ -153,18 +159,18 @@ public void ConsumeOwnedPurchases() ITask task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq); task.AddOnSuccessListener((result) => { - Debug.Log("HMSP: recoverPurchases"); + Debug.Log("[HMSIAPManager] recoverPurchases"); foreach (var inAppPurchaseData in result.InAppPurchaseDataList) { ConsumePurchaseWithPurchaseData(inAppPurchaseData); - Debug.Log("HMSP: recoverPurchases result> " + result.ReturnCode); + Debug.Log("[HMSIAPManager] recoverPurchases result> " + result.ReturnCode); } OnRecoverPurchasesSuccess?.Invoke(); }).AddOnFailureListener((exception) => { - Debug.Log($"HMSP: Error on recoverPurchases {exception.StackTrace}"); + Debug.LogError("[HMSIAPManager] ConsumeOwnedPurchases failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnRecoverPurchasesFailure?.Invoke(exception); }); @@ -199,12 +205,12 @@ public void ConsumePurchaseWithToken(string token) task.AddOnSuccessListener((result) => { - Debug.Log("HMSP: consumePurchase"); + Debug.Log("[HMSIAPManager] consumePurchase"); OnConsumePurchaseSuccess?.Invoke(); }).AddOnFailureListener((exception) => { - Debug.Log("HMSP: Error on consumePurchase"); + Debug.LogError("[HMSIAPManager] ConsumePurchaseWithToken failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnConsumePurchaseFailure?.Invoke(exception); }); @@ -219,7 +225,7 @@ public void BuyProduct(string productId, bool consumeAfter = true, string payloa } else { - Debug.LogError($"[HMSPlugin->HMSIAPManager]: Specified: {productId} could not be found in retrieved product list!"); + Debug.LogError($"[HMSIAPManager] Specified: {productId} could not be found in retrieved product list!"); } } @@ -243,20 +249,17 @@ public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true { if (result != null) { - Debug.Log("[HMSPlugin]:" + result.ErrMsg + result.ReturnCode.ToString()); - Debug.Log("[HMSPlugin]: Buying " + purchaseIntentReq.ProductId); + Debug.Log("[HMSIAPManager]:" + result.ErrMsg + result.ReturnCode.ToString()); + Debug.Log("[HMSIAPManager]: Buying " + purchaseIntentReq.ProductId); Status status = result.Status; status.StartResolutionForResult((androidIntent) => { PurchaseResultInfo purchaseResultInfo = iapClient.ParsePurchaseResultInfoFromIntent(androidIntent); - Debug.Log("HMSPluginResult: " + purchaseResultInfo.ReturnCode); - Debug.Log("HMSErrorMsg: " + purchaseResultInfo.ErrMsg); - if (purchaseResultInfo.ReturnCode == OrderStatusCode.ORDER_STATE_SUCCESS) { - Debug.Log("HMS: HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData); - Debug.Log("HMS: HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature); + Debug.Log("[HMSIAPManager] HMSInAppPurchaseData" + purchaseResultInfo.InAppPurchaseData); + Debug.Log("[HMSIAPManager] HMSInAppDataSignature" + purchaseResultInfo.InAppDataSignature); OnBuyProductSuccess.Invoke(purchaseResultInfo); if (consumeAfter) ConsumePurchase(purchaseResultInfo); @@ -266,19 +269,19 @@ public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true switch (purchaseResultInfo.ReturnCode) { case OrderStatusCode.ORDER_STATE_CANCEL: - Debug.Log("[HMS]: User cancel payment"); + Debug.LogError("[HMSIAPManager] User cancel payment"); break; case OrderStatusCode.ORDER_STATE_FAILED: - Debug.Log("[HMS]: order payment failed"); + Debug.LogError("[HMSIAPManager] order payment failed"); break; case OrderStatusCode.ORDER_PRODUCT_OWNED: - Debug.Log("[HMS]: Product owned"); + Debug.LogError("[HMSIAPManager] Product owned"); break; default: - Debug.Log("[HMS:] BuyProduct ERROR" + purchaseResultInfo.ReturnCode); + Debug.LogError("[HMSIAPManager] BuyProduct failed. ReturnCode: " + purchaseResultInfo.ReturnCode + ", ErrorMsg: " + purchaseResultInfo.ErrMsg); break; } OnBuyProductFailure?.Invoke(purchaseResultInfo.ReturnCode); @@ -286,14 +289,14 @@ public void InternalBuyProduct(ProductInfo productInfo, bool consumeAfter = true }, (exception) => { - Debug.Log("[HMSPlugin]:startIntent ERROR"); + Debug.LogError("[HMSIAPManager] startIntent ERROR"); }); } }).AddOnFailureListener((exception) => { - Debug.Log("[HMSPlugin]: ERROR BuyProduct!!" + exception.Message); + Debug.LogError("[HMSIAPManager]: BuyProduct failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); }); } @@ -306,7 +309,7 @@ public void ObtainOwnedPurchases() } - Debug.Log("HMSP: ObtainOwnedPurchaseRequest"); + Debug.Log("[HMSIAPManager] ObtainOwnedPurchaseRequest"); ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_CONSUMABLE }); ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_NONCONSUMABLE }); ObtainOwnedPurchases(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_SUBSCRIPTION }); @@ -317,20 +320,53 @@ private void ObtainOwnedPurchases(OwnedPurchasesReq ownedPurchasesReq) ITask task = iapClient.ObtainOwnedPurchases(ownedPurchasesReq); task.AddOnSuccessListener((result) => { - Debug.Log("HMSP: ObtainOwnedPurchases"); + Debug.Log("[HMSIAPManager] ObtainOwnedPurchases"); foreach (var item in result.InAppPurchaseDataList) { - Debug.Log("[HMSPlugin]: ProductId: " + item.ProductId + ", ProductName: " + item.ProductName + ", Price: " + item.Price); + Debug.Log("[HMSIAPManager] ProductId: " + item.ProductId + ", ProductName: " + item.ProductName + ", Price: " + item.Price); } OnObtainOwnedPurchasesSuccess?.Invoke(result); }).AddOnFailureListener((exception) => { - Debug.Log("HMSP: Error on ObtainOwnedPurchases"); + Debug.LogError("[HMSIAPManager]: ObtainOwnedPurchases failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnObtainProductInfoFailure?.Invoke(exception); }); } + public void ObtainOwnedPurchaseRecord() + { + if (iapAvailable != true) + { + OnObtainOwnedPurchaseRecordFailure?.Invoke(IAP_NOT_AVAILABLE); + return; + } + + Debug.Log("HMSP: ObtainOwnedPurchaseRecord"); + ObtainOwnedPurchaseRecord(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_CONSUMABLE }); + ObtainOwnedPurchaseRecord(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_NONCONSUMABLE }); + ObtainOwnedPurchaseRecord(new OwnedPurchasesReq() { PriceType = PriceType.IN_APP_SUBSCRIPTION }); + } + + private void ObtainOwnedPurchaseRecord(OwnedPurchasesReq req) + { + ITask task = iapClient.ObtainOwnedPurchaseRecord(req); + task.AddOnSuccessListener((result) => + { + Debug.Log("HMSP: ObtainOwnedPurchaseRecord"); + foreach (var item in result.InAppPurchaseDataList) + { + Debug.Log("[HMSPlugin]: ProductId: " + item.ProductId + ", ProductName: " + item.ProductName + ", Price: " + item.Price); + } + OnObtainOwnedPurchaseRecordSuccess?.Invoke(result); + + }).AddOnFailureListener((exception) => + { + Debug.Log("HMSP: Error on ObtainOwnedPurchaseRecord"); + OnObtainOwnedPurchaseRecordFailure?.Invoke(exception); + }); + } + public void RestorePurchases(Action action) { OnObtainOwnedPurchasesSuccess = (ownedPurchaseResult) => @@ -344,7 +380,7 @@ public void RestorePurchases(Action action) OnObtainOwnedPurchasesFailure = (error) => { - Debug.Log("[HMSPlugin:] RestorePurchasesError" + error.Message); + Debug.LogError("[HMSIAPManager]: RestorePurchasesError failed. CauseMessage: " + error.WrappedCauseMessage + ", ExceptionMessage: " + error.WrappedExceptionMessage); }; ObtainOwnedPurchases(); @@ -359,5 +395,26 @@ public bool IsNullOrEmpty(List array) { return (array == null || array.Count == 0); } + + public void IsSandboxActivated() + { + if (iapClient != null) + { + var task = iapClient.SandboxActivated; + task.AddOnSuccessListener((result) => + { + Debug.Log("[HMSIAPManager]: IsSandboxActivated success!"); + OnIsSandboxActivatedSuccess?.Invoke(result); + }).AddOnFailureListener((exception) => + { + Debug.LogError("[HMSIAPManager]: IsSandboxActivated failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); + OnIsSandboxActivatedFailure?.Invoke(exception); + }); + } + else + { + Debug.LogError("[HMSIAPManager]: IsSandboxActivated failed. IAP is not initialized."); + } + } } } \ No newline at end of file diff --git a/Assets/Huawei/Scripts/RemoteConfig/HMSRemoteConfigManager.cs b/Assets/Huawei/Scripts/RemoteConfig/HMSRemoteConfigManager.cs index d54e20da..cc3fdd56 100644 --- a/Assets/Huawei/Scripts/RemoteConfig/HMSRemoteConfigManager.cs +++ b/Assets/Huawei/Scripts/RemoteConfig/HMSRemoteConfigManager.cs @@ -72,10 +72,12 @@ public void Fetch() ITask x = agc.Fetch(); x.AddOnSuccessListener((configValues) => { + Debug.Log("[HMSRemoteConfigManager] Fetch success."); OnFecthSuccess?.Invoke(configValues); }); x.AddOnFailureListener((exception) => { + Debug.LogError("[HMSRemoteConfigManager]: Fetch failed. CauseMessage: " + exception.WrappedCauseMessage + ", ExceptionMessage: " + exception.WrappedExceptionMessage); OnFecthFailure?.Invoke(exception); }); } diff --git a/Assets/Huawei/VERSION b/Assets/Huawei/VERSION index 703cec9e..6a0ca2d5 100644 --- a/Assets/Huawei/VERSION +++ b/Assets/Huawei/VERSION @@ -1 +1 @@ -2.0.6 \ No newline at end of file +2.0.7 \ No newline at end of file