示例#1
0
    static async Task Loading(Type sceneType)
    {
        string sceneName = sceneType.Name.Replace("Scene", "");

        if (string.IsNullOrEmpty(sceneName))
        {
            GameLog.LogErrorFormat("Failed to load scene {0}({1})", sceneName, sceneType.Name);
            onSceneLoaded = null;
            return;
        }

        await ScreenFader.AsyncFade(true);

        if (null != current)
        {
            current.OnDestroy();
        }
        current = null;
        // UI.Instance.ClosePanelsWhenSceneDestroy();

        await SceneLoader.AsyncLoad(sceneName);

        current = (IScene)Activator.CreateInstance(sceneType);
        current.Start();

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

        await ScreenFader.AsyncFade(false);
    }
 private void OnLoadingScreenHideComplete()
 {
     LoadingScreenController.Instance.OnLoadingScreenHideComplete -= OnLoadingScreenHideComplete;
     _isLoadingScene = false;
     // Debug.Log("Scene load complete!");
     OnSceneLoaded?.Invoke(_nextSceneName);
 }
        /// <summary>
        /// Load the scene in the given ScenePackage.
        /// </summary>
        /// <param name="scenePackage">The ScenePackage to load.</param>
        public IEnumerable <SceneBuildStatus> loadScene(ScenePackage scenePackage, SceneBuildOptions options)
        {
            currentScenePackage = scenePackage;
            yield return(new SceneBuildStatus()
            {
                Message = "Setting up Resources"
            });

            sceneResourceManager.changeResourcesToMatch(scenePackage.ResourceManager);
            sceneResourceManager.initializeResources();

            currentScene = scenePackage.SceneDefinition.createScene();
            if (OnSceneLoading != null)
            {
                OnSceneLoading.Invoke(this, currentScene);
            }
            currentSimObjects = scenePackage.SimObjectManagerDefinition.createSimObjectManager(currentScene.getDefaultSubScene());
            foreach (var status in currentScene.buildSceneStatus(options))
            {
                yield return(status);
            }
            if (OnSceneLoaded != null)
            {
                OnSceneLoaded.Invoke(this, currentScene);
            }
        }
 void Init(OnSceneLoaded e)
 {
     if (!_init)
     {
         _init = true;
         ArrayExtensions.ToList(FindObjectsOfType <Player>(), out _playersArray);
         _player = GetPlayer();
         if (GameManager.Instance.LoadedScene == SceneString.ZoomView)
         {
             StudioListener listener = _player.GetComponent <StudioListener>();
             if (listener)
             {
                 listener.enabled = true;
             }
         }
     }
     else
     {
         ArrayExtensions.ToList(FindObjectsOfType <Player>(), out _playersArray);
         _player = GetPlayer();
         if (GameManager.Instance.LoadedScene == SceneString.ZoomView)
         {
             StudioListener listener = _player.GetComponent <StudioListener>();
             if (listener)
             {
                 listener.enabled = true;
             }
         }
     }
     Events.Instance.Raise(new OnPlayerInitFinish());
 }
示例#5
0
    private IEnumerator LoadSceneAsync(string sceneName)
    {
        Time.timeScale = 1;
        if (SceneTransition.Instance)
        {
            SceneTransition.Instance.FadeIn();
            while (!SceneTransition.isDone)
            {
                yield return(null);
            }
        }

        AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);

        while (!operation.isDone)
        {
            yield return(null);
        }

        OnSceneLoaded?.Invoke(sceneName);

        if (SceneTransition.Instance)
        {
            SceneTransition.Instance.FadeOut();
        }
    }
 private void LoadSceneInstant(string sceneName)
 {
     _isLoadingScene = false;
     SceneManager.LoadScene(sceneName);
     // Debug.Log("Scene load complete!");
     OnSceneLoaded?.Invoke(_nextSceneName);
 }
示例#7
0
        private void InvokeLoadedActions(List <string> sceneNames, SceneType sceneType)
        {
            try
            {
                foreach (string sceneName in sceneNames)
                {  // Announce scenes individually regardless of type
                    OnSceneLoaded?.Invoke(sceneName);
                }

                switch (sceneType)
                {
                case SceneType.Content:
                    // Announce content as a set
                    OnContentLoaded?.Invoke(sceneNames);
                    break;

                case SceneType.Lighting:
                    // We only handle lighting scenes one at a time
                    Debug.Assert(sceneNames.Count == 1);
                    OnLightingLoaded?.Invoke(sceneNames[0]);
                    break;

                default:
                    // Don't announce other types of scenes invidually
                    break;
                }
            }
            catch (Exception e)
            {
                Debug.LogError("Error when attempting to invoke loaded actions for " + string.Join(", ", sceneNames));
                Debug.LogException(e);
            }
        }
    private IEnumerator FadeAndSwitchScenes(string sceneName)
    {
        m_ScreenFader.FadeOut();

        while (m_ScreenFader.IsFading)
        {
            Debug.Log("Fading...");

            yield return(null);
        }

        OnSceneUnload?.Invoke();

        yield return(SceneManager.UnloadSceneAsync(SceneManager.GetActiveScene().buildIndex));

        yield return(StartCoroutine(LoadSceneAndSetActive(sceneName)));

        OnSceneLoaded?.Invoke();

        StateController.Instance.StateMachine.ChangeState(StateController.shop);

        m_ScreenFader.FadeIn();

        while (m_ScreenFader.IsFading)
        {
            Debug.Log("Fading...");

            yield return(null);
        }
    }
示例#9
0
        IEnumerator LoadLevel(string level)
        {
            yield return(SceneManager.LoadSceneAsync(level, LoadSceneMode.Single));

            if (onSceneLoaded != null)
            {
                onSceneLoaded();
                onSceneLoaded = null;
            }
        }
        //+ BEHAVIOUR
        private void Start()
        {
            StartCoroutine(TimedUpdate());

            AmbianceDirector.onAwakeDelegate += dir => OnAmbienceAwake?.Handle(args: new object[] { dir }, unique: true);

            SceneContext.onNextSceneAwake  += cxt => OnNextSceneAwake?.Handle(args: new object[] { cxt }, unique: true);
            SceneContext.onSceneLoaded     += cxt => OnSceneLoaded?.Handle(args: new object[] { cxt }, unique: true);
            SceneContext.beforeSceneLoaded += cxt => BeforeSceneLoaded?.Handle(args: new object[] { cxt }, unique: true);
        }
        public void LoadCurrentSceneActual(OnSceneLoaded callback = null)
        {
            Multiplayer.Room room = GameManagers.GetResourcesManager().currentRoom.value;

            if (!isLoading)
            {
                isLoading = true;
                StartCoroutine(LoadScene(room.sceneName, onSceneLoadedCallback));
            }
        }
 public virtual void OnSceneLoadedInvoke(Scene x)
 {
     if (GameSparksManager.Instance().IsDebug)
     {
         var subs     = OnSceneLoaded?.GetInvocationList();
         var debugStr = "OnSceneLoaded InvokationList: ";
         subs?.ToList().ForEach(m => debugStr += "\n" + m.Method.Name);
         Debug.Log(debugStr);
     }
     OnSceneLoaded?.Invoke(x);
 }
示例#13
0
 void StopEmitter(OnSceneLoaded pEvent)
 {
     if (GameManager.Instance.LoadedScene == SceneString.MapView)
     {
         _emitter.Stop();
     }
     else
     {
         _emitter.Play();
     }
 }
        private IEnumerator LoadScene(string targetLevel, OnSceneLoaded callback = null)
        {
            yield return(SceneManager.LoadSceneAsync(targetLevel, LoadSceneMode.Single));

            isLoading = false;

            if (callback != null)
            {
                callback.Invoke();
            }
        }
 private void SceneManager_OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
 {
     Detach();
     _active = false;
     OnSceneUnloaded?.Invoke();
     if (arg0.buildIndex == SceneBuildIndex)
     {
         Attach(arg0);
         _active = true;
         OnSceneLoaded?.Invoke();
     }
 }
示例#16
0
        private static void SceneLoadedHandler(Scene scene, LoadSceneMode mode)
        {
            if (AllAvailableGameObjectsByScene.ContainsKey(scene.name))
            {
                AllAvailableGameObjectsByScene[scene.name] = scene.GetRootGameObjects();
            }
            else
            {
                AllAvailableGameObjectsByScene.Add(scene.name, scene.GetRootGameObjects());
            }

            OnSceneLoaded?.Invoke(scene.name);
        }
示例#17
0
 private void FinishLoading(Scene scene)
 {
     if (scene.buildIndex != 0)
     {
         if (_isLoaded && _isUnloaded)
         {
             _isLoaded   = false;
             _isUnloaded = false;
             var currentScene = _loadingScene == SceneType.None ? CurrentScene : _loadingScene;
             OnSceneLoaded?.Invoke(this, new SceneLoadedEventArgs(currentScene));
         }
     }
 }
示例#18
0
 /// <summary>
 /// Load scene of specified url
 /// </summary>
 /// <param name="url"></param>
 /// <param name="onSceneLoaded"></param>
 public void LoadSceneAsync(string url, OnSceneLoaded onSceneLoaded)
 {
     if (state == State.Ready)
     {
         StartCoroutine(LoadScene(url, onSceneLoaded));
     }
     else
     {
         if (onSceneLoaded != null)
         {
             onSceneLoaded("Error : Scene state is " + state.ToString());
         }
     }
 }
        private IEnumerator LoadSceneAsync(GameScene scene, bool slowLoad = false)
        {
            _busy = true;

            if (PopupWindow.Opened)
            {
                PopupWindow.Opened.Close();
            }

            var dimmer = slowLoad ? slowDimmer : fastDimmer;

            dimmer.Switch(true);
            yield return(StartCoroutine(dimmer.WaitForSwitchAsync()));

            var loadedScene = GetLoadedScene();

            if (loadedScene != string.Empty)
            {
                yield return(SceneManager.UnloadSceneAsync(loadedScene));
            }

            Time.timeScale = 1;

            if (slowLoad)
            {
                dimmer.StartWaitingForTap();
                yield return(StartCoroutine(dimmer.WaitForTapAsync()));
            }

            yield return(SceneManager.LoadSceneAsync(scene.ToStringName(), LoadSceneMode.Additive));

            if (scene.IsPivot())
            {
                PivotScene = scene;
            }

            if (_hasSceneLoadingConflict)
            {
                _hasSceneLoadingConflict = false;
                StartCoroutine(LoadSceneAsync(_conflictedLoadedScene, true));
                yield break;
            }

            dimmer.Switch(false);
            yield return(StartCoroutine(dimmer.WaitForSwitchAsync()));

            OnSceneLoaded?.Invoke(null, EventArgs.Empty);
            _busy = false;
        }
示例#20
0
        private static void OnCompleteSceneLoad(OWScene oldScene, OWScene newScene)
        {
            DebugLog.DebugWrite($"COMPLETE SCENE LOAD ({oldScene} -> {newScene})", MessageType.Info);
            if (QSBCore.IsInMultiplayer)
            {
                WorldObjectManager.Rebuild(newScene);
            }
            var universe = InUniverse(newScene);

            OnSceneLoaded?.SafeInvoke(newScene, universe);
            if (universe)
            {
                OnUniverseSceneLoaded?.SafeInvoke(newScene);
            }
        }
        void SwitchSnapshot(OnSceneLoaded e)
        {
            Events.Instance.RemoveListener <OnSceneLoaded>(SwitchSnapshot);
            StudioEventEmitter lEmitter;

            int lLength = _emitterArray.Length;
            int lIndex;

            string lStringStart;
            string lStringStop;

            if (e == null)
            {
                for (lIndex = lLength - 1; lIndex >= 0; lIndex--)
                {
                    lEmitter = _emitterArray[lIndex];
                    if (lEmitter.Event.Contains(MAP_VIEW_SNAPSHOT_STRING) || lEmitter.Event.Contains(ZOOM_VIEW_SNAPSHOT_STRING))
                    {
                        lEmitter.Stop();
                    }
                }

                _onMenu = true;
            }
            else
            {
                lStringStart = e.scene == SceneString.MapView ? MAP_VIEW_SNAPSHOT_STRING : ZOOM_VIEW_SNAPSHOT_STRING;
                lStringStop  = e.scene == SceneString.MapView ? ZOOM_VIEW_SNAPSHOT_STRING : MAP_VIEW_SNAPSHOT_STRING;

                for (lIndex = lLength - 1; lIndex >= 0; lIndex--)
                {
                    lEmitter = _emitterArray[lIndex];
                    if (lEmitter.Event.Contains(lStringStart))
                    {
                        lEmitter.Play();
                    }
                    else if (lEmitter.Event.Contains(lStringStop))
                    {
                        lEmitter.Stop();
                    }
                }

                _onMenu = false;
            }
        }
示例#22
0
 public void createScene()
 {
     scene       = sceneDefinition.createScene();
     scene.Scope = pluginManager.GlobalScope.ServiceProvider.CreateScope(); //Disposed in destroyscene
     if (OnSceneLoading != null)
     {
         OnSceneLoading.Invoke(this, scene);
     }
     createSimObjects();
     if (OnSceneLoaded != null)
     {
         OnSceneLoaded.Invoke(this, scene);
     }
     foreach (DebugInterface debugInterface in controller.PluginManager.DebugInterfaces)
     {
         debugInterface.createDebugInterface(controller.PluginManager.RendererPlugin, scene.getDefaultSubScene());
     }
 }
        /// <summary>
        /// Loads a single scene.
        /// </summary>
        /// <param name="scene">The scene to unload.</param>
        /// <param name="onComplete">Optional callback.</param>
        public static void LoadScene(string scene, Action onComplete = null)
        {
            //Block flow if the scene does not exist
            if (!Application.CanStreamedLevelBeLoaded(scene))
            {
                if (LogLevel >= LogType.Less)
                {
                    Debug.LogWarning(Tag + "The scene \"" + scene + "\" cannot be found or does not exist.");
                }
                return;
            }

            AsyncOperation op = SceneManager.LoadSceneAsync(scene);

            op.completed += _ => {
                onComplete?.Invoke();
                OnSceneLoaded?.Invoke(new [] { scene });
            };
        }
示例#24
0
        private void PrepareScene()
        {
            SpawnCamera();
            SpawnWorldUiCanvas();
            sceneSettings = FindObjectOfType <SceneSettings>();
#if (UNITY_EDITOR)
            levelController.StartCurrentEditorLevel();
            if (sceneSettings != null && sceneSettings.levels != null)
            {
                currentLevel = sceneSettings.startLevel;
                levelController.LoadLevel(sceneSettings.GetLevel(currentLevel));
            }
#else
            currentLevel = sceneSettings.startLevel;
            levelController.LoadLevel(sceneSettings.GetLevel(currentLevel));
#endif
            loadingScreen.Hide();
            isLoading = false;
            OnSceneLoaded?.Invoke();
        }
示例#25
0
        /// <summary>
        /// Load the scene in the given ScenePackage.
        /// </summary>
        /// <param name="scenePackage">The ScenePackage to load.</param>
        public IEnumerable <SceneBuildStatus> loadSceneCo(ScenePackage scenePackage, SceneBuildOptions options = SceneBuildOptions.SingleUseDefinitions)
        {
            this.scenePackage = scenePackage;
            yield return(new SceneBuildStatus()
            {
                Message = "Setting up Resources"
            });

            sceneResourceManager.changeResourcesToMatch(scenePackage.ResourceManager);
            sceneResourceManager.initializeResources();

            scene       = scenePackage.SceneDefinition.createScene();
            scene.Scope = pluginManager.GlobalScope.ServiceProvider.CreateScope();
            if (OnSceneLoading != null)
            {
                OnSceneLoading.Invoke(this, scene);
            }
            currentSimObjects = scenePackage.SimObjectManagerDefinition.createSimObjectManager(scene.getDefaultSubScene());
            if (dynamicMode)
            {
                foreach (var status in scene.buildSceneStatus(options))
                {
                    yield return(status);
                }
            }
            else
            {
                scene.buildStaticScene();
            }
            if (OnSceneLoaded != null)
            {
                OnSceneLoaded.Invoke(this, scene);
            }
            foreach (DebugInterface debugInterface in pluginManager.DebugInterfaces)
            {
                debugInterface.createDebugInterface(pluginManager.RendererPlugin, scene.getDefaultSubScene());
            }
        }