유니티 안드로이드 키스토어 비밀번호 자동 입력

카테고리 없음|2021. 5. 7. 16:02

Project Settings 윈도우에서 비밀번호를 입력할 수 있으며, 유니티를 끄고 켜도 입력이 유지된다.

#if UNITY_ANDROID
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using UnityEditor.Callbacks;

namespace Waker.BuildTools
{
    public partial class AndroidKeystore : ScriptableObject
    {
        public const string CustomSettingsPath = "Assets/Editor/Android Keystore Password.asset";

        [SerializeField] private string keystorePassword;
        [SerializeField] private string keyaliasPassword;

        public void UpdatePlayerSettings()
        {
            var i = GetOrCreateSettings(); 

            PlayerSettings.Android.keystorePass = i.keystorePassword;
            PlayerSettings.Android.keyaliasPass = i.keyaliasPassword;
        }

        internal static AndroidKeystore GetOrCreateSettings()
        {
            var settings = AssetDatabase.LoadAssetAtPath<AndroidKeystore>(CustomSettingsPath);
            if (settings == null)
            {
                settings = ScriptableObject.CreateInstance<AndroidKeystore>();
                AssetDatabase.CreateAsset(settings, CustomSettingsPath);
                AssetDatabase.SaveAssets();
            }
            return settings;
        }

        internal static SerializedObject GetSerializedSettings()
        {
            return new SerializedObject(GetOrCreateSettings());
        }

        [SettingsProvider]
        public static SettingsProvider CreateSettingsProvider()
        {
            // First parameter is the path in the Settings window.
            // Second parameter is the scope of this setting: it only appears in the Project Settings window.
            var provider = new SettingsProvider("Project/Waker/Android Keystore Password", SettingsScope.Project)
            {
                // By default the last token of the path is used as display name if no label is provided.
                label = "Android Keystore Password",
                // Create the SettingsProvider and initialize its drawing (IMGUI) function in place:
                guiHandler = (searchContext) =>
                {
                    var settings = AndroidKeystore.GetSerializedSettings();

                    settings.Update();

                    EditorGUILayout.PropertyField(settings.FindProperty("keystorePassword"), new GUIContent("keystorePassword"));
                    EditorGUILayout.PropertyField(settings.FindProperty("keyaliasPassword"), new GUIContent("keyaliasPassword"));

                    settings.ApplyModifiedProperties();

                    if (GUILayout.Button("Update"))
                    {
                        AndroidKeystore.GetOrCreateSettings().UpdatePlayerSettings();
                    }
                },

                // Populate the search keywords to enable smart search filtering and label highlighting:
                // keywords = new HashSet<string>(new[] { "Number", "Some String" })
            };

            return provider;
        }
    }
}
#endif

댓글()