Ejemplo n.º 1
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);
    }
Ejemplo n.º 2
0
 public SMUnmodifiableLevelProgress(SMILevelProgress levelProgress, SMIConfigurationAdapter configurationAdapter)
 {
     foreach (var level in configurationAdapter.Levels)
     {
         status.Add(level, levelProgress.GetLevelStatus(level));
     }
     foreach (var group in configurationAdapter.Groups)
     {
         groupStatus.Add(group, levelProgress.GetGroupStatus(group));
     }
     hasPlayed      = levelProgress.HasPlayed;
     lastLevelId    = levelProgress.LastLevelId;
     currentLevelId = levelProgress.CurrentLevelId;
 }
Ejemplo n.º 3
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);
        }
    }
Ejemplo n.º 4
0
    void OnGUI()
    {
        GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
        GUILayout.FlexibleSpace();
        GUILayout.BeginHorizontal();
        GUILayout.FlexibleSpace();
        GUILayout.BeginVertical();
        GUILayout.FlexibleSpace();


        GUILayout.Label("Scene Manager Demo - Level Selector");
        GUILayout.FlexibleSpace();
        if (sceneManager.ConfigurationName.Contains("DemoGame"))
        {
            GUILayout.Label("This is the demo version of the game with only 2 levels.");
        }
        else
        {
            GUILayout.Label("This is the full version of the game with 4 levels.");
        }

        GUILayout.FlexibleSpace();

        if (sceneManager.ConfigurationName.Contains("Grouped"))
        {
            foreach (var group in sceneManager.Groups)
            {
                var groupStatus = levelProgress.GetGroupStatus(group);
                if (GUILayout.Button(group + " [" + groupStatus + "]"))
                {
                    activeGroup       = group;
                    activeGroupLevels = sceneManager.LevelsInGroup(activeGroup);
                }
                if (activeGroup == group)
                {
                    RenderLevels(activeGroupLevels);
                }
            }
        }
        else
        {
            RenderLevels(sceneManager.Levels);
        }

        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Reset Progress"))
        {
            sceneManager.LevelProgress.ResetLastLevel();
            foreach (string levelId in sceneManager.Levels)
            {
                sceneManager.LevelProgress.SetLevelStatus(levelId, SMLevelStatus.New);
            }

            foreach (string groupId in sceneManager.Groups)
            {
                sceneManager.LevelProgress.SetGroupStatus(groupId, SMGroupStatus.New);
            }

            levelProgress = sceneManager.UnmodifiableLevelProgress;
        }


        if (GUILayout.Button("Return to main menu"))
        {
            sceneManager.LoadScreen("MainMenu");
        }
        GUILayout.FlexibleSpace();
        GUILayout.EndVertical();

        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        GUILayout.EndArea();
    }