Ejemplo n.º 1
0
        public static void LevelCompleted(string levelId, LevelDatabase levelDatabase)
        {
            Debug.Log("in Level Completed");
            bool found     = false;
            int  nextIndex = 0;

            for (int i = 0; i < levelDatabase.levelDatabaseEntries.Length; i++)
            {
                LevelDatabaseEntry temp = levelDatabase.levelDatabaseEntries[i];
                if (temp.levelId == levelId)
                {
                    StaticData.LevelInformation = temp;
                    found     = true;
                    nextIndex = i + 1;
                    Debug.Log("Found true");
                }
            }

            if (found)
            {
                PlayerPrefs.SetInt(levelId, 2);
                Debug.Log($"levelDataBaseEntries length = {levelDatabase.levelDatabaseEntries.Length}");
                Debug.Log($"nextIndex = {nextIndex}");
                if (nextIndex < levelDatabase.levelDatabaseEntries.Length)
                {
                    Debug.Log("setting 1 level up to unlocked");
                    PlayerPrefs.SetInt(levelDatabase.levelDatabaseEntries[nextIndex].levelId, 1);
                }
            }
            else
            {
                Debug.LogError("Level completed, but no such level found");
            }
        }
Ejemplo n.º 2
0
        public void LoadLevel(string levelId)
        {
            bool valid = false;

            for (int i = 0; i < levelDatabase.levelDatabaseEntries.Length; i++)
            {
                LevelDatabaseEntry temp = levelDatabase.levelDatabaseEntries[i];
                if (temp.levelId == levelId)
                {
                    StaticData.LevelInformation = temp;
                    valid = true;
                }
            }

            if (valid && SceneUtility.GetBuildIndexByScenePath(StaticData.LevelInformation.sceneName) >= 0)
            {
                if (levelId == "Tutorial")
                {
                    SceneManager.LoadScene("Tutorial");
                }
                else
                {
                    SceneManager.LoadScene("UnitSelection");
                }
            }
            else
            {
                Debug.LogError("No such level found.");
            }
        }