Exemplo n.º 1
0
        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            Patcher patcher = (Patcher)target;

            if (patcher.EditorAppSecret != Patcher.EditorAllowedSecret)
            {
                EditorGUILayout.HelpBox("Reset the editor app secret before building.", MessageType.Warning);
                if (GUILayout.Button("Reset"))
                {
                    patcher.EditorAppSecret = Patcher.EditorAllowedSecret;
                    EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene());
                }
            }
        }
Exemplo n.º 2
0
        private void Awake()
        {
            Assert.IsNull(_instance, "There must be only one instance of Patcher component.");
            Assert.IsNotNull(ErrorDialog, "ErrorDialog must be set.");

            _instance = this;
            UnityDispatcher.Initialize();
            Application.runInBackground = true;

            DebugLogger.LogFormat("patchkit-patcher-unity: {0}", PatcherInfo.GetVersion());
            DebugLogger.LogFormat("System version: {0}", EnvironmentInfo.GetSystemVersion());
            DebugLogger.LogFormat("Runtime version: {0}", EnvironmentInfo.GetSystemVersion());

            CheckEditorAppSecretSecure();

            if (_canStartThread)
            {
                StartThread();
            }
        }
        private static void Build(BuildTarget target)
        {
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }

            string[] scenePaths = EditorBuildSettings.scenes
                                  .Where(s => s.enabled)
                                  .Select(s => s.path)
                                  .ToArray();

            if (scenePaths.Count() == 0)
            {
                EditorUtility.DisplayDialog("Error", "Add or enable scenes to be included in the Build Settings menu.", "Ok");
                return;
            }

            Patcher.Patcher patcher = null;
            foreach (var scenePath in scenePaths)
            {
                var scene = EditorSceneManager.OpenScene(scenePath);
                EditorSceneManager.SetActiveScene(scene);

                patcher = PatchKit.Unity.Patcher.Patcher.Instance;

                if (patcher)
                {
                    break;
                }
            }

            if (!patcher)
            {
                EditorUtility.DisplayDialog("Error", "Couldn't resolve an instance of the Patcher component in any of the build scenes.", "Ok");
                return;
            }

            if (patcher.EditorAppSecret != PatchKit.Unity.Patcher.Patcher.EditorAllowedSecret)
            {
                if (EditorUtility.DisplayDialog("Error", "Please reset the editor app secret to continue building.", "Reset the secret and continue", "Cancel"))
                {
                    patcher.EditorAppSecret = PatchKit.Unity.Patcher.Patcher.EditorAllowedSecret;

                    var activeScene = EditorSceneManager.GetActiveScene();

                    EditorSceneManager.MarkSceneDirty(activeScene);
                    EditorSceneManager.SaveScene(activeScene);
                }
                else
                {
                    return;
                }
            }

            BuildOptions buildOptions = BuildOptions.ForceEnableAssertions
                                        | BuildOptions.ShowBuiltPlayer;

            string path = EditorUtility.SaveFolderPanel("Choose where to build the Patcher", "", "");

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            string error = BuildPipeline.BuildPlayer(scenePaths, path + "/" + PatcherExecutableName(target), target, buildOptions);

            if (!string.IsNullOrEmpty(error))
            {
                EditorUtility.DisplayDialog("Error", error, "Ok");
            }
        }