コード例 #1
0
    public void NextLevel()
    {
        int index = CurrentContainer.Levels.IndexOf(CurrentLevel);

        index++;
        if (index > 0 && index != CurrentContainer.Levels.Count)
        {
            CurrentLevel = CurrentContainer.Levels[index];
            LoadLevel(CurrentLevel);
        }
        if (index == CurrentContainer.Levels.Count)
        {
            KeyValuePair <string, LevelsContainer> keyValuePair = LevelsGroups.First(x => x.Value == CurrentContainer);
            List <string> keys    = LevelsGroups.Keys.ToList <string>();
            int           nextKey = keys.IndexOf(keyValuePair.Key) + 1;

            if (nextKey != keys.Count)
            {
                CurrentContainer = LevelsGroups[keys[nextKey]];
                CurrentLevel     = CurrentContainer.Levels[0];
                LoadLevel(CurrentLevel);
            }
            else
            {
                SceneManager.LoadScene(0);
            }
        }
    }
コード例 #2
0
 public void LoadLevel(LevelDescription level, LevelsContainer container)
 {
     CurrentLevel     = level;
     CurrentContainer = container;
     //SceneManager.LoadScene(1);
     AsyncSceneLoading(1);
 }
コード例 #3
0
    public void AddLevels(List <LevelsContainer> levelsContainer, List <SaveData> saves)
    {
        for (int i = saves.Count - 1, j = 0; i >= 0; i--)
        {
            LevelsContainer  container = null;
            LevelDescription lvl       = null;
            foreach (var lc in levelsContainer)
            {
                lvl = lc.Levels.Find(x => x.ID == saves[i].LevelID);
                if (lvl != null)
                {
                    container = lc;
                    break;
                }
            }
            if (lvl != null)
            {
                if ((j) % (LevelsOnPage) == 0)
                {
                    RectTransform lvlPage = Instantiate(PagePrefab);
                    pages.Add(lvlPage);

                    lvlPage.transform.SetParent(PageParent);
                    lvlPage.transform.localScale = Vector3.one;
                    lvlPage.offsetMin            = Vector2.zero;
                    lvlPage.offsetMax            = Vector2.zero;
                    // CalculateInventoryPanelParameters(lvlPage, LevelsOnPage);
                }
                Button btn = Instantiate(LevelButtonPrefab);
                btn.transform.SetParent(pages[pages.Count - 1]);
                btn.transform.localScale = Vector3.one;
                btn.GetComponentInChildren <TextMeshProUGUI>().text = lvl.Name;


                RecordLevelSave recordLevelSave = FindObjectOfType <RecordLevelSave>();
                if (recordLevelSave != null)
                {
                    int record = recordLevelSave.GetRecordByLevelID(lvl);
                    if (record != 0)
                    {
                        SetPassedLevel(btn.transform, record.ToString());
                    }
                }
                btn.onClick.AddListener(() =>
                {
                    GameManager.Instance.LoadLevel(lvl, container);
                });
                j++;
            }
        }
        ScrollSnapRect scrollSnapRect = GetComponentInChildren <ScrollSnapRect>();

        if (scrollSnapRect != null)
        {
            scrollSnapRect.OnPageSwitched += GetCurrentPage;
        }
        GetCurrentPage(currentPage);
    }
コード例 #4
0
 public FieldObjectsSpawner(LevelsContainer levelsContainer, TowerElementMonoBehaviour.Factory towerElementsFactory, StringPrefabPairContainer prefabsContainer, GameManager gameManager)
 {
     _levelsContainer      = levelsContainer;
     _towerElementsFactory = towerElementsFactory;
     _prefabsContainer     = prefabsContainer;
     _gameManager          = gameManager;
     _rootGameObject       = new GameObject("Root");
     _rootGameObject.transform.position = Vector3.zero;
 }
コード例 #5
0
 private void LoadJson()
 {
     using (StreamReader stream = new StreamReader(dataPath))
     {
         string json = stream.ReadToEnd();
         levels = JsonConvert.DeserializeObject <LevelsContainer>(json);
     }
     Levels = levels.levels.ToList();
 }
コード例 #6
0
    public void AddLevels(LevelsContainer levelsContainer)
    {
        for (int i = 0; i < levelsContainer.Levels.Count; i++)
        {
            if (i == 0 || (i) % (LevelsOnPage) == 0)
            {
                RectTransform lvlPage = Instantiate(PagePrefab);

                pages.Add(lvlPage);
                lvlPage.transform.SetParent(PageParent);
                lvlPage.transform.localScale = Vector3.one;
                lvlPage.offsetMin            = Vector2.zero;
                lvlPage.offsetMax            = Vector2.zero;
                //CalculateInventoryPanelParameters(lvlPage, LevelsOnPage);
            }
            Button btn = Instantiate(LevelButtonPrefab);
            btn.transform.SetParent(pages[pages.Count - 1]);
            btn.transform.localScale = Vector3.one;
            btn.GetComponentInChildren <TextMeshProUGUI>().text = levelsContainer.Levels[i].Name;



            LevelDescription lvl             = levelsContainer.Levels[i];
            RecordLevelSave  recordLevelSave = FindObjectOfType <RecordLevelSave>();
            if (recordLevelSave != null)
            {
                int record = recordLevelSave.GetRecordByLevelID(lvl);
                if (record != 0)
                {
                    SetPassedLevel(btn.transform, record.ToString());
                }
            }
            btn.onClick.AddListener(() =>
            {
                GameManager.Instance.LoadLevel(lvl, levelsContainer);
            });
        }
        ScrollSnapRect scrollSnapRect = GetComponentInChildren <ScrollSnapRect>();

        if (scrollSnapRect != null)
        {
            scrollSnapRect.OnPageSwitched += GetCurrentPage;
        }
        GetCurrentPage(currentPage);
    }
コード例 #7
0
    public void Awake()
    {
        LeanTween.reset();
        LeanTween.init(800);
        startfading.FadeOut();
        Destroy(startfading.gameObject, 0.6f);
        GameObject levelLoader = Instantiate(LevelLoader);

        _levelLoader = levelLoader.GetComponent <LevelLoader>();
        if (levelsContainer && horizontalContainer && levelBubble)
        {
            string          loadedJsonFile = Resources.Load <TextAsset>("levels").text;
            LevelsContainer levelsInJson   = JsonUtility.FromJson <LevelsContainer>(loadedJsonFile);

            //We instanciate the matrix that will contain all the buttons
            uibuttons = new UIButton[(Mathf.Min(levelsInJson.levels.Length, ActualSave.actualSave.NextLevel() + 1) / 4) + 1][];
            for (int i = 0; i < uibuttons.Length; i++)
            {
                uibuttons[i] = new UIButton[4];
            }

            //FIRST LOOP
            GameObject actualContainer = Instantiate(horizontalContainer, levelsContainer.transform);
            firstBubble = Instantiate(levelBubble, actualContainer.transform);
            firstBubble.GetComponent <levelBubbleHandlerScript>().setData(levelsInJson.levels[0], 1);
            int modifier = ((Mathf.Min(ActualSave.actualSave.NextLevel() + 1, levelsInJson.levels.Length) % 4 > 0) ? 1 : 0);

            //Debug.Log("Resultat du calcul : " + Mathf.Min(ActualSave.actualSave.NextLevel() + 1, levelsInJson.levels.Length) % 4);
            levelsContainer.GetComponent <RectTransform>().sizeDelta = new Vector2(700f, ((Mathf.Min(ActualSave.actualSave.NextLevel() + 1, levelsInJson.levels.Length) / 4f + modifier) * 133f + 20f));
            levelsContainer.GetComponent <RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, ((Mathf.Min(ActualSave.actualSave.NextLevel() + 1, levelsInJson.levels.Length) / 4f + modifier) * 133f + 20f));

            //We enter the first element in the matrix
            uibuttons[0][0] = firstBubble.GetComponent <levelBubbleHandlerScript>().getButton();



            //THEN ITERATION



            //This will be the row number
            int j = 0;
            for (int i = 1; i < Mathf.Min(levelsInJson.levels.Length, ActualSave.actualSave.NextLevel() + 1); i++)
            {
                if (i % 4 == 0)
                {
                    j++;
                    actualContainer = Instantiate(horizontalContainer, levelsContainer.transform);
                }

                if (i == levelsInJson.levels.Length - 1)
                {
                    //The only thing that changes is that we store it in a global variable
                    lastBubble = Instantiate(levelBubble, actualContainer.transform);
                    lastBubble.GetComponent <levelBubbleHandlerScript>().setData(levelsInJson.levels[i], i + 1);
                    uibuttons[j][i % 4] = lastBubble.GetComponent <levelBubbleHandlerScript>().getButton();
                }
                else
                {
                    GameObject created = Instantiate(levelBubble, actualContainer.transform);
                    created.GetComponent <levelBubbleHandlerScript>().setData(levelsInJson.levels[i], i + 1);
                    uibuttons[j][i % 4] = created.GetComponent <levelBubbleHandlerScript>().getButton();
                }
            }

            //We will now define the navigation of all buttons

            for (j = 0; j < uibuttons.Length; j++)
            {
                for (int i = 0; i < 4; i++)
                {
                    if (uibuttons[j][i])
                    {
                        //Horizontal movement
                        if (i == 0) //Left
                        {
                            if (uibuttons[j][i + 1])
                            {
                                uibuttons[j][i].rightButton = uibuttons[j][i + 1];
                            }
                        }
                        else if (i == 3) //Right
                        {
                            if (uibuttons[j][i - 1])
                            {
                                uibuttons[j][i].leftButton = uibuttons[j][i - 1];
                            }
                            if (ActualSave.actualSave.NextLevel() >= 12)
                            {
                                uibuttons[j][i].rightButton = bar;
                            }
                            else
                            {
                                uibuttons[j][i].rightButton = bar.rightButton;
                            }
                        }
                        else //Center
                        {
                            if (uibuttons[j][i - 1])
                            {
                                uibuttons[j][i].leftButton = uibuttons[j][i - 1];
                            }
                            if (uibuttons[j][i + 1])
                            {
                                uibuttons[j][i].rightButton = uibuttons[j][i + 1];
                            }
                        }

                        //We handle the case of the last button
                        if (j * 4 + i == ActualSave.actualSave.NextLevel() || j * 4 + i == ActualSave.actualSave.NextLevel() - 1)
                        {
                            if (ActualSave.actualSave.NextLevel() >= 12)
                            {
                                uibuttons[j][i].rightButton = bar;
                            }
                            else
                            {
                                uibuttons[j][i].rightButton = bar.rightButton;
                            }
                        }

                        //Vertical movement
                        if (j == 0) //Top
                        {
                            if (j + 1 <= uibuttons.Length - 1)
                            {
                                uibuttons[j][i].downButton = uibuttons[j + 1][i];
                            }
                        }
                        else if (j == uibuttons.Length - 1)//Bottom
                        {
                            if (j - 1 >= 0)
                            {
                                uibuttons[j][i].upButton = uibuttons[j - 1][i];
                            }
                        }
                        else //Center
                        {
                            if (j + 1 <= uibuttons.Length - 1)
                            {
                                uibuttons[j][i].downButton = uibuttons[j + 1][i];
                            }
                            if (j - 1 >= 0)
                            {
                                uibuttons[j][i].upButton = uibuttons[j - 1][i];
                            }
                        }
                    }
                }
            }

            stateMachine.firstSelected = firstBubble.GetComponent <levelBubbleHandlerScript>().getButton();
            stateMachine.firstSelected.changeState(UIButton.SELECTED);
            //events.firstSelectedGameObject = firstBubble.GetComponent<levelBubbleHandlerScript>().getButton();
            size = ActualSave.actualSave.NextLevel() / 4 - 1; /// A REVOIR -----------------------------------------

            initialAnchor = levelsContainer.GetComponent <RectTransform>().anchoredPosition.y;
            if (ActualSave.actualSave.NextLevel() < 12)
            {
                bar.rightButton.leftButton = uibuttons[0][(uibuttons[0][3]) ? 3 : (uibuttons[0][2]) ? 2 : (uibuttons[0][1]) ? 1 : 0];
                bar.isActive = false;
                Destroy(bar.gameObject);
                scrollRect.anchoredPosition = new Vector2(scrollRect.anchoredPosition.x, -scrollRect.sizeDelta.y / 2);
                backButton.leftButton       = (uibuttons[0][3]) ? uibuttons[0][2]: (uibuttons[0][2]) ? uibuttons[0][1] : uibuttons[0][0];
            }
            else
            {
                bar.nbSteps = size + 1;
                bar.size    = (1f / size) * 4f;
                bar.value   = 0;
                bar.Refresh();
            }
        }
    }
コード例 #8
0
    public void LoadNextLevel(int levelToLoad, bool mustPassIntro = false)
    {
        //If the current level is negative (level was chosen in level Loader), so we force the loading to reload the current level until the player quits it himself.
        //In level selection, we make sur that the players has enough lives
        //We also check if the leveltoLoad wanted is really a level and not the menu, to allow quitting
        if (currentLevel.value < 0 && levelToLoad >= 0)
        {
            if (!mustPassIntro)
            {
                livesLeft.value = 99; //That way we keep the current difficulty setting chosen by the player
            }


            levelToLoad = -currentLevel.value - 1;

            updateMusic(levelToLoad);

            string          loadedJsonFile = Resources.Load <TextAsset>("levels").text;
            LevelsContainer levelsInJson   = JsonUtility.FromJson <LevelsContainer>(loadedJsonFile);
            CrossLevelInfo.LevelName     = levelsInJson.levels[levelToLoad].name;
            CrossLevelInfo.mustPassIntro = mustPassIntro;
            CrossLevelInfo.time          = levelsInJson.levels[levelToLoad].time[0];//We set speed to minimum
            CrossLevelInfo.maxSlimes     = levelsInJson.levels[levelToLoad].bonusCount;

            StartCoroutine(loadAsynchronously(levelsInJson.levels[levelToLoad].sceneName));
        }
        else
        {
            //If level to load is bigger than zero, and the currentlevel value isnt negative, then it means that we are loading a level
            if (levelToLoad >= 0)
            {
                Debug.Log("Level number : " + levelToLoad);

                updateMusic(levelToLoad);
                string          loadedJsonFile = Resources.Load <TextAsset>("levels").text;
                LevelsContainer levelsInJson   = JsonUtility.FromJson <LevelsContainer>(loadedJsonFile);
                CrossLevelInfo.LevelName     = levelsInJson.levels[levelToLoad].name;
                CrossLevelInfo.mustPassIntro = mustPassIntro;
                CrossLevelInfo.time          = levelsInJson.levels[levelToLoad].time[difficultyChrono.value];
                CrossLevelInfo.maxSlimes     = levelsInJson.levels[levelToLoad].bonusCount;

                if (difficultyLife.value == 1)
                {
                    //We avoid any glitch where someone gets more that 5 lives
                    if (livesLeft.value > 5)
                    {
                        livesLeft.value = 5;
                    }
                    if (!mustPassIntro)
                    {
                        livesLeft.value = 5;
                    }
                    else
                    {
                        livesLeft.value = livesLeft.value - 1;
                        if (livesLeft.value < 0)
                        {
                            currentLevel.value--;
                            cancelLevelProgress(levelToLoad);
                            livesLeft.value = 5;
                            LoadNextLevel(Mathf.Max(0, levelToLoad - 1), false);
                            return;
                        }
                    }
                }
                else if (difficultyLife.value == 2)
                {
                    //We avoid any glitch where someone gets more that 5 lives
                    if (livesLeft.value > 5)
                    {
                        livesLeft.value = 5;
                    }
                    if (mustPassIntro)
                    {
                        livesLeft.value = livesLeft.value - 1;

                        if (livesLeft.value < 0)
                        {
                            cancelAllProgress();
                            livesLeft.value    = 5;
                            currentLevel.value = 0;
                            LoadNextLevel(0);
                            return;
                        }
                    }
                }
                StartCoroutine(loadAsynchronously(levelsInJson.levels[levelToLoad].sceneName));
            }
            else if (levelToLoad == -1)
            {
                updateMusic(0);

                StartCoroutine(loadAsynchronously("LevelSelection"));
            }
            else
            {
                updateMusic(0);

                StartCoroutine(loadAsynchronously("MainMenu"));
            }
        }


        LeanTween.reset();
        LeanTween.init(800);

        /*Debug.Log(levelsInJson.levels[levelToLoad].objName);
         * Debug.Log(levelsInJson.levels[levelToLoad].previewScale[0]);
         * Debug.Log(levelsInJson.levels[levelToLoad].previewRotation[0]);
         * Debug.Log(levelsInJson.levels[levelToLoad].bonusCount);*/
    }
コード例 #9
0
    void CreateLevelData()
    {
        TextAsset levelText = Resources.Load("Levels") as TextAsset;

        Levels = JsonUtility.FromJson <LevelsContainer>(levelText.text);
    }
コード例 #10
0
    public void MakeLevelButton(Button btn, LevelsContainer levelsContainer, string key = null)
    {
        LevelsPanel levelsPanel = InstantiateBtn(btn, key);

        levelsPanel.AddLevels(levelsContainer);
    }