Page 1 of 1

Adding Loading Screen (ARPG Kit)

Posted: Fri Feb 10, 2017 5:29 am
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

Re: Adding Loading Screen (ARPG Kit)

Posted: Fri Feb 10, 2017 10:48 am
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();
}

Re: Adding Loading Screen (ARPG Kit)

Posted: Sat Feb 11, 2017 10:45 am
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();
}

Re: Adding Loading Screen (ARPG Kit)

Posted: Sat Feb 11, 2017 11:46 am
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();
}