|
@@ -0,0 +1,53 @@
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Diagnostics;
|
|
|
+using System.IO;
|
|
|
+using System.Linq;
|
|
|
+using UnityEditor;
|
|
|
+
|
|
|
+public class KeystorePasswordSetter
|
|
|
+{
|
|
|
+#if UNITY_ANDROID
|
|
|
+ private const string KeystoreFolderPath = "Keystore";
|
|
|
+
|
|
|
+ private static string KeystoreFilePath => Directory.GetFiles(KeystoreFolderPath, "*.keystore") .FirstOrDefault();
|
|
|
+ private static string KeystorePasswordFilePath => Directory.GetFiles(KeystoreFolderPath, "*.txt") .FirstOrDefault();
|
|
|
+
|
|
|
+ [UnityEditor.Callbacks.PostProcessBuild]
|
|
|
+ private static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject)
|
|
|
+ {
|
|
|
+ AutoSetupKeystore();
|
|
|
+ }
|
|
|
+
|
|
|
+ [MenuItem("Tools/自动设置 Keystore")]
|
|
|
+ private static void AutoSetupKeystore()
|
|
|
+ {
|
|
|
+ var keystorePasswordDict = ReadKeystorePassword();
|
|
|
+
|
|
|
+ PlayerSettings.Android.useCustomKeystore = true;
|
|
|
+ PlayerSettings.Android.keystoreName = KeystoreFilePath;
|
|
|
+ PlayerSettings.Android.keystorePass = keystorePasswordDict["keystorePass"];
|
|
|
+ PlayerSettings.Android.keyaliasName = keystorePasswordDict["keyaliasName"];
|
|
|
+ PlayerSettings.Android.keyaliasPass = keystorePasswordDict["keyaliasPass"];
|
|
|
+ AssetDatabase.SaveAssets();
|
|
|
+ AssetDatabase.Refresh();
|
|
|
+ }
|
|
|
+
|
|
|
+ private static Dictionary<string, string> ReadKeystorePassword()
|
|
|
+ {
|
|
|
+ var result = new Dictionary<string, string>();
|
|
|
+
|
|
|
+ foreach (string line in File.ReadLines(KeystorePasswordFilePath))
|
|
|
+ {
|
|
|
+ string[] parts = line.Split(new[] { ':', ':' }, StringSplitOptions.None);
|
|
|
+ if (parts.Length == 2 && !string.IsNullOrWhiteSpace(parts[0]) && !string.IsNullOrWhiteSpace(parts[1]))
|
|
|
+ {
|
|
|
+ result.Add(parts[0].Trim(), parts[1].Trim());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+#endif
|
|
|
+}
|