예제 #1
0
        private void UpdateUnlockedChapters()
        {
            KeyValuePair <int, List <string> >[] lastUnlockedChapters = UserModule.Instance.GetAndClearLastUnlockedChapters();

            if (lastUnlockedChapters == null || lastUnlockedChapters.Length <= 0)
            {
                return;
            }

            foreach (KeyValuePair <int, List <string> > unlockedChapter in lastUnlockedChapters)
            {
                int chapterNo = unlockedChapter.Key;
                if (!m_chapterModels.ContainsKey(chapterNo))
                {
                    continue;
                }
                KeyValuePair <UIChapterNoBtnModel, List <UIMapItemModel> > chapterModel = m_chapterModels[chapterNo];
                // 更新关卡按钮的信息
                UIChapterNoBtnModel chapterNoBtnModel = chapterModel.Key;
                chapterNoBtnModel.IsUnlocked = true;

                // 更新小章节面板的信息
                foreach (string no in unlockedChapter.Value)
                {
                    foreach (UIMapItemModel mapItemModel in chapterModel.Value)
                    {
                        if (no.Equals(mapItemModel.MapConfigData.no))
                        {
                            mapItemModel.IsUnlocked = true;
                            break;
                        }
                    }
                }
            }
        }
예제 #2
0
        private void LoadDataToChapterPanel()
        {
            List <ChapterMapConfigsData> chapterMaps = MapModule.Instance.GetChapterModeConfigs();

            if (chapterMaps == null || chapterMaps.Count <= 0)
            {
                return;
            }

            UserModule userModule = UserModule.Instance;

            List <Button>     chapterSelectedBtns = new List <Button>(chapterMaps.Count);
            List <GameObject> smallChapterPanels  = new List <GameObject>(chapterMaps.Count);

            m_chapterModels = new Dictionary <int, KeyValuePair <UIChapterNoBtnModel, List <UIMapItemModel> > >(chapterMaps.Count);

            foreach (ChapterMapConfigsData data in chapterMaps)
            {
                // 生成选择按钮
                GameObject selectedBtnGo = GameObject.Instantiate <GameObject>(ChapterSelectedBtnPrefab, ChapterSelectedContent.transform);

                // 保存预制体的Button脚本
                UIChapterNoBtn      selectedChapterNoBtn = selectedBtnGo.GetComponent <UIChapterNoBtn>();
                UIChapterNoBtnModel chapterNoBtnModel    = new UIChapterNoBtnModel(data.chapterNo, userModule.IsChapterUnlocked(data.chapterNo));
                selectedChapterNoBtn.SetModel(chapterNoBtnModel);
                chapterSelectedBtns.Add(selectedBtnGo.GetComponent <Button>());

                // 保存章节按钮和小章节的映射
                List <UIMapItemModel> uiMapItemModels = new List <UIMapItemModel>(data.chapterConfigs.Count);
                KeyValuePair <UIChapterNoBtnModel, List <UIMapItemModel> > chapterModelKV = new KeyValuePair <UIChapterNoBtnModel, List <UIMapItemModel> >(chapterNoBtnModel, uiMapItemModels);
                m_chapterModels.Add(data.chapterNo, chapterModelKV);

                // 生成小章节面板
                GameObject smallChapterPanelGo = GameObject.Instantiate <GameObject>(SmallChapterPanelPrefab, SmallChapterRootPanel.transform);
                smallChapterPanels.Add(smallChapterPanelGo);

                // 获取小章节面板的滚动脚本
                UIScrollView smallChapterScrollView = GameObjectUtils.EnsureComponent <UIScrollView>(smallChapterPanelGo);

                // 添加数据到小章节面板
                foreach (MapConfigData mapData in data.chapterConfigs)
                {
                    GameObject mapItem = GameObject.Instantiate <GameObject>(ChapterMapItemPrefab);
                    smallChapterScrollView.AddChild(mapItem);

                    // 保存小章节数据的model
                    UIMapItemModel mapItemModel = new UIMapItemModel(mapData, userModule.IsChapterUnlocked(data.chapterNo, mapData.no));
                    SetDataToMapItem(mapItem, mapItemModel);
                    uiMapItemModels.Add(mapItemModel);
                }
            }

            UIDynamicLabelBtnGroup chapterBtnGroup = GameObjectUtils.EnsureComponent <UIDynamicLabelBtnGroup>(ChapterSelectedContent);

            chapterBtnGroup.Init(chapterSelectedBtns, (int index) =>
            {
                UIDynamicPanelGroup panelGroup = SmallChapterRootPanel.GetComponent <UIDynamicPanelGroup>();
                if (panelGroup == null)
                {
                    return;
                }

                panelGroup.ActivePanel(index);
            });

            UIDynamicPanelGroup smallChapterPanelGroup = GameObjectUtils.EnsureComponent <UIDynamicPanelGroup>(SmallChapterRootPanel.gameObject);

            smallChapterPanelGroup.Init(smallChapterPanels);
        }