Пример #1
0
    /// <summary>
    /// Loads the next level after the given level. If the given level is the last level this will load the
    /// screen that is configured to be the screen after the last level. This will use the default transition prefab.
    /// </summary>
    /// <param name='levelId'>
    /// Level identifier.
    /// </param>
    /// <param name='transitionPrefab'>
    ///  The path to the transition prefab to use.
    /// </param>
    /// <exception cref="System.ArgumentException">if the given level name is unknown.</exception>
    /// <remarks>@since version 1.2.0</remarks>
    public void LoadNextLevelAfter(string levelId, string transitionPrefab)
    {
        string nextLevel = GetNextLevelAfter(levelId);

        levelProgress.SetLevelStatus(levelId, SMLevelStatus.Done);

        var thisGroup = GroupOfLevel(levelId);

        if (nextLevel == null)
        {
            // this was the last level
            levelProgress.ResetLastLevel();
            levelProgress.SetGroupStatus(thisGroup, SMGroupStatus.Done);
            LoadScreen(configurationAdapter.FirstScreenAfterLastLevel, transitionPrefab);
        }
        else
        {
            var nextGroup = GroupOfLevel(nextLevel);
            if (thisGroup != nextGroup)
            {
                // group is finished.
                // set group status to done
                levelProgress.SetGroupStatus(thisGroup, SMGroupStatus.Done);
                // show intermediate screen if wanted.
                if (ActionAfterGroup == SMWorkflowActionType.LoadScreen)
                {
                    // set level and group status to "Open" implying that the level and group can
                    // potentially be visited after the intermediate screen.
                    // only set to open when it's new, otherwise it keeps it's status
                    if (levelProgress.GetLevelStatus(nextLevel) == SMLevelStatus.New)
                    {
                        levelProgress.SetLevelStatus(nextLevel, SMLevelStatus.Open);
                    }
                    if (levelProgress.GetGroupStatus(nextGroup) == SMGroupStatus.New)
                    {
                        levelProgress.SetGroupStatus(nextGroup, SMGroupStatus.Open);
                    }
                    levelProgress.CurrentLevelId = nextLevel;
                    LoadScreen(FirstScreenAfterGroup, transitionPrefab);
                    return;
                }
            }
            // otherwise simply load the next level
            LoadLevel(nextLevel, transitionPrefab);
        }
    }
Пример #2
0
    /// <summary>
    /// Loads a level and updates the level progress tracker. Uses the given transition to do the transition between
    /// the levels. Do not use this function load a screen. Use <see cref="SMSceneManager.LoadScreen" instead.
    /// </summary>
    /// <param name="level">
    /// A <see cref="SMLevelDescriptor"/> of the level.
    /// </param>
    /// <param name="transitionPrefab">
    /// The path of the transition to use.
    /// </param>
    /// <seealso cref="SMSceneMananger[]"/>
    public void LoadLevel(string levelId, string transitionPrefab)
    {
        if (!configurationAdapter.LevelExists(levelId))
        {
            throw new ArgumentException("There is no level with the id '" + levelId + "' in the scene configuration");
        }
        if (levelProgress.GetLevelStatus(levelId) != SMLevelStatus.Done)
        {
            levelProgress.SetLevelStatus(levelId, SMLevelStatus.Visited);
        }

        string groupId = GroupOfLevel(levelId);

        if (levelProgress.GetGroupStatus(groupId) != SMGroupStatus.Done)
        {
            levelProgress.SetGroupStatus(groupId, SMGroupStatus.Visited);
        }

        levelProgress.LastLevelId    = levelId;
        levelProgress.CurrentLevelId = levelId;
        LoadScreen(levelId, transitionPrefab);
    }