Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

using System.IO;

using Photon.Pun;

using Photon.VR;

using UnityEngine;

using UnityEngine.SceneManagement;

public class SBASceneSwitcher : MonoBehaviour

{

    public string sceneToLoad;

    public string handTag;

    private void OnTriggerEnter(Collider other)

    {

        if (other.CompareTag(this.handTag))

        {

            this.SwitchSceneProperly();

            return;

        }

    }

    private void SwitchSceneProperly()

    {

        if (this.IsSceneInBuildSettings(this.sceneToLoad))

        {

            if (PhotonVRManager.<Manager>k__BackingField != null)

            {

                PhotonNetwork.Disconnect();

                Object.Destroy(PhotonVRManager.<Manager>k__BackingField.gameObject);

            }

            SceneManager.LoadScene(this.sceneToLoad);

            return;

        }

        Debug.LogError(string.Concat("Scene \'", this.sceneToLoad, "\' is NOT in Build Settings!"));

    }

    private bool IsSceneInBuildSettings(string sceneName)

    {

        int sceneCountInBuildSettings = SceneManager.sceneCountInBuildSettings;

        if (sceneCountInBuildSettings >= 1)

        {

            int num2;

            int num;

            for (num = 0; Path.GetFileNameWithoutExtension(SceneUtility.GetScenePathByBuildIndex(num)) != sceneName; num = num2)

            {

                num2 = (num + 1);

                if (sceneCountInBuildSettings == num2)

                {

                    return false;

                }

            }

            return true;

        }

        return false;

    }

    public SBASceneSwitcher()

    {

        this.handTag = "Hand";

        base();

    }

}