public void UpdateScrollView() { List <UIHeroCategory.Hero> herosCategory = _formationHeroCategory.GetSortHero(); if (!isInitScrllView) { int i = 0; isInitScrllView = true; foreach (UIHeroCategory.Hero heroCategory in herosCategory) { GameObject prefab = Resources.Load(HERO_ITEM_PATH) as GameObject; GameObject obj = NGUITools.AddChild(_grid.gameObject, prefab); _grid.AddChild(obj.transform); obj.name = UIHelper.GetItemSuffix(++i); UIHeroBodyItem heroBodyItem = obj.GetComponent <UIHeroBodyItem> (); heroBodyItem.UpdateUI(heroCategory); UIHeroHeadItem heroHeadItem = obj.GetComponent <UIHeroHeadItem> (); heroHeadItem.UpdateUI(heroCategory.pb_Hero); UIHeroDragItem heroDragItem = obj.GetComponent <UIHeroDragItem> (); heroDragItem.heroPanel = this; heroDragItem.slotUIManager = _battleFormationPanel.slotUIManager; obj.transform.Find("Hero_Head_Sprite").gameObject.SetActive(false); obj.transform.Find("Hero_Body_Sprite").gameObject.SetActive(true); } // scrollView cell 排序 _grid.animateSmoothly = false; _grid.repositionNow = true; // 小于单行最多显示 停止滑动 if (herosCategory.Count < BattleFormationPanel.UNIT_SHOW_MAX) { _scrollView.enabled = false; } else { _scrollView.enabled = true; } } else { int id = 0; foreach (UIHeroCategory.Hero heroCategory in herosCategory) { string cellPath = UIHelper.GetItemSuffix(++id); GameObject cell = _grid.transform.Find(cellPath).gameObject; UIHeroBodyItem heroBodyItem = cell.GetComponent <UIHeroBodyItem> (); heroBodyItem.UpdateUI(heroCategory); } } }
// 从scrollView中 上阵Hero public Model_Formation.RESULT EnterBattleHero(Model_UnitGroup model_UnitGroup) { Model_Formation.RESULT result = Model_Formation.RESULT.SUCCESS; UIHeroBodyItem bodyItem = this.GetComponent <UIHeroBodyItem>(); int heroId = bodyItem.heroId; Model_UnitGroup new_UnitGroup = new Model_UnitGroup(); new_UnitGroup.teamId = model_UnitGroup.teamId; new_UnitGroup.posId = model_UnitGroup.posId; new_UnitGroup.heroId = heroId; result = _heroPanel._battleFormationPanel.model_Formation.AddHero(new_UnitGroup); return(result); }