diff --git a/Editor/GoogleGradleWorker.cs b/Editor/GoogleGradleWorker.cs index cff5aad..b6921f3 100644 --- a/Editor/GoogleGradleWorker.cs +++ b/Editor/GoogleGradleWorker.cs @@ -49,7 +49,10 @@ private void CreateMainGradleFile(string[] configs) { /// Array of configs private void CreateLauncherGradleFile(string[] configs) { using (StreamWriter file = File.CreateText(Path.Combine(_supportsPath, GradleFixer.LAUNCHER_GRADLE))) { - file.Write("apply plugin: 'com.google.gms.google-services'\n\n"); + bool isGoogleServices = UBHPrefs.GetBool(UnityBuilderHelper.GOOGLE_SERVICES_KEY, false); + if (isGoogleServices) { + file.Write("apply plugin: 'com.google.gms.google-services'\n\n"); + } file.Write("dependencies {\n"); for (int i = 0; i < configs.Length; i++) { file.Write(AddDependency(configs[i])); @@ -63,10 +66,13 @@ private void CreateLauncherGradleFile(string[] configs) { /// private void CreateBaseProjectGradleFile() { using (StreamWriter file = File.CreateText(Path.Combine(_supportsPath, GradleFixer.BASE_GRADLE))) { + bool isGoogleServices = UBHPrefs.GetBool(UnityBuilderHelper.GOOGLE_SERVICES_KEY, false); file.Write("allprojects {\n"); file.Write("\tbuildscript {\n"); file.Write("\t\tdependencies {\n"); - file.Write(AddClasspath("com.google.gms:google-services:4.3.10")); + if (isGoogleServices) { + file.Write(AddClasspath("com.google.gms:google-services:4.3.10")); + } file.Write("\t\t}\n\t}\n}"); } } diff --git a/Editor/GradleFixer.cs b/Editor/GradleFixer.cs index e7c0411..1ad82e2 100644 --- a/Editor/GradleFixer.cs +++ b/Editor/GradleFixer.cs @@ -85,6 +85,17 @@ public void OnPostGenerateGradleAndroidProject(string path) { if (File.Exists(destPath)) { FileUtil.DeleteFileOrDirectory(destPath); } +#if GOOGLE + bool isGoogleServices = UBHPrefs.GetBool(UnityBuilderHelper.GOOGLE_SERVICES_KEY, false); + if (!isGoogleServices) { + return; + } +#elif HUAWEI + bool isHuaweiServices = UBHPrefs.GetBool(UnityBuilderHelper.HUAWEI_SERVICES_KEY, false); + if (!isHuaweiServices) { + return; + } +#endif File.Copy(filePath, destPath); #endif } diff --git a/Editor/HuaweiGradleWorker.cs b/Editor/HuaweiGradleWorker.cs index 3c6ef4d..d4694e3 100644 --- a/Editor/HuaweiGradleWorker.cs +++ b/Editor/HuaweiGradleWorker.cs @@ -50,7 +50,10 @@ private void CreateMainGradleFile(string[] configs) { /// Array of configs private void CreateLauncherGradleFile(string[] configs) { using (StreamWriter file = File.CreateText(Path.Combine(_supportsPath, GradleFixer.LAUNCHER_GRADLE))) { - file.Write("apply plugin: 'com.huawei.agconnect'\n\n"); + bool isHuaweiServices = UBHPrefs.GetBool(UnityBuilderHelper.HUAWEI_SERVICES_KEY, false); + if (isHuaweiServices) { + file.Write("apply plugin: 'com.huawei.agconnect'\n\n"); + } file.Write("dependencies {\n"); for (int i = 0; i < configs.Length; i++) { file.Write(AddDependency(configs[i])); @@ -64,12 +67,15 @@ private void CreateLauncherGradleFile(string[] configs) { /// private void CreateBaseProjectGradleFile() { using (StreamWriter file = File.CreateText(Path.Combine(_supportsPath, GradleFixer.BASE_GRADLE))) { + bool isHuaweiServices = UBHPrefs.GetBool(UnityBuilderHelper.HUAWEI_SERVICES_KEY, false); file.Write("allprojects {\n"); file.Write("\tbuildscript {\n"); file.Write("\t\trepositories {\n"); file.Write("\t\t\tmaven { url 'https://developer.huawei.com/repo/' }\n\t\t}\n\n"); file.Write("\t\tdependencies {\n"); - file.Write(AddClasspath("com.huawei.agconnect:agcp:1.6.3.300")); + if (isHuaweiServices) { + file.Write(AddClasspath("com.huawei.agconnect:agcp:1.6.3.300")); + } file.Write("\t\t}\n\t}\n\n"); file.Write("\trepositories {\n"); file.Write("\t\tmaven { url 'https://developer.huawei.com/repo/' }\n\t}\n}\n\n"); diff --git a/Editor/PlatformValidator.cs b/Editor/PlatformValidator.cs index cf13f23..7e539b4 100644 --- a/Editor/PlatformValidator.cs +++ b/Editor/PlatformValidator.cs @@ -51,7 +51,8 @@ static PlatformValidator() { _lastValidatedPlatform = (PlatformType)UBHPrefs.GetInt(KEY, (int)PlatformType.UNKNOWN); #if HUAWEI if (_lastValidatedPlatform != PlatformType.HUAWEI) { - if (!File.Exists(Path.Combine(Application.dataPath, "StreamingAssets", HUAWEI_CONFIG))) { + bool isHuaweiServices = UBHPrefs.GetBool(UnityBuilderHelper.HUAWEI_SERVICES_KEY, false); + if (isHuaweiServices && !File.Exists(Path.Combine(Application.dataPath, "StreamingAssets", HUAWEI_CONFIG))) { Debug.LogErrorFormat(string.Format("Huawei config \"{0}\" not found in StreamingAssets!", HUAWEI_CONFIG)); return; } @@ -68,7 +69,8 @@ static PlatformValidator() { } #elif GOOGLE if (_lastValidatedPlatform != PlatformType.GOOGLE) { - if (!File.Exists(Path.Combine(Application.dataPath, "StreamingAssets", GOOGLE_CONFIG))) { + bool isGoogleServices = UBHPrefs.GetBool(UnityBuilderHelper.GOOGLE_SERVICES_KEY, false); + if (isGoogleServices && !File.Exists(Path.Combine(Application.dataPath, "StreamingAssets", GOOGLE_CONFIG))) { Debug.LogErrorFormat("Google config \"{0}\" not found in StreamingAssets!", GOOGLE_CONFIG); return; } @@ -104,6 +106,10 @@ public static bool SetKeyStore(bool isForceUpdate = false) { return true; } #if GOOGLE + bool isGoogleKeystore = UBHPrefs.GetBool(UnityBuilderHelper.GOOGLE_KEYSTORE_KEY, false); + if (!isGoogleKeystore) { + return false; + } if (string.IsNullOrEmpty(UBHPrefs.GetString(UnityBuilderHelper.GOOGLE_PASSWORD_KEY))) { Debug.LogError("KeyStore object in Config not completed"); return false; @@ -114,6 +120,10 @@ public static bool SetKeyStore(bool isForceUpdate = false) { PlayerSettings.Android.keyaliasPass = UBHPrefs.GetString(UnityBuilderHelper.GOOGLE_APASS_KEY); Debug.LogFormat("Keystore file loaded from: {0}", UBHPrefs.GetString(UnityBuilderHelper.GOOGLE_PATH_KEY)); #elif HUAWEI + bool isHuaweiKeystore = UBHPrefs.GetBool(UnityBuilderHelper.HUAWEI_KEYSTORE_KEY, false); + if (!isHuaweiKeystore) { + return false; + } if (string.IsNullOrEmpty(UBHPrefs.GetString(UnityBuilderHelper.HUAWEI_PASSWORD_KEY))) { Debug.LogError("KeyStore object in Config not completed"); return false; diff --git a/Editor/UBH.Editor.asmdef b/Editor/UBH.Editor.asmdef index 68310d3..66d061f 100644 --- a/Editor/UBH.Editor.asmdef +++ b/Editor/UBH.Editor.asmdef @@ -6,10 +6,7 @@ "GUID:eed29f14b3d2b4f4cbbc2a96074951e9" ], "includePlatforms": [ - "Android", - "Editor", - "iOS", - "WebGL" + "Editor" ], "excludePlatforms": [], "allowUnsafeCode": false, diff --git a/Editor/UnityBuilderHelper.cs b/Editor/UnityBuilderHelper.cs index bb62235..e8947b3 100644 --- a/Editor/UnityBuilderHelper.cs +++ b/Editor/UnityBuilderHelper.cs @@ -234,6 +234,26 @@ enum LoggerType { /// public const string PLIST_KEY = "ubh_plist"; + /// + /// Use google services + /// + public const string GOOGLE_SERVICES_KEY = "ubh_g_services"; + + /// + /// Use huawei services + /// + public const string HUAWEI_SERVICES_KEY = "ubh_h_services"; + + /// + /// Use keystore + /// + public const string GOOGLE_KEYSTORE_KEY = "ubh_g_keystore"; + + /// + /// Use keystore + /// + public const string HUAWEI_KEYSTORE_KEY = "ubh_h_keystore"; + /// /// Current platform /// @@ -339,6 +359,26 @@ enum LoggerType { /// private bool _isSignIn = false; + /// + /// Enable google services + /// + private bool _isGoogleServices = false; + + /// + /// Enable huawei services + /// + private bool _isHuaweiServices = false; + + /// + /// Use keystore + /// + private bool _isGoogleKeystore = false; + + /// + /// Use keystore + /// + private bool _isHuaweiKeystore = false; + /// /// Path to keystore file /// @@ -586,33 +626,40 @@ private void ShowSettings() { GUILayout.Space(VERTICAL_SPACING); _androidStatus = EditorGUILayout.Foldout(_androidStatus, "Android settings"); if (_androidStatus) { - GUILayout.Label("KeyStore for Google", EditorStyles.label); - GUILayout.BeginHorizontal(); - _googlePath = EditorGUILayout.TextField("Path:", _googlePath); - if (GUILayout.Button("...", GUILayout.MaxWidth(BROWSE_WIDTH))) { - string path = EditorUtility.OpenFilePanel("Select keystore", _googlePath, ""); - if (!string.IsNullOrEmpty(path)) { - _googlePath = path; + _isGoogleServices = EditorGUILayout.Toggle("Use google-services.json:", _isGoogleServices); + _isGoogleKeystore = EditorGUILayout.Toggle("Use KeyStore for Google", _isGoogleKeystore); + if (_isGoogleKeystore) { + GUILayout.Space(VERTICAL_SPACING); + GUILayout.BeginHorizontal(); + _googlePath = EditorGUILayout.TextField("Path:", _googlePath); + if (GUILayout.Button("...", GUILayout.MaxWidth(BROWSE_WIDTH))) { + string path = EditorUtility.OpenFilePanel("Select keystore", _googlePath, ""); + if (!string.IsNullOrEmpty(path)) { + _googlePath = path; + } } + GUILayout.EndHorizontal(); + _googlePassword = EditorGUILayout.TextField("Password:", _googlePassword); + _googleAlias = EditorGUILayout.TextField("Alias:", _googleAlias); + _googleAliasPassword = EditorGUILayout.TextField("Alias password:", _googleAliasPassword); } - GUILayout.EndHorizontal(); - _googlePassword = EditorGUILayout.TextField("Password:", _googlePassword); - _googleAlias = EditorGUILayout.TextField("Alias:", _googleAlias); - _googleAliasPassword = EditorGUILayout.TextField("Alias password:", _googleAliasPassword); GUILayout.Space(VERTICAL_SPACING); - GUILayout.Label("KeyStore for Huawei", EditorStyles.label); - GUILayout.BeginHorizontal(); - _huaweiPath = EditorGUILayout.TextField("Path:", _huaweiPath); - if (GUILayout.Button("...", GUILayout.MaxWidth(BROWSE_WIDTH))) { - string path = EditorUtility.OpenFilePanel("Select keystore", _huaweiPath, ""); - if (!string.IsNullOrEmpty(path)) { - _huaweiPath = path; + _isHuaweiServices = EditorGUILayout.Toggle("Use agconnect-services.json:", _isHuaweiServices); + _isHuaweiKeystore = EditorGUILayout.Toggle("Use KeyStore for Huawei", _isHuaweiKeystore); + if (_isHuaweiKeystore) { + GUILayout.BeginHorizontal(); + _huaweiPath = EditorGUILayout.TextField("Path:", _huaweiPath); + if (GUILayout.Button("...", GUILayout.MaxWidth(BROWSE_WIDTH))) { + string path = EditorUtility.OpenFilePanel("Select keystore", _huaweiPath, ""); + if (!string.IsNullOrEmpty(path)) { + _huaweiPath = path; + } } + GUILayout.EndHorizontal(); + _huaweiPassword = EditorGUILayout.TextField("Password:", _huaweiPassword); + _huaweiAlias = EditorGUILayout.TextField("Alias:", _huaweiAlias); + _huaweiAliasPassword = EditorGUILayout.TextField("Alias password:", _huaweiAliasPassword); } - GUILayout.EndHorizontal(); - _huaweiPassword = EditorGUILayout.TextField("Password:", _huaweiPassword); - _huaweiAlias = EditorGUILayout.TextField("Alias:", _huaweiAlias); - _huaweiAliasPassword = EditorGUILayout.TextField("Alias password:", _huaweiAliasPassword); GUILayout.Space(VERTICAL_SPACING); _huaweiDependencies = EditorGUILayout.TextField("Huawei dependencies:", _huaweiDependencies); } @@ -667,6 +714,11 @@ private void LoadSettings() { _remoteStatus = UBHPrefs.GetBool(REMOTE_KEY, true); _androidStatus = UBHPrefs.GetBool(ANDROID_KEY, false); _iosStatus = UBHPrefs.GetBool(IOS_KEY, true); + _isGoogleServices = UBHPrefs.GetBool(GOOGLE_SERVICES_KEY, false); + _isHuaweiServices = UBHPrefs.GetBool(HUAWEI_SERVICES_KEY, false); + _isGoogleKeystore = UBHPrefs.GetBool(GOOGLE_KEYSTORE_KEY, false); + _isHuaweiKeystore = UBHPrefs.GetBool(HUAWEI_KEYSTORE_KEY, false); + _iosStatus = UBHPrefs.GetBool(IOS_KEY, true); _botToken = UBHPrefs.GetString(BOT_TOKEN_KEY); _userID = UBHPrefs.GetString(USER_ID_KEY); _gameTitle = UBHPrefs.GetString(GAME_TITLE_KEY); @@ -710,6 +762,10 @@ private void SaveSettings() { UBHPrefs.SetBool(REMOTE_KEY, _remoteStatus); UBHPrefs.SetBool(ANDROID_KEY, _androidStatus); UBHPrefs.SetBool(IOS_KEY, _iosStatus); + UBHPrefs.SetBool(GOOGLE_SERVICES_KEY, _isGoogleServices); + UBHPrefs.SetBool(HUAWEI_SERVICES_KEY, _isHuaweiServices); + UBHPrefs.SetBool(GOOGLE_KEYSTORE_KEY, _isGoogleKeystore); + UBHPrefs.SetBool(HUAWEI_KEYSTORE_KEY, _isHuaweiKeystore); UBHPrefs.SetString(BOT_TOKEN_KEY, !string.IsNullOrEmpty(_botToken) ? _botToken.Trim() : ""); UBHPrefs.SetString(USER_ID_KEY, !string.IsNullOrEmpty(_userID) ? _userID.Trim() : ""); UBHPrefs.SetString(GAME_TITLE_KEY, !string.IsNullOrEmpty(_gameTitle) ? _gameTitle.Trim() : ""); @@ -817,6 +873,11 @@ private void ShowPanel() { GUILayout.EndVertical(); GUI.backgroundColor = Color.red; if (GUILayout.Button("Local build", GUILayout.Height(ACTION_HEIGHT))) { + if (string.IsNullOrEmpty(_gameTitle)) { + if (EditorUtility.DisplayDialog("Error", "Game title is empty!", "Close")) { + return; + } + } Close(); BuildResult result = Build(); string message = (result == BuildResult.Succeeded) ? "Build succeeded!" : "Build failed. See console logs :(";