Skip to content

Commit

Permalink
* Keystores settings added
Browse files Browse the repository at this point in the history
* Services settings added
  • Loading branch information
mopsicus committed Jun 8, 2022
1 parent 4348781 commit 9359740
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 32 deletions.
10 changes: 8 additions & 2 deletions Editor/GoogleGradleWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ private void CreateMainGradleFile(string[] configs) {
/// <param name="configs">Array of configs</param>
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]));
Expand All @@ -63,10 +66,13 @@ private void CreateLauncherGradleFile(string[] configs) {
/// </summary>
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}");
}
}
Expand Down
11 changes: 11 additions & 0 deletions Editor/GradleFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
10 changes: 8 additions & 2 deletions Editor/HuaweiGradleWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ private void CreateMainGradleFile(string[] configs) {
/// <param name="configs">Array of configs</param>
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]));
Expand All @@ -64,12 +67,15 @@ private void CreateLauncherGradleFile(string[] configs) {
/// </summary>
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");
Expand Down
14 changes: 12 additions & 2 deletions Editor/PlatformValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions Editor/UBH.Editor.asmdef
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
"GUID:eed29f14b3d2b4f4cbbc2a96074951e9"
],
"includePlatforms": [
"Android",
"Editor",
"iOS",
"WebGL"
"Editor"
],
"excludePlatforms": [],
"allowUnsafeCode": false,
Expand Down
105 changes: 83 additions & 22 deletions Editor/UnityBuilderHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,26 @@ enum LoggerType {
/// </summary>
public const string PLIST_KEY = "ubh_plist";

/// <summary>
/// Use google services
/// </summary>
public const string GOOGLE_SERVICES_KEY = "ubh_g_services";

/// <summary>
/// Use huawei services
/// </summary>
public const string HUAWEI_SERVICES_KEY = "ubh_h_services";

/// <summary>
/// Use keystore
/// </summary>
public const string GOOGLE_KEYSTORE_KEY = "ubh_g_keystore";

/// <summary>
/// Use keystore
/// </summary>
public const string HUAWEI_KEYSTORE_KEY = "ubh_h_keystore";

/// <summary>
/// Current platform
/// </summary>
Expand Down Expand Up @@ -339,6 +359,26 @@ enum LoggerType {
/// </summary>
private bool _isSignIn = false;

/// <summary>
/// Enable google services
/// </summary>
private bool _isGoogleServices = false;

/// <summary>
/// Enable huawei services
/// </summary>
private bool _isHuaweiServices = false;

/// <summary>
/// Use keystore
/// </summary>
private bool _isGoogleKeystore = false;

/// <summary>
/// Use keystore
/// </summary>
private bool _isHuaweiKeystore = false;

/// <summary>
/// Path to keystore file
/// </summary>
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() : "");
Expand Down Expand Up @@ -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 :(";
Expand Down

0 comments on commit 9359740

Please sign in to comment.