예제 #1
0
        IEnumerator Loadcubemap(FolderAssist.FileInfo file)
        {
            Console.WriteLine("Load cubemap: " + file.FileName);
            yield return(null);

            IsLoading = true;

            if (asyncLoad)
            {
                AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(file.FullPath);
                yield return(assetBundleCreateRequest);

                AssetBundle        cubemapbundle  = assetBundleCreateRequest.assetBundle;
                AssetBundleRequest bundleRequest1 = assetBundleCreateRequest.assetBundle.LoadAssetAsync <Material>("skybox-bg");
                yield return(bundleRequest1);

                Skybox.Skyboxbg = bundleRequest1.asset as Material;
                AssetBundleRequest bundleRequest2 = assetBundleCreateRequest.assetBundle.LoadAssetAsync <Material>("skybox");
                yield return(bundleRequest2);

                Skybox.Skybox = bundleRequest2.asset as Material;
                cubemapbundle.Unload(false);
                cubemapbundle            = null;
                bundleRequest1           = null;
                bundleRequest2           = null;
                assetBundleCreateRequest = null;
            }
            else
            {
                AssetBundle cubemapbundle = AssetBundle.LoadFromFile(file.FullPath);
                Skybox.Skyboxbg = cubemapbundle.LoadAsset <Material>("skybox-bg");
                Skybox.Skybox   = cubemapbundle.LoadAsset <Material>("skybox");
                cubemapbundle.Unload(false);
                cubemapbundle = null;
            }
            if (Skybox.Skyboxbg == null)
            {
                Skybox.Skyboxbg = Skybox.Skybox;
            }

            Skybox.ApplySkybox();
            Skybox.ApplySkyboxParams();
            EnvironmentUpdateFlag = true;
            Resources.UnloadUnusedAssets();
            IsLoading = false;
            //ModPrefs.SetString("PHIBL", "LastLoadedCubeMap", file.FileName);
            yield break;
        }
예제 #2
0
        IEnumerator LoadScene(FolderAssist.FileInfo file, bool unloadOldScene = false, int variant = 0)
        {
            IsLoading = true;
            //DisableLightMap(true);
            if (StudioMode)
            {
                var scene = Studio.Scene.Instance;

                while (true)
                {
                    Console.WriteLine("Added scene name: " + scene.addSceneName);
                    if (scene.addSceneName == string.Empty)
                    {
                        break;
                    }
                    scene.UnLoad();
                }
            }
            deferredShading.InitDeferredShading(Camera.main);
            AssetBundle AB;

            if (asyncLoad)
            {
                AssetBundleCreateRequest assetBundleCreateRequest = AssetBundle.LoadFromFileAsync(file.FullPath);
                yield return(assetBundleCreateRequest);

                AB = assetBundleCreateRequest.assetBundle;
            }
            else
            {
                AB = AssetBundle.LoadFromFile(file.FullPath);
            }
            scenePaths   = AB.GetAllScenePaths();
            SceneVariant = 0;
            if (!unloadOldScene)
            {
                RootGOs = SceneManager.GetActiveScene().GetRootGameObjects();
                foreach (var GO in RootGOs)
                {
                    Console.WriteLine("Root Gameobject: " + GO.name);
                    DontDestroyOnLoad(GO);
                    //SceneManager.MoveGameObjectToScene(GO, newscene);
                }
            }

            if (asyncLoad)
            {
                var asyncOperation = SceneManager.LoadSceneAsync(scenePaths[variant], LoadSceneMode.Single);
                asyncOperation.allowSceneActivation = false;

                while (!asyncOperation.isDone)
                {
                    yield return(null);

                    if (asyncOperation.progress > 0.899f && !asyncOperation.allowSceneActivation)
                    {
                        if (SceneManager.GetActiveScene().buildIndex != -1)
                        {
                            foreach (var l in defaultLights)
                            {
                                if (l.name == "CharaLight_back")
                                {
                                    l.GetComponent <AlloyAreaLight>().Intensity = 0f;
                                }
                                else
                                {
                                    l.enabled = false;
                                }
                            }
                            var map = FindObjectOfType <Map>();
                            if (null != map)
                            {
                                GlobalData.showMap = false;
                                map.ChangeShow();
                            }
                        }
                        asyncOperation.allowSceneActivation = true;
                    }
                }
            }
            else
            {
                if (SceneManager.GetActiveScene().buildIndex != -1)
                {
                    foreach (var l in defaultLights)
                    {
                        if (l.name == "CharaLight_back")
                        {
                            l.GetComponent <AlloyAreaLight>().Intensity = 0f;
                        }
                        else
                        {
                            l.enabled = false;
                        }
                    }
                }
                SceneManager.LoadScene(scenePaths[variant], LoadSceneMode.Single);
                var map = FindObjectOfType <Map>();
                if (null != map)
                {
                    GlobalData.showMap = false;
                    map.ChangeShow();
                }
                SceneManager.SetActiveScene(SceneManager.GetSceneByPath(scenePaths[variant]));
            }


            if (unloadOldScene)
            {
                Scenebundle.Unload(true);
            }
            Scenebundle = AB;
            if (StudioMode)
            {
                var bg = FindObjectOfType <Studio.BackgroundCtrl>();
                bg.isVisible           = false;
                bg.enabled             = false;
                Camera.main.clearFlags = CameraClearFlags.Skybox;
            }
            Camera.main.GetOrAddComponent <FlareLayer>().enabled = true;
            Camera.main.GetComponent <Skybox>().enabled          = false;
            probeComponent.enabled = false;
            RendererSetup.SetupProbes();
            //EnvironmentUpdateFlag = true;
            Resources.UnloadUnusedAssets();
            IsLoading        = false;
            PPCtrl.enableFog = RenderSettings.fog;
            CloneSceneRenderSettings();
            LightsInit();
            ReflectionProbeChangeMode(rpRate);
            yield break;
        }