public void Unload()
    {
        GameObject.DestroyImmediate(_loadedScreenCache._duplicateScreen);

        LoadedScreenCache cache = GameObject.FindObjectOfType <LoadedScreenCache>();

        if (cache != null)
        {
            GameObject.DestroyImmediate(cache.gameObject);
        }

        SceneManager.UnloadSceneAsync(_scene);
    }
    public LoadedScreen(LoadedScreenCache loadedScreenCache)
    {
        _loadedScreenCache = loadedScreenCache;

        _scene           = SceneManager.GetSceneByPath(loadedScreenCache.scenePath);
        _duplicateScreen = GameObject.FindObjectOfType <ScreenView>().gameObject;

        if (_scene.isLoaded)
        {
            foreach (GameObject rootObject in _scene.GetRootGameObjects())
            {
                _screenController = rootObject.GetComponent <ScreenView>();

                if (_screenController != null)
                {
                    break;
                }
            }
        }
    }
    public void OnGUI()
    {
        if (_loadedScreenCache == null && !hasSearchedForCache)
        {
            _loadedScreenCache  = GameObject.FindObjectOfType <LoadedScreenCache>();
            hasSearchedForCache = true;

            if (_loadedScreenCache != null)
            {
                _loadedScreen = new LoadedScreen(_loadedScreenCache);
            }
        }

        if (_loadedScreen == null)
        {
            OnSceneListGUI();
        }
        else
        {
            OnLoadedScreenGUI(_loadedScreen);
        }
    }
    private void ImportScene(string path)
    {
        WindowView windowController = GameObject.FindObjectOfType <WindowView>();

        if (windowController == null)
        {
            Debug.LogError("WindowController not found in scene.");
            return;
        }

        Scene      scene            = EditorSceneManager.OpenScene(path, UnityEditor.SceneManagement.OpenSceneMode.Additive);
        Scene      activeScene      = EditorSceneManager.GetActiveScene();
        ScreenView screenController = null;

        //EditorSceneManager.MergeScenes(scene, activeScene);

        GameObject[] rootObjects = scene.GetRootGameObjects();

        foreach (GameObject rootObject in rootObjects)
        {
            screenController = rootObject.GetComponent <ScreenView>();

            if (screenController != null)
            {
                break;
            }
        }

        if (screenController == null)
        {
            Debug.LogError("ScreenController not found in loaded scene. ");
            SceneManager.UnloadSceneAsync(scene);
            return;
        }
        else
        {
            if (_loadedScreenCache == null)
            {
                GameObject cache = new GameObject("Cache");
                _loadedScreenCache = cache.AddComponent <LoadedScreenCache>();
            }

            _loadedScreen = new LoadedScreen(scene, screenController, _loadedScreenCache);
            GameObject duplicateScreen = _loadedScreen.GetDuplicateScreen();
            duplicateScreen.transform.SetParent(windowController.transform, false);

            RectTransform rectTransform = duplicateScreen.GetComponent <RectTransform>();

            if (rectTransform)
            {
                rectTransform.anchorMin = Vector2.zero;
                rectTransform.anchorMax = Vector2.one;
                rectTransform.offsetMax = Vector2.zero;
                rectTransform.offsetMin = Vector2.zero;

                rectTransform.hasChanged = false;
            }

            _loadedScreenCache.scenePath        = scene.path;
            _loadedScreenCache._duplicateScreen = duplicateScreen;

            screenController.gameObject.SetActive(false);
        }
    }
 public LoadedScreen(Scene scene, ScreenView screenController, LoadedScreenCache loadedScreenCache)
 {
     _scene             = scene;
     _screenController  = screenController;
     _loadedScreenCache = loadedScreenCache;
 }