IsValid() public method

Whether this is a valid scene. A scene may be invalid if, for example, you tried to open a scene that does not exist. In this case, the scene returned from EditorSceneManager.OpenScene would return False for IsValid.

public IsValid ( ) : bool
return bool
 private IEnumerator _UnloadCurrentUIScene()
 {
     if (currentUIScene.IsValid() && currentSceneBase != null)
     {
         yield return(currentSceneBase.Out());
     }
 }
    public IEnumerator _PopUIScene(int depth = 1)
    {
        UnityEngine.SceneManagement.Scene beforeScene = currentUIScene;
        SceneBase beforeSceneBase = currentSceneBase;

        if (currentUIScene.IsValid() && beforeSceneBase != null)
        {
            beforeSceneBase.SetSortingOrderCanvas(12);
        }
        currentUIScene   = new UnityEngine.SceneManagement.Scene();
        currentSceneBase = null;
        for (int i = 0; i < depth; i++)
        {
            uiSceneNameList.RemoveAt(uiSceneNameList.Count - 1);
        }
        string         sceneName = uiSceneNameList[uiSceneNameList.Count - 1];
        AsyncOperation oparation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);

        do
        {
            yield return(null);
        } while (oparation.isDone == false);
        if (beforeScene.IsValid() && beforeSceneBase != null)
        {
            beforeSceneBase.SetSortingOrderCanvas(11);
            StartCoroutine(beforeSceneBase.PopOut());
        }
        currentUIScene = GetSceneBySceneName(sceneName);
        if (currentUIScene.IsValid())
        {
            currentUISceneName = sceneName;
            currentSceneBase   = GetSceneBase(currentUIScene);
            if (currentSceneBase != null)
            {
                currentSceneBase.SetSortingOrderCanvas(12);
                yield return(currentSceneBase.PopIn());
            }
        }
        yield return(null);

        if (beforeScene.IsValid())
        {
            AsyncOperation oparation2 = UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(beforeScene);
            do
            {
                yield return(null);
            } while (oparation2.isDone == false);
        }
        IsLoadingUIScene = false;
    }
    public IEnumerator _ReplaceUIScene(string sceneName)
    {
        UnityEngine.SceneManagement.Scene beforeScene = currentUIScene;
        SceneBase beforeSceneBase = currentSceneBase;

        if (currentUIScene.IsValid() && beforeSceneBase != null)
        {
            beforeSceneBase.SetSortingOrderCanvas(12);
        }
        currentUIScene   = new UnityEngine.SceneManagement.Scene();
        currentSceneBase = null;
        uiSceneNameList.Clear();
        if (beforeScene.IsValid() && beforeSceneBase != null)
        {
            beforeSceneBase.SetSortingOrderCanvas(11);
            yield return(beforeSceneBase.Out());
        }
        if (beforeScene.IsValid())
        {
            AsyncOperation oparation2 = UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(beforeScene);
            do
            {
                yield return(null);
            } while (oparation2.isDone == false);
        }
        beforeUiSceneName = null;
        AsyncOperation oparation = UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(sceneName, UnityEngine.SceneManagement.LoadSceneMode.Additive);

        do
        {
            yield return(null);
        } while (oparation.isDone == false);
        yield return(null);

        currentUIScene = GetSceneBySceneName(sceneName);
        if (currentUIScene.IsValid())
        {
            currentUISceneName = sceneName;
            currentSceneBase   = GetSceneBase(currentUIScene);
            uiSceneNameList.Add(sceneName);
            if (currentSceneBase != null)
            {
                currentSceneBase.SetSortingOrderCanvas(12);
                yield return(currentSceneBase.In());
            }
        }
        yield return(null);

        IsLoadingUIScene = false;
    }
    public void OnGUI()
    {
        // Create a button for each scene.
        //GUI.BeginGroup(new Rect(Screen.width/2 - 150, Screen.height/2, 300, 500));
        GUILayout.BeginHorizontal(GUILayout.Width(1000));
        int i            = 0;
        int maxPerColumn = 6;

        while (i < scenes.Scenes.Count)
        {
            GUILayout.BeginVertical("box", w);
            for (int j = 0; j < maxPerColumn && i < scenes.Scenes.Count; j++)
            {
                if (GUILayout.Button(scenes.Scenes[i].Name, w, h))
                {
                    Debug.Log("=========================================================");
                    Debug.Log("Loading level: " + scenes.Scenes[i].Path);
                    UnityEngine.SceneManagement.Scene sc = SceneManager.GetSceneByName(scenes.Scenes[i].Path);
                    if (sc.IsValid())
                    {
                        SceneManager.LoadScene(i);
                    }
                    else
                    {
                        Debug.LogErrorFormat("The scene {0} needs to be added in the Build Settings before it can be accessed from the ExampleMenu. Try opening the scene in the editor.", scenes.Scenes[i].Path);
                    }
                }
                i++;
            }
            GUILayout.EndVertical();
        }
        GUILayout.EndHorizontal();
        //GUI.EndGroup();
    }
Example #5
0
        void Syncwithevents()
        {
            this.framework.InitFrameWorkModuldes(this);
#if UNITY_EDITOR
            UnityEngine.SceneManagement.Scene scene = EditorSceneManager.GetActiveScene();
            if (scene.IsValid())
            {
                this._tryCall(MainLoopEvent.OnLevelWasLoaded, scene.buildIndex);
            }
            else
            {
                this._tryCall(MainLoopEvent.OnLevelWasLoaded, 0);
            }
#else
            this._tryCall(MainLoopEvent.OnLevelWasLoaded, 0);
#endif

            if (FrameWorkDoneEvent != null)
            {
                FrameWorkDoneEvent();
            }

            FrameWorkDoneEvent = null;

            this._tryCall(MainLoopEvent.Start);
        }
Example #6
0
    RoomDefinition SceneToRoom(UnityEngine.SceneManagement.Scene scene)
    {
        if (!scene.IsValid())
        {
            return(null);
        }
        if (config == null)
        {
            throw new NullReferenceException("GameManager config is null; can't resolve room scene");
        }
        if (config.roomConfiguration == null)
        {
            throw new NullReferenceException("GameManager room configuration is null; can't resolve room scene");
        }
        if (config.roomConfiguration.rooms == null || config.roomConfiguration.rooms.Length == 0)
        {
            UnityEngine.Debug.LogError("Config/RoomConfiguration exists for GameManager, but there are no RoomDefinitions set up in it");
            return(null);
        }

        var ret = config.roomConfiguration.rooms.FirstOrDefault(rm => scene.path.Contains(rm.scenePath) || string.Equals(scene.path, rm.scenePath, StringComparison.InvariantCultureIgnoreCase));

        if (ret == null)
        {
            UnityEngine.Debug.LogError("We are starting in a scene which is not normally accessible via the current RoomConfiguration. Scene-transitioning logic may be unavailable.");
        }
        return(ret);
    }
Example #7
0
    private static List <GameObject> GetDontDestroyOnLoadRoots()
    {
        List <GameObject> objs = new List <GameObject>();

        if (Application.isPlaying)
        {
            GameObject temp = null;
            try
            {
                temp = new GameObject();
                DontDestroyOnLoad(temp);
                UnityEngine.SceneManagement.Scene dontDestryScene = temp.scene;
                DestroyImmediate(temp);
                temp = null;

                if (dontDestryScene.IsValid())
                {
                    objs = dontDestryScene.GetRootGameObjects().ToList();
                }
            }
            catch (System.Exception e)
            {
                Debug.LogException(e);
                return(null);
            }
            finally
            {
                if (temp != null)
                {
                    DestroyImmediate(temp);
                }
            }
        }
        return(objs);
    }
Example #8
0
 public void LoadLevel(string scene)
 {
     if (currentScene.IsValid())
     {
         UnityEngine.SceneManagement.SceneManager.UnloadSceneAsync(currentScene);
     }
     if (!string.IsNullOrEmpty(scene))
     {
         UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(scene, UnityEngine.SceneManagement.LoadSceneMode.Additive);
         currentScene = UnityEngine.SceneManagement.SceneManager.GetSceneAt(UnityEngine.SceneManagement.SceneManager.sceneCount - 1);
         ui.enabled   = false;
     }
     else
     {
         currentScene = default;
         ui.enabled   = true;
     }
 }
Example #9
0
        private void EnablePickingNoUndo(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.EnablePicking(scene);
        }
        public void Hide(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            Undo.RecordObject(SceneVisibilityState.GetInstance(), "Hide Scene");
            Hide(scene, true);
        }
Example #11
0
    public void BuildCheck()
    {
        UnityEngine.SceneManagement.Scene scene = EditorSceneManager.OpenScene("Assets/BridgeExample/Scenes/MR Example.unity");
        Assert.That(scene.IsValid());

        var buildScene = new EditorBuildSettingsScene(scene.path, true);

        EditorBuildSettings.scenes = new EditorBuildSettingsScene[] { buildScene };
        Assert.That(EditorBuildSettings.scenes.Length == 1);
    }
Example #12
0
        public void EnablePicking(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            Undo.RecordObject(SceneVisibilityState.GetInstance(), "Enable Picking Scene");
            EnablePicking(scene, true);
        }
Example #13
0
        public void DisablePicking(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            Undo.RecordObject(SceneVisibilityState.GetInstance(), "Disable Picking Scene");
            DisablePickingNoUndo(scene);
        }
Example #14
0
        private void HideNoUndo(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.ShowScene(scene);
            SceneVisibilityState.SetGameObjectsHidden(scene.GetRootGameObjects(), true, true);
        }
Example #15
0
        internal void DisablePickingNoUndo(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.EnablePicking(scene);
            SceneVisibilityState.SetGameObjectsPickingDisabled(scene.GetRootGameObjects(), true, true);
        }
Example #16
0
        public IEnumerator UnitySetUp()
        {
            const string mainScenePath = "Assets/SampleNoLevels.Tests/MainSceneNoLevelsForTesting.unity";

            FileAssert.Exists(mainScenePath);
            loadedScene = EditorSceneManager.LoadSceneInPlayMode(mainScenePath,
                                                                 new LoadSceneParameters(LoadSceneMode.Additive, LocalPhysicsMode.Physics3D));

            Assert.True(loadedScene.IsValid());
            yield return(null);

            Assert.True(SceneManager.SetActiveScene(loadedScene));
        }
Example #17
0
        private void EnablePicking(Scene scene, bool sendContentChangedEvent)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.EnablePicking(scene);

            if (sendContentChangedEvent)
            {
                PickableContentChanged();
            }
        }
        private void Show(Scene scene, bool sendContentChangedEvent)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.ShowScene(scene);

            if (sendContentChangedEvent)
            {
                VisibilityChanged();
            }
        }
Example #19
0
        public void Show(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            if (!scene.isLoaded)
            {
                return;
            }

            Undo.RecordObject(SceneVisibilityState.GetInstance(), "Show Scene");
            Show(scene, true);
        }
        private void Hide(Scene scene, bool sendContentChangedEvent)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.ShowScene(scene);
            SceneVisibilityState.SetGameObjectsHidden(scene.GetRootGameObjects(), true, true);

            if (sendContentChangedEvent)
            {
                VisibilityChanged();
            }
        }
Example #21
0
        internal void DisablePicking(Scene scene, bool sendContentChangedEvent)
        {
            if (!scene.IsValid())
            {
                return;
            }

            SceneVisibilityState.EnablePicking(scene);
            SceneVisibilityState.SetGameObjectsPickingDisabled(scene.GetRootGameObjects(), true, true);

            if (sendContentChangedEvent)
            {
                PickableContentChanged();
            }
        }
Example #22
0
 public static int IsValid_wrap(long L)
 {
     try
     {
         long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);
         UnityEngine.SceneManagement.Scene obj = get_obj(nThisPtr);
         bool ret     = obj.IsValid();
         long ret_ptr = FCLibHelper.fc_get_return_ptr(L);
         FCLibHelper.fc_set_value_bool(ret_ptr, ret);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
     return(0);
 }
 static int IsValid(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 1);
         UnityEngine.SceneManagement.Scene obj = (UnityEngine.SceneManagement.Scene)ToLua.CheckObject(L, 1, typeof(UnityEngine.SceneManagement.Scene));
         bool o = obj.IsValid();
         LuaDLL.lua_pushboolean(L, o);
         ToLua.SetBack(L, 1, obj);
         return(1);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Example #24
0
        internal void DisablePickingNoUndo(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            if (!scene.isLoaded)
            {
                return;
            }

            SceneVisibilityState.EnablePicking(scene);
            scene.GetRootGameObjects(m_RootBuffer);
            SceneVisibilityState.SetGameObjectsPickingDisabled(m_RootBuffer.ToArray(), true, true);
        }
Example #25
0
 public GameObject GetSceneRoot(string sceneName)
 {
     UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(sceneName);
     if (scene != null && scene.IsValid() && scene.isLoaded)
     {
         GameObject[] objs = scene.GetRootGameObjects();
         foreach (var item in objs)
         {
             if (item.name.Equals(sceneName))
             {
                 return(item);
             }
         }
     }
     return(null);
 }
Example #26
0
        private void HideNoUndo(Scene scene)
        {
            if (!scene.IsValid())
            {
                return;
            }

            if (!scene.isLoaded)
            {
                return;
            }

            SceneVisibilityState.ShowScene(scene);
            scene.GetRootGameObjects(m_RootBuffer);
            SceneVisibilityState.SetGameObjectsHidden(m_RootBuffer.ToArray(), true, true);
        }
    public void OnGUI()
    {
        UnityEngine.SceneManagement.Scene sc = SceneManager.GetSceneByName("ExampleMenu");
        if (sc.IsValid())
        {
            GUI.BeginGroup(new Rect(Screen.width - 150, Screen.height - 40, 300, 400));
            GUILayout.BeginVertical("box", GUILayout.Width(150));

            if (GUILayout.Button("Back"))
            {
                SceneManager.LoadScene(0);
            }

            GUILayout.EndVertical();
            GUI.EndGroup();
        }
    }
Example #28
0
 bool GetSceneSetState(string sceneName, bool activity)
 {
     UnityEngine.SceneManagement.Scene scene = UnityEngine.SceneManagement.SceneManager.GetSceneByName(sceneName);
     if (scene != null && scene.IsValid() && scene.isLoaded)
     {
         GameObject[] objs = scene.GetRootGameObjects();
         if (objs != null)
         {
             foreach (var obj in objs)
             {
                 obj.SetActive(activity);
             }
         }
         return(true);
     }
     return(false);
 }
        static void SaveAll()
        {
            UnityEngine.SceneManagement.Scene sc = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
            if (!sc.IsValid())
            {
                return;
            }

            SceneConfig data = new SceneConfig();

            data.Data.LevelName = sc.name;

            GameObject[] array = GameObject.FindGameObjectsWithTag(SERIALIZE_SCENE_OBJECT_TAG);
            if (array == null)
            {
                return;
            }

            for (int i = 0; i < array.Length; ++i)
            {
                UnityEngine.Object parentObject = PrefabUtility.GetPrefabParent(array[i]);
                string             path         = AssetDatabase.GetAssetPath(parentObject);
                if (string.IsNullOrEmpty(path))
                {
                    continue;
                }

                var transform = array[i].transform;
                var parent    = transform.parent;

                //写入数据
                var obj = new SceneConfigData.SceneObject();
                obj.AssetName  = path;
                obj.Position   = transform.position;
                obj.Scale      = transform.lossyScale;
                obj.Rotation   = transform.rotation;
                obj.ParentName = parent != null?
                                 Common.CalcTransformHierarchyPath(parent) : "";

                data.Data.SceneObjects.Add(obj);
            }

            data.Save(SceneConfig.GetSceneConfigPath(sc.path));
            AssetDatabase.Refresh();
        }
Example #30
0
        protected override void OnDrawForm(int id)
        {
            m_ScrollPos = GUILayout.BeginScrollView(m_ScrollPos);
            {
                Label(GetString("Scene Count"), SceneManager.sceneCount.ToString());
                Label(GetString("Scene Count In Build Settings"), SceneManager.sceneCountInBuildSettings.ToString());

                UnityEngine.SceneManagement.Scene activeScene = SceneManager.GetActiveScene();
                Label(GetString("Active Scene Name"), activeScene.name);
                Label(GetString("Active Scene Path"), activeScene.path);
                Label(GetString("Active Scene Build Index"), activeScene.buildIndex.ToString());
                Label(GetString("Active Scene Is Dirty"), activeScene.isDirty.ToString());
                Label(GetString("Active Scene Is Loaded"), activeScene.isLoaded.ToString());
                Label(GetString("Active Scene Is Valid"), activeScene.IsValid().ToString());
                Label(GetString("Active Scene Root Count"), activeScene.rootCount.ToString());
            }
            GUILayout.EndScrollView();
        }
 public static bool IsSceneHeaderInHierarchyWindow(Scene scene)
 {
   return scene.IsValid();
 }
		/// <summary>
		/// This is a co-routine for waiting until a given scene is loaded, then performing a cross-scene reference resolve
		/// </summary>
		/// <param name="scene">The scene to guarantee loaded</param>
		System.Collections.IEnumerator	CoWaitForSceneLoadThenResolveReferences( Scene scene )
		{
			if ( !Application.isPlaying )
			{
				Debug.LogErrorFormat( this, "CoWaitForSceneLoadThenResolveReferences called, but we're not playing. Co-routines do not work reliably in the Editor!" );
				yield break;
			}

			if ( !scene.IsValid() )
				yield break;

			while ( !scene.isLoaded )
				yield return null;

			ResolvePendingCrossSceneReferences();
		}