Browse Source

开发:更换Keystore,以及打包自动设置keystore

XuJJ 3 weeks ago
parent
commit
8ba348a8b8

+ 53 - 0
snipershooting/ShootSniper/Assets/Editor/ProjectBuild/AndroidBuild/KeystorePasswordSetter.cs

@@ -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
+}

+ 11 - 0
snipershooting/ShootSniper/Assets/Editor/ProjectBuild/AndroidBuild/KeystorePasswordSetter.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ef3f55a5b4bce4df1821646327290273
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

BIN
snipershooting/ShootSniper/Keystore/ShootSniper.keystore


+ 0 - 7
snipershooting/ShootSniper/Keystore/ShootSniper.txt

@@ -1,7 +0,0 @@
-password:
-shootsniper
-
-alias:
-shoot_sniper
-password:
-shoot_sniper

+ 4 - 0
snipershooting/ShootSniper/Keystore/keystore密码.txt

@@ -0,0 +1,4 @@
+keystore : widesscattersgass.keystore 
+keystorePass : widesscattersgass
+keyaliasName : widesscattersgass.keystore 
+keyaliasPass : widesscattersgass

BIN
snipershooting/ShootSniper/Keystore/widesscattersgass.keystore


+ 2 - 2
snipershooting/ShootSniper/ProjectSettings/ProjectSettings.asset

@@ -262,8 +262,8 @@ PlayerSettings:
   AndroidTargetDevices: 0
   AndroidSplashScreenScale: 0
   androidSplashScreen: {fileID: 0}
-  AndroidKeystoreName: '{inproject}: Keystore/ShootSniper.keystore'
-  AndroidKeyaliasName: shoot_sniper
+  AndroidKeystoreName: '{inproject}: Keystore/widesscattersgass.keystore'
+  AndroidKeyaliasName: widesscattersgass.keystore
   AndroidEnableArmv9SecurityFeatures: 0
   AndroidBuildApkPerCpuArchitecture: 0
   AndroidTVCompatibility: 0