Beispiel #1
0
    public static void ViewDestinationPortal(string scenePath, int destinationId)
    {
        // Check if we are already in the scene
        bool inSceneAlready = SceneManager.GetActiveScene().path == scenePath ||
                              SceneManager.GetSceneByPath(scenePath).IsValid();

        if (!inSceneAlready)
        {
            // Require that modified scenes be saved before proceeding
            if (!EditorSceneManager.SaveCurrentModifiedScenesIfUserWantsTo())
            {
                return;
            }

            Scene nextScene = EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single);
            if (!nextScene.IsValid())
            {
                Debug.LogError("Could not find scene asset \"" + scenePath + "\"");
                return;
            }
        }

        PortalComponent destination = PortalComponentCache.GetPortal(destinationId);

        if (destination == null)
        {
            Debug.LogError("Could not find the portal with id = " + destinationId + " in \"" + scenePath + "\"");
            return;
        }

        Selection.activeGameObject = destination.gameObject;
        SceneView.FrameLastActiveSceneView();
    }
 private void OnDrawGizmos()
 {
     GizmosUtils.DrawText(GUI.skin, " " + id, transform.position + Vector3.down * 1.5f, Color.yellow, 16, 0);
     if (destinationScene.ScenePath == this.gameObject.scene.path)
     {
         PortalComponent destinationPortalRef = PortalComponentCache.GetPortal(destinationId);
         if (destinationPortalRef != null)
         {
             GizmosUtils.DrawArrow(transform.position, destinationPortalRef.transform.position, Color.yellow, 2.0f);
         }
     }
     else if (destinationScene.ScenePath != string.Empty)
     {
         Gizmos.color = Color.yellow;
         Gizmos.DrawWireSphere(transform.position, 0.7f);
         Gizmos.DrawWireSphere(transform.position, 0.5f);
     }
 }
    private IEnumerator TeleportOperation(string scenePath, int id, Scene[] scenesToUnload)
    {
        // Exit early if scene cannot be found in build settings
        if (SceneUtility.GetBuildIndexByScenePath(scenePath) == -1)
        {
            Debug.LogError("The scene " + scenePath + " could not be found in the build settings. This error happens fairly often and can be fixed easily. Just clear all scenes from your build setting, and drag the scenes back into the build settings.");
            teleporting = false;
            yield break;
        }

        if (OnTeleportStart != null)
        {
            OnTeleportStart(scenePath);
        }

        // Change scenes if necessary
        if (SceneManager.GetActiveScene().path != scenePath)
        {
            // Start scene operations for loading the next scene and unloading the specified scenes
            List <AsyncOperation> sceneOperations = new List <AsyncOperation> ();
            if (scenesToUnload != null)
            {
                foreach (Scene s in scenesToUnload)
                {
                    sceneOperations.Add(SceneManager.UnloadSceneAsync(s));
                }
            }

            // Load next scene
            AsyncOperation nextSceneLoad = SceneManager.LoadSceneAsync(scenePath, LoadSceneMode.Additive);
            nextSceneLoad.allowSceneActivation = false;

            // Wait for all scene operations to finish
            foreach (AsyncOperation s in sceneOperations)
            {
                yield return(new WaitUntil(() => s.isDone));
            }

            // Wait for next scene to finish loading
            yield return(new WaitUntil(() => nextSceneLoad.progress >= 0.9f));

            // Wait until scene activation is allowed
            yield return(new WaitUntil(() => allowSceneActivation));

            // Activate next scene
            nextSceneLoad.allowSceneActivation = true;
            yield return(new WaitUntil(() => nextSceneLoad.isDone));

            SceneManager.SetActiveScene(SceneManager.GetSceneByPath(scenePath));
        }

        PortalComponent exitPortal = PortalComponentCache.GetPortal(id);

        if (exitPortal == null)
        {
            Debug.LogError("Could not find destination portal with id = " + id + " in scene \"" + SceneManager.GetActiveScene().path + "\"");
        }
        else
        {
            exitPortal.Exit();
        }

        teleporting = false;

        if (OnTeleportFinish != null)
        {
            OnTeleportFinish(scenePath);
        }
    }