Adding Loading Screen (ARPG Kit)

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
warlockoo1
Posts: 15
Joined: Thu Feb 02, 2017 2:47 am

Adding Loading Screen (ARPG Kit)

Post by warlockoo1 »

Hello,
So I want to add loading screen when users loads the game. I have made the script for it, but for that I have to call new function to load the level which is "SceneController.LoadLevel ("Level1")". But as Dialogue Manager uses "levelManager.LoadGame(saveData)" for directly loading data and it is precompiled so is there any way to use my function for loading level without extracting source code of Dialogue System?

Thanks
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding Loading Screen (ARPG Kit)

Post by Tony Li »

To use a loading scene, can you write a wrapper similar to how the Menu Framework's loading scene works?

You can download the Menu Framework from the Dialogue System Extras page or check out the manual here.
The loading scene information is on page 4.

If that doesn't work for your needs, you can replicate what LevelManager.LoadGame() does by writing a coroutine similar to this:

Code: Select all

IEnumerator LoadGame(string saveData) {
    // Get name of saved level to load:
    string levelName = string.Empty;
    if (string.IsNullOrEmpty(saveData)) {
        DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
    } else {
        Lua.Run(saveData, true);
        levelName = DialogueLua.GetVariable("SavedLevelName").AsString;
    }
    if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil"))
        levelName = FindObjectOfType<LevelManager>().defaultStartingLevel    
    
    // Load level:
    PersistentDataManager.LevelWillBeUnloaded();
    var async = Tools.LoadLevelAsync(levelName);
    while (!async.isDone) {
        yield return null;
    }

    // Wait for objects to finish their Start() methods, then apply save data:
    yield return null;
    PersistentDataManager.ApplySaveData(saveData);
    DialogueManager.SendUpdateTracker();
}
warlockoo1
Posts: 15
Joined: Thu Feb 02, 2017 2:47 am

Re: Adding Loading Screen (ARPG Kit)

Post by warlockoo1 »

Sorry for late reply, so I added loading screen scene to this code, loading screen appears but after that only character spawns and level 1 doesn't load.

Code: Select all

IEnumerator LoadGame(string saveData) {
    // Get name of saved level to load:
    string levelName = string.Empty;
    if (string.IsNullOrEmpty(saveData)) {
        DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
    } else {
        Lua.Run(saveData, true);
        levelName = DialogueLua.GetVariable("SavedLevelName").AsString;
    }
    if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil"))
        levelName = FindObjectOfType<LevelManager>().defaultStartingLevel    
    
    // Load level:
    PersistentDataManager.LevelWillBeUnloaded();
    var async = Tools.LoadLevelAsync(levelName);
    while (!async.isDone) {
        SceneManager.LoadLevelAsync("LoadingScene");
        yield return null;
    }

    // Wait for objects to finish their Start() methods, then apply save data:
    yield return null;
    PersistentDataManager.ApplySaveData(saveData);
    DialogueManager.SendUpdateTracker();
}
User avatar
Tony Li
Posts: 22062
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding Loading Screen (ARPG Kit)

Post by Tony Li »

Hi!

Try this:

Code: Select all

IEnumerator LoadGame(string saveData) {
    // Get name of saved level to load:
    string levelName = string.Empty;
    if (string.IsNullOrEmpty(saveData)) {
        DialogueManager.ResetDatabase(DatabaseResetOptions.RevertToDefault);
    } else {
        Lua.Run(saveData, true);
        levelName = DialogueLua.GetVariable("SavedLevelName").AsString;
    }
    if (string.IsNullOrEmpty(levelName) || string.Equals(levelName, "nil"))
        levelName = FindObjectOfType<LevelManager>().defaultStartingLevel    
    
    // Load the LoadingScene:
    PersistentDataManager.LevelWillBeUnloaded();
    var async = Tools.LoadLevelAsync("LoadingScene");
    while (!async.isDone) {
        yield return null;
    }
    
    // Then load the gameplay level:
    async = Tools.LoadLevelAsync(levelName);
    while (!async.isDone) {
        yield return null;
    }

    // Wait for objects to finish their Start() methods, then apply save data:
    yield return null;
    PersistentDataManager.ApplySaveData(saveData);
    DialogueManager.SendUpdateTracker();
} 
Post Reply