/// <summary>
        /// Creates a new scene with sceneName and saves to path.
        /// </summary>
        public static SceneInfo CreateAndSaveScene(string sceneName, string path = null)
        {
            SceneInfo sceneInfo = default(SceneInfo);

            if (!EditorSceneManager.EnsureUntitledSceneHasBeenSaved("Save untitled scene before proceeding?"))
            {
                return(sceneInfo);
            }

            Scene newScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            if (string.IsNullOrEmpty(path))
            {
                path = "Assets/" + sceneName + ".unity";
            }

            if (!EditorSceneManager.SaveScene(newScene, path))
            {
                Debug.LogError("Couldn't create and save scene " + sceneName + " at path " + path);
                return(sceneInfo);
            }

            SceneAsset sceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(path);

            sceneInfo.Asset = sceneAsset;
            sceneInfo.Name  = sceneAsset.name;
            sceneInfo.Path  = path;

            return(sceneInfo);
        }
 public virtual void Open(string path)
 {
     if (EditorSceneManager.EnsureUntitledSceneHasBeenSaved("You don't have saved the Untitled Scene, Do you want to leave?"))
     {
         EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();
         EditorSceneManager.OpenScene(path, this.openSceneMode);
     }
 }
Пример #3
0
    public static void Build(BuildType buildType)
    {
        if (!EditorSceneManager.EnsureUntitledSceneHasBeenSaved("Scene must be saved before creating build"))
        {
            return;
        }

        BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions()
        {
            scenes  = new[] { EditorSceneManager.GetActiveScene().path },
            options = BuildOptions.ShowBuiltPlayer
        };

        switch (buildType)
        {
        case BuildType.Desktop:
            PrepareDesktopBuild(ref buildPlayerOptions);
            break;

        case BuildType.Android:
            PrepareAndroidBuild(ref buildPlayerOptions);
            break;
        }

        BuildReport  report  = BuildPipeline.BuildPlayer(buildPlayerOptions);
        BuildSummary summary = report.summary;

        if (summary.result == BuildResult.Succeeded)
        {
            Debug.Log("Build succeeded: " + summary.totalSize + " bytes");
        }

        if (summary.result == BuildResult.Failed)
        {
            Debug.Log("Build failed");
        }
    }
Пример #4
0
        public static void CreateMixedRealityToolkitGameObject()
        {
            var startScene = MixedRealityPreferences.StartSceneAsset;

            if (startScene != null)
            {
                if (!EditorUtility.DisplayDialog(
                        title: "Attention!",
                        message: $"It seems you've already set the projects Start Scene to {startScene.name}\n" +
                        "You only need to configure the toolkit once in your Start Scene.\n" +
                        "Would you like to replace your Start Scene with the current scene you're configuring?",
                        ok: "Yes",
                        cancel: "No"))
                {
                    return;
                }
            }

            Selection.activeObject = MixedRealityToolkit.Instance;
            Debug.Assert(MixedRealityToolkit.IsInitialized);
            var playspace = MixedRealityToolkit.Instance.MixedRealityPlayspace;

            Debug.Assert(playspace != null);

            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                Debug.LogWarning("You must save this scene and assign it to the Start Scene in the XRTK preferences for the Mixed Reality Toolkit to function correctly.");
            }

            EditorSceneManager.EnsureUntitledSceneHasBeenSaved("Mixed Reality Start Scene for the Mixed Reality Toolkit to function correctly.");

            Debug.Assert(!string.IsNullOrEmpty(SceneManager.GetActiveScene().path),
                         "Configured Scene must be saved in order to set it as the Start Scene!\n" +
                         "Please save your scene and set it as the Start Scene in the XRTK preferences.");
            MixedRealityPreferences.StartSceneAsset = AssetDatabase.LoadAssetAtPath <SceneAsset>(SceneManager.GetActiveScene().path);
            EditorGUIUtility.PingObject(MixedRealityToolkit.Instance);
        }
        private Scene?OpenNewScene()
        {
            string operation = "Current scene is not saved. Do you want to save it?\n\n(You can disable this prompt in the Tests Runner's options)";

            if (string.IsNullOrEmpty(SceneManager.GetActiveScene().path) && ((operation != "") || !EditorSceneManager.EnsureUntitledSceneHasBeenSaved(operation)))
            {
                EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Single);
                return(null);
            }
            Scene scene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);

            SceneManager.SetActiveScene(scene);
            return(new Scene?(scene));
        }
Пример #6
0
        /// <summary>
        /// Sets up the current scene to be a compatible Liminal Experience App.
        /// </summary>
        public static void SetupAppScene()
        {
            var scene  = SceneManager.GetActiveScene();
            var accept = EditorUtility.DisplayDialog("Setup Experience App Scene",
                                                     string.Format("Setup the current scene ({0}) as your Experience App scene? This will modify the structure of the scene.", scene.name),
                                                     "OK", "Cancel");

            if (!accept)
            {
                return;
            }

            EditorSceneManager.EnsureUntitledSceneHasBeenSaved("You must save the current scene before continuing.");
            EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo();

            // Clear the 'appscene' asset bundle from ALL other assets
            // Only the experience app scene can have this bundle name!
            foreach (var path in AssetDatabase.GetAssetPathsFromAssetBundle("appscene"))
            {
                AssetImporter.GetAtPath(path).SetAssetBundleNameAndVariant(null, null);
            }

            // Make sure this is the only open scene
            scene = EditorSceneManager.OpenScene(scene.path, OpenSceneMode.Single);

            var app = UnityEngine.Object.FindObjectOfType <ExperienceApp>();

            if (app == null)
            {
                app = new GameObject("[ExperienceApp]")
                      .AddComponent <ExperienceApp>();
            }
            else
            {
                // Move to the root
                app.gameObject.name = "[ExperienceApp]";
                app.transform.SetParentAndIdentity(null);
            }

            //attach the experience settings profile to the config if it exists
            app.LimappConfig.ProfileToApply = Resources.Load <ExperienceProfile>("LimappConfig");

            // Ensure the VREmulator is available on the app
            app.gameObject.GetOrAddComponent <VREmulator>();

            // Move all other objects under the ExperienceApp object
            foreach (var obj in scene.GetRootGameObjects())
            {
                if (obj == app.gameObject)
                {
                    continue;
                }

                obj.transform.parent = app.transform;
            }

            // Ensure there is a VRAvatar
            var vrAvatar = UnityEngine.Object.FindObjectOfType <VRAvatar>();

            if (vrAvatar == null)
            {
                var prefabAsset = Resources.Load <VRAvatar>("VRAvatar");
                vrAvatar = (VRAvatar)PrefabUtility.InstantiatePrefab(prefabAsset);
            }

            // Move avatar to the app
            vrAvatar.transform.SetParentAndIdentity(app.transform);
            vrAvatar.transform.SetAsFirstSibling();

            // Disable the cameras tagged with MainCamera if it isn't part of the VRAvatar
            foreach (var camera in UnityEngine.Object.FindObjectsOfType <Camera>())
            {
                if (!camera.transform.IsDescendentOf(vrAvatar.transform))
                {
                    if (camera.CompareTag("MainCamera"))
                    {
                        camera.gameObject.SetActive(false);
                        Debug.LogWarning("MainCamera was disabled. Use VRAvatar/Head/CenterEye as your main camera", camera);
                    }
                }
            }

            Debug.Log("Setup complete! Please ensure that you use the cameras nested under VRAvatar/Head as your VR cameras.");
        }