Beispiel #1
0
    private void InitLevelEntries()
    {
        Level[] progress = XMLHelper.Load <Level>(Level.path);
        if (progress.Length == 0)
        {
            progress = new Level[SceneManager.sceneCountInBuildSettings - 1];
            for (int i = 0; i < progress.Length; i++)
            {
                progress[i] = new Level(i + 1);
            }
            progress[0].state = true;
            XMLHelper.Save <Level>(ref progress, Level.path);
        }

        if (progress.Length < SceneManager.sceneCountInBuildSettings - 1)
        {
            Level[] tmp = new Level[SceneManager.sceneCountInBuildSettings - 1];
            for (int i = 0; i < tmp.Length; i++)
            {
                tmp[i] = i < progress.Length ? progress[i] : new Level(i + 1);
            }
            progress = tmp;
            XMLHelper.Save <Level>(ref progress, Level.path);
        }

        for (int i = 0; i < SceneManager.sceneCountInBuildSettings - 1; i++)
        {
            LevelEntry entry = Instantiate(EntryPrefab);
            entry.transform.SetParent(LevelPanel);
            entry.transform.localScale = new Vector3(1, 1, 0);
            entry.Init(progress[i].index, !progress[i].state);
            entry.clicked = new LevelEntry.OnClick(StartPlaying);
        }
    }
Beispiel #2
0
    private void PopulateSelector(LevelManager.SortOption sortOption, string searchTerm)
    {
        searchPopup.SetActive(false);

        LevelManager.Instance.FetchLevels(sortOption, searchTerm, levelInfos => {
            if (levelInfos != null)
            {
                if (levelInfos.Length == 0)
                {
                    Debug.Log("No levels for search term " + searchTerm);
                    return;
                }

                // Remove old level entries
                foreach (Transform child in scrollViewContent)
                {
                    Destroy(child.gameObject);
                }

                foreach (LevelInfo levelInfo in levelInfos)
                {
                    LevelEntry levelEntry = Instantiate(levelEntryPrefab);
                    levelEntry.Init(levelInfo);
                    levelEntry.transform.SetParent(scrollViewContent);
                }
            }
            else
            {
                Debug.LogError("Could not fetch levels.");
            }
        });
    }
Beispiel #3
0
 public void AddLevels(IEnumerable <Level> levels)
 {
     foreach (var level in levels)
     {
         GameObject entryObj = Instantiate(LevelEntryPrefab);
         entryObj.transform.SetParent(Container, false);
         LevelEntry entry = entryObj.GetComponent <LevelEntry>();
         entry.Init(this, level.Number, level.GetResult());
     }
 }