Last active
March 11, 2024 11:18
-
-
Save JLChnToZ/f1524c577208935c679da5f3dd826d53 to your computer and use it in GitHub Desktop.
Prompt you to enter the keystore password if you forget before starting a new Android build in Unity.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using UnityEditor.Build; | |
public class AutoPasswordPrompt : EditorWindow { | |
[InitializeOnLoadMethod] | |
static void Register() => BuildPlayerWindow.RegisterBuildPlayerHandler(BuildHandler); | |
static bool IsUnfilled() => | |
string.IsNullOrEmpty(PlayerSettings.Android.keystorePass) || | |
string.IsNullOrEmpty(PlayerSettings.Android.keyaliasPass); | |
static void BuildHandler(BuildPlayerOptions options) { | |
if (options.target == BuildTarget.Android && | |
PlayerSettings.Android.useCustomKeystore && | |
IsUnfilled() && | |
EditorUtility.DisplayDialog( | |
"Password Prompt", | |
"You have not set the keystore password or the key alias password. Do you want to set it now?", | |
"Yes", "No" | |
) | |
) { | |
GetWindow<AutoPasswordPrompt>("Keystore Password").ShowModalUtility(); | |
if (IsUnfilled()) throw new BuildFailedException("Keystore password and key alias password not set."); | |
} | |
BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(options); | |
} | |
void OnGUI() { | |
GUILayout.Label("Please enter the keystore password and the key alias password."); | |
var keystorePass = PlayerSettings.Android.keystorePass; | |
using (var changed = new EditorGUI.ChangeCheckScope()) { | |
keystorePass = EditorGUILayout.PasswordField(PlayerSettings.Android.keystoreName, keystorePass); | |
if (changed.changed) PlayerSettings.Android.keystorePass = keystorePass; | |
} | |
var keyaliasPass = PlayerSettings.Android.keyaliasPass; | |
using (var changed = new EditorGUI.ChangeCheckScope()) { | |
keyaliasPass = EditorGUILayout.PasswordField(PlayerSettings.Android.keyaliasName, keyaliasPass); | |
if (changed.changed) PlayerSettings.Android.keyaliasPass = keyaliasPass; | |
} | |
if (GUILayout.Button("Done")) Close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment