Пример #1
0
        /// <summary>
        /// Displays a save dialog, saves the specified path to config, and then creates a loading scene at that path.
        /// </summary>
        private void HandleCreateLoadingSceneButton()
        {
            if (string.IsNullOrEmpty(Config.AssetBundleUrl))
            {
                DialogHelper.DisplayMessage(LoadingScreenCreationErrorTitle,
                                            "AssetBundle URL text field cannot be null or empty.");
                return;
            }

            string saveFilePath =
                DialogHelper.SaveFilePanelInProject("Create Loading Scene", Config.LoadingSceneFileName, "unity");

            if (String.IsNullOrEmpty(saveFilePath))
            {
                // Assume cancelled.
                return;
            }

            Config.LoadingSceneFileName = saveFilePath;

            try
            {
                Config.SaveConfiguration(true);
                LoadingScreenGenerator.GenerateScene(Config.AssetBundleUrl, Config.LoadingBackgroundImage,
                                                     saveFilePath);

                // Select the Loading screen element in the generated scene, so the user can see the assetBundle url
                // field in the inspector.
                Selection.SetActiveObjectWithContext(LoadingScreenGenerator.CurrentLoadingScreen, null);
                Close();
            }
            catch (Exception ex)
            {
                DialogHelper.DisplayMessage(LoadingScreenCreationErrorTitle, ex.Message);
                throw;
            }
        }
        private void OnGuiLoadingScreenSelect()
        {
            var descriptionTextStyle = CreateDescriptionTextStyle();

            EditorGUILayout.LabelField("Set AssetBundle URL", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical(UserInputGuiStyle);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField(
                "Specify the URL that points to the deployed AssetBundle. The AssetBundle will be downloaded at game startup. ",
                descriptionTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("AssetBundle URL", GUILayout.MinWidth(FieldMinWidth));
            Config.AssetBundleUrl =
                EditorGUILayout.TextField(Config.AssetBundleUrl, GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();

            var setAssetBundleText = QuickDeployConfig.EngineConfigExists()
                ? "Update AssetBundle URL"
                : "Set AssetBundle URL";

            if (GUILayout.Button(setAssetBundleText))
            {
                try
                {
                    Config.SaveConfiguration(ToolBarSelectedButton.LoadingScreen);
                }
                catch (Exception ex)
                {
                    DialogHelper.DisplayMessage(AssetBundleCheckerErrorTitle, ex.Message);

                    throw;
                }
            }

            EditorGUILayout.Space();
            if (GUILayout.Button("Check AssetBundle"))
            {
                var window = AssetBundleVerifierWindow.ShowWindow();

                try
                {
                    Config.SaveConfiguration(ToolBarSelectedButton.LoadingScreen);
                    window.StartAssetBundleDownload(Config.AssetBundleUrl);
                }
                catch (Exception ex)
                {
                    DialogHelper.DisplayMessage(AssetBundleCheckerErrorTitle, ex.Message);

                    window.Close();

                    throw;
                }
            }

            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Select Loading Screen Image", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical(UserInputGuiStyle);
            EditorGUILayout.Space();

            EditorGUILayout.LabelField(
                "Choose image to use as background for the loading scene.", descriptionTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Image File Path", GUILayout.MinWidth(FieldMinWidth));

            _loadingScreenImagePath =
                EditorGUILayout.TextField(_loadingScreenImagePath, GUILayout.MinWidth(FieldMinWidth));

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Browse", GUILayout.Width(ShortButtonWidth)))
            {
                _loadingScreenImagePath =
                    EditorUtility.OpenFilePanel("Select Image", "", "png,jpg,jpeg,tif,tiff,gif,bmp");
                HandleDialogExit();
            }

            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            if (LoadingScreenGenerator.LoadingScreenExists())
            {
                if (GUILayout.Button("Update Loading Scene"))
                {
                    try
                    {
                        Config.SaveConfiguration(ToolBarSelectedButton.LoadingScreen);
                        LoadingScreenGenerator.AddImageToScene(LoadingScreenGenerator.GetLoadingScreenCanvasObject(),
                                                               _loadingScreenImagePath);
                    }
                    catch (Exception ex)
                    {
                        DialogHelper.DisplayMessage(LoadingScreenUpdateErrorTitle, ex.Message);
                        throw;
                    }
                }
            }
            else
            {
                if (GUILayout.Button("Create Loading Scene"))
                {
                    try
                    {
                        Config.SaveConfiguration(ToolBarSelectedButton.LoadingScreen);
                        LoadingScreenGenerator.GenerateScene(Config.AssetBundleUrl,
                                                             _loadingScreenImagePath);
                    }
                    catch (Exception ex)
                    {
                        DialogHelper.DisplayMessage(LoadingScreenCreationErrorTitle, ex.Message);
                        throw;
                    }
                }
            }

            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();
        }