예제 #1
0
        /// <summary>
        /// Creates a scene in the current project that acts as a loading scene until assetbundles are downloaded from the CDN.
        /// Takes in an assetbundle URL, and a background image to display behind the loading bar.
        /// Replaces the current loading scene with a new one if it exists.
        /// </summary>
        public static void GenerateScene(string assetBundleUrl, Texture2D loadingScreenImage, string sceneFilePath)
        {
            // Removes the loading scene if it is present, otherwise does nothing.
            EditorSceneManager.CloseScene(SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(sceneFilePath)),
                                          true);

            var loadingScreenScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            PopulateScene(loadingScreenImage, assetBundleUrl);

            bool saveOk = EditorSceneManager.SaveScene(loadingScreenScene, sceneFilePath);

            if (!saveOk)
            {
                // Not a fatal issue. User can attempt to resave this scene.
                var warningMessage = string.Format("Issue while saving scene {0}.", sceneFilePath);
                Debug.LogWarning(warningMessage);
                DialogHelper.DisplayMessage(SaveErrorTitle, warningMessage);
            }
            else
            {
                AssetDatabase.Refresh();
                SetMainSceneInBuild(sceneFilePath);
            }
        }
        /// <summary>
        /// Creates a scene in the current project that acts as a loading scene until assetbundles are
        /// downloaded from the CDN. Takes in a loadingScreenImagePath, a path to the image shown in the loading scene,
        /// and an assetbundle URL. Replaces the current loading scene with a new one if it exists.
        /// </summary>
        public static void GenerateScene(string assetBundleUrl, string loadingScreenImagePath)
        {
            if (string.IsNullOrEmpty(assetBundleUrl))
            {
                throw new ArgumentException("AssetBundle URL text field cannot be null or empty.");
            }

            if (!File.Exists(loadingScreenImagePath))
            {
                throw new FileNotFoundException(string.Format("Loading screen image file cannot be found: {0}",
                                                              loadingScreenImagePath));
            }

            // Removes the loading scene if it is present, otherwise does nothing.
            EditorSceneManager.CloseScene(SceneManager.GetSceneByName(Path.GetFileNameWithoutExtension(SceneName)),
                                          true);

            var loadingScreenScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            var loadingScreenGameObject = new GameObject(CanvasName);

            AddImageToScene(loadingScreenGameObject, loadingScreenImagePath);

            AddScript(loadingScreenGameObject);

            LoadingBar.AddComponent(loadingScreenGameObject);

            bool saveOk = EditorSceneManager.SaveScene(loadingScreenScene, SceneFilePath);

            if (!saveOk)
            {
                // Not a fatal issue. User can attempt to resave this scene.
                var warningMessage = string.Format("Issue while saving scene {0}.",
                                                   SceneName);

                Debug.LogWarning(warningMessage);

                DialogHelper.DisplayMessage(SaveErrorTitle, warningMessage);
            }
            else
            {
                //TODO: investigate GUI Layout errors that occur when moving this to DialogHelper
                if (EditorUtility.DisplayDialog("Change Scenes in Build",
                                                "Would you like to replace any existing Scenes in Build with the loading screen scene?", "Yes",
                                                "No"))
                {
                    SetMainSceneInBuild(SceneFilePath);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// Displays a save dialog, saves the specified path to config, and then creates an AssetBundle at that path.
        /// </summary>
        private void HandleBuildAssetBundleButton()
        {
            string saveFilePath = DialogHelper.SaveFilePanel("Save AssetBundle", Config.AssetBundleFileName, "");

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

            Config.AssetBundleFileName = saveFilePath;

            try
            {
                Config.SaveConfiguration(true);
                AssetBundleBuilder.BuildQuickDeployAssetBundle(GetEnabledSceneItemPaths());
            }
            catch (Exception ex)
            {
                DialogHelper.DisplayMessage(AssetBundleBuildErrorTitle, ex.Message);
                throw;
            }
        }
예제 #4
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();
        }
        private void OnGuiDeployBundleSelect()
        {
            //TODO: investigate sharing this code
            var descriptionTextStyle = CreateDescriptionTextStyle();

            EditorGUILayout.LabelField("Create Google Cloud Credentials", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical(UserInputGuiStyle);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(
                "Quick Deploy requires valid credentials to upload the AssetBundle file.",
                descriptionTextStyle);
            EditorGUILayout.LabelField(
                "Open Google Cloud console to create an OAuth 2.0 client ID. Select Application Type \"Other\". " +
                "Download the JSON file containing the credentials.",
                descriptionTextStyle);
            EditorGUILayout.Space();

            if (GUILayout.Button("Open Google Cloud Console"))
            {
                Application.OpenURL("https://console.cloud.google.com/apis/credentials");
            }

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

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

            EditorGUILayout.LabelField("Configure AssetBundle Deployment", EditorStyles.boldLabel);
            EditorGUILayout.BeginVertical(UserInputGuiStyle);
            EditorGUILayout.Space();
            EditorGUILayout.LabelField(
                "Specify path to credentials file created above and to AssetBundle file created with  " +
                "AssetBundle Browser. Choose bucket and object names to use for uploaded AssetBundle file.",
                descriptionTextStyle);
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Google Cloud Credentials File Path", GUILayout.MinWidth(FieldMinWidth));
            Config.CloudCredentialsFileName =
                EditorGUILayout.TextField(Config.CloudCredentialsFileName,
                                          GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Browse", GUILayout.Width(ShortButtonWidth)))
            {
                Config.CloudCredentialsFileName =
                    EditorUtility.OpenFilePanel("Select cloud credentials file", "", "");
                HandleDialogExit();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("AssetBundle File Path", GUILayout.MinWidth(FieldMinWidth));
            Config.AssetBundleFileName = EditorGUILayout.TextField(Config.AssetBundleFileName,
                                                                   GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Browse", GUILayout.Width(ShortButtonWidth)))
            {
                Config.AssetBundleFileName = EditorUtility.OpenFilePanel("Select AssetBundle file", "", "");
                HandleDialogExit();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cloud Storage Bucket Name", GUILayout.MinWidth(FieldMinWidth));
            Config.CloudStorageBucketName =
                EditorGUILayout.TextField(Config.CloudStorageBucketName, GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cloud Storage Object Name", GUILayout.MinWidth(FieldMinWidth));
            Config.CloudStorageObjectName =
                EditorGUILayout.TextField(Config.CloudStorageObjectName, GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.Space();

            EditorGUILayout.Space();
            if (GUILayout.Button("Upload to Google Cloud Storage"))
            {
                try
                {
                    Config.SaveConfiguration(ToolBarSelectedButton.DeployBundle);
                    GcpClient.DeployConfiguredFile();
                }
                catch (Exception ex)
                {
                    DialogHelper.DisplayMessage(AssetBundleDeploymentErrorTitle, ex.Message);

                    throw;
                }
            }

            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();
        }
        private void OnGuiCreateBundleSelect()
        {
            var descriptionTextStyle = CreateDescriptionTextStyle();

            EditorGUILayout.LabelField("Create AssetBundle", EditorStyles.boldLabel);

            EditorGUILayout.BeginVertical(UserInputGuiStyle);

            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Select scenes to be put into an AssetBundle and then build it.",
                                       descriptionTextStyle);

            EditorGUILayout.Space();

            EditorGUILayout.EndVertical();

            EditorGUILayout.Space();

            EditorGUILayout.BeginVertical(UserInputGuiStyle);
            EditorGUILayout.Space();

            _playInstantSceneTreeTreeView.OnGUI(GUILayoutUtility.GetRect(position.width,
                                                                         position.height - SceneViewDeltaFromTop));
            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Add Open Scenes"))
            {
                _playInstantSceneTreeTreeView.AddOpenScenes();
            }

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

            EditorGUILayout.Space();


            EditorGUILayout.BeginHorizontal();

            EditorGUILayout.LabelField("AssetBundle File Path", GUILayout.MinWidth(FieldMinWidth));
            Config.AssetBundleFileName = EditorGUILayout.TextField(Config.AssetBundleFileName,
                                                                   GUILayout.MinWidth(FieldMinWidth));
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Browse", GUILayout.Width(ShortButtonWidth)))
            {
                Config.AssetBundleFileName = EditorUtility.SaveFilePanel("Save AssetBundle", "", "", "");
                HandleDialogExit();
            }

            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();

            if (GUILayout.Button("Build AssetBundle"))
            {
                try
                {
                    Config.SaveConfiguration(ToolBarSelectedButton.CreateBundle);
                    AssetBundleBuilder.BuildQuickDeployAssetBundle(GetEnabledSceneItemPaths());
                }
                catch (Exception ex)
                {
                    DialogHelper.DisplayMessage(AssetBundleBuildErrorTitle,
                                                ex.Message);
                    throw;
                }

                HandleDialogExit();
            }

            EditorGUILayout.EndHorizontal();
        }