/// <summary> /// 将MapConfigData填充到mapItem中 /// </summary> /// <param name="mapItem"></param> /// <param name="data"></param> private void SetDataToMapItem(GameObject mapItem, UIMapItemModel model) { UIMapItem uiMapItem = mapItem.GetComponent <UIMapItem>(); if (uiMapItem == null) { this.LogError("this GameObject = {0} don't have UIMapItem Script!!!", mapItem); return; } uiMapItem.SetModel(model); }
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); }