public void InitSlotItemUI() { GameObject prefab = Resources.Load(_unit_Item_Path) as GameObject; GameObject obj = NGUITools.AddChild(this.gameObject, prefab); obj.transform.parent = battleFormationPanel.dragDropRoot.transform; obj.transform.Find("formation_unit_slot").gameObject.SetActive(true); obj.transform.Find("formation_unit_scrollview").gameObject.SetActive(false); dragItemUI = obj.GetComponent <FormationDragItemUI>(); dragItemUI.InitForSlot(); dragItemUI.attachSlotUI = this.GetComponent <FormationSlotUI>(); FormationSlotItemUI slotItem = obj.GetComponent <FormationSlotItemUI>(); slotItem.UpdateUI(model_UnitGroup); FormationDragItemUI dragItem = obj.GetComponent <FormationDragItemUI>(); dragItem.attachSlotUI = this; dragItem.battlePanel = battleFormationPanel; dragItem.unitId = slotItem.unitId; dragItem.CreateSpineTank(); }
private void SetUnitSlotEnabled(Dictionary <int, FormationSlotUI> team, bool active) { foreach (FormationSlotUI slotUI in team.Values) { if (slotUI.dragItemUI != null) { slotUI.dragItemUI.gameObject.SetActive(active); FormationSlotItemUI slotItemUI = slotUI.dragItemUI.GetComponent <FormationSlotItemUI>(); slotItemUI.ResetUI(); } } }
public void ResetTeamSlotItemUI() { FormationSlotItemUI currentSlotItemUI = this.GetComponent <FormationSlotItemUI> (); if (currentSlotItemUI != null) { currentSlotItemUI.ResetUI(); } cloneFormationDragItemUI = null; battlePanel.ResetCurrentTeamSlotItemUI(); }
public void ResetTeamSlotItemUI(int teamId) { foreach (FormationSlotUI slotUI in _unitSlotMap[teamId - 1].Values) { if (slotUI != null && slotUI.dragItemUI != null) { FormationSlotItemUI slotItemUI = slotUI.dragItemUI.GetComponent <FormationSlotItemUI>(); if (slotItemUI != null) { slotItemUI.ResetUI(); } } } }
// 更新上阵Unit数量 public void UpdateBattleUnitNum(Model_UnitGroup unit_Group) { int i = unit_Group.teamId - 1; int j = unit_Group.posId - 1; FormationSlotUI formation = GetFormationSlotUI(i, j); FormationDragItemUI dragItem = formation.dragItemUI; if (dragItem != null) { FormationSlotItemUI slotItem = dragItem.GetComponent <FormationSlotItemUI> (); slotItem.UpdateUI(unit_Group); } }
public void UpdateUnitSlotUI(int teamId) { Model_UnitGroup[] team = InstancePlayer.instance.model_User.model_Formation.GetUnitTeam(teamId); if (team != null) { int index = 0; foreach (FormationSlotUI slotUI in _unitSlotMap[teamId - 1].Values) { if (slotUI != null && slotUI.dragItemUI != null) { FormationSlotItemUI slotItemUI = slotUI.dragItemUI.GetComponent <FormationSlotItemUI>(); if (team != null && team[index] != null) { slotItemUI.UpdateUI(team[index]); } } ++index; } } }
protected override void OnDragDropRelease(GameObject surface) { SetBoxColliderEnabled(); ResetTeamSlotItemUI(); if (surface != null) { switch (state) { case STATE.SCROLLVIEW: { // scrollView 移动空slot FormationSlotUI surfaceSlotUI = surface.GetComponent <FormationSlotUI>(); if (surfaceSlotUI != null && surfaceSlotUI.model_UnitGroup.isEmpty) { Model_UnitGroup model_UnitGroup = surfaceSlotUI.model_UnitGroup; //上阵 Model_Formation.RESULT result = EnterBattleFormation(model_UnitGroup); if (result == Model_Formation.RESULT.SUCCESS) { this.transform.position = surface.transform.position; attachSlotUI = surfaceSlotUI; state = STATE.SLOT; surfaceSlotUI.dragItemUI = gameObject.GetComponent <FormationDragItemUI>(); this.GetComponent <FormationSlotItemUI>().UpdateUI(model_UnitGroup); // 首次进入 上阵Unit 如果teamId = 0 强制修改为1 int teamId = InstancePlayer.instance.model_User.model_Formation.GetSelectTeamId(); if (teamId == 0) { InstancePlayer.instance.model_User.model_Formation.SetSelectTeamId(1); } // 更新scrollView列表 UpdateUnitScrollView(); // 播放粒子特效 StartCoroutine(PlayEffect(this.gameObject)); } else { base.OnDragDropRelease(surface); UpdateEnterBattlePopupMsg(result); } return; } // scrollView 移动到包含 item slot FormationDragItemUI dragItemUI = surface.GetComponent <FormationDragItemUI>(); if (dragItemUI != null && dragItemUI.attachSlotUI != null) { FormationSlotUI slotUI = dragItemUI.attachSlotUI; Model_UnitGroup model_UnitGroup = slotUI.model_UnitGroup; Model_Formation.RESULT result = EnterExchangeBattleFormation(model_UnitGroup); if (result == Model_Formation.RESULT.SUCCESS) { dragItemUI.GetComponent <FormationSlotItemUI>().UpdateUI(model_UnitGroup); // 替换spine tankicon dragItemUI.ReplaceTankIcon(); // 更新scrollView列表 UpdateUnitScrollView(); // 播放粒子特效 StartCoroutine(PlayEffect(dragItemUI.gameObject)); } else { UpdateEnterBattlePopupMsg(result); } // 删除当前拖动 GameObject base.OnDragDropRelease(surface); return; } } break; case STATE.SLOT: /* * 1 移动另一个slot * (1) slot 区域没有item * (2) slot 区域有item * 2 移动到scrollView * 3 移动到空白区 */ // 1 移动另一个slot // (1)slot区域没有item { FormationSlotUI surfaceSlotUI = surface.GetComponent <FormationSlotUI>(); if (surfaceSlotUI != null && surfaceSlotUI.model_UnitGroup.isEmpty) { Model_Formation.RESULT result = ExchageFormation(surfaceSlotUI.model_UnitGroup); if (result == Model_Formation.RESULT.SUCCESS) { this.transform.position = surfaceSlotUI.transform.position; this.attachSlotUI.dragItemUI = null; this.attachSlotUI = surfaceSlotUI; this.attachSlotUI.dragItemUI = this.GetComponent <FormationDragItemUI>(); this.GetComponent <FormationSlotItemUI>().UpdateUI(surfaceSlotUI.model_UnitGroup); // 播放粒子特效 StartCoroutine(PlayEffect(this.gameObject)); } else { base.OnDragDropRelease(surface); } UpdateUnitScrollView(); return; } } // (2) slot区域有item { FormationDragItemUI surfaceDragItemUI = surface.GetComponent <FormationDragItemUI>(); if (surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI != null) { FormationSlotUI surfaceSlotUI = surfaceDragItemUI.attachSlotUI; Model_Formation.RESULT result = ExchageFormation(surfaceSlotUI.model_UnitGroup); if (result == Model_Formation.RESULT.SUCCESS) { // 更显UI显示数据 FormationSlotUI sourceSlotUI = this.attachSlotUI; FormationDragItemUI sourceDragUI = this.GetComponent <FormationDragItemUI>(); FormationSlotUI targetSlotUI = surfaceDragItemUI.attachSlotUI; FormationDragItemUI targetDragUI = surfaceDragItemUI; FormationSlotItemUI sourceSlotItemUI = sourceDragUI.gameObject.GetComponent <FormationSlotItemUI>(); FormationSlotItemUI targetSlotItemUI = targetDragUI.gameObject.GetComponent <FormationSlotItemUI>(); Model_UnitGroup source = attachSlotUI.model_UnitGroup; Model_UnitGroup target = targetSlotUI.model_UnitGroup; sourceSlotItemUI.UpdateUI(source); targetSlotItemUI.UpdateUI(target); this.transform.position = sourceSlotUI.transform.position; // 交换 spine tank icon surfaceDragItemUI.ReplaceTankIcon(); sourceDragUI.ReplaceTankIcon(); // 播放粒子特效 StartCoroutine(PlayEffect(sourceSlotItemUI.gameObject)); StartCoroutine(PlayEffect(targetSlotItemUI.gameObject)); } else { base.OnDragDropRelease(surface); } UpdateUnitScrollView(); return; } } // 2 移动到scrollView 下阵 { FormationDragItemUI surfaceDragItemUI = surface.GetComponent <FormationDragItemUI>(); bool isScrllViewCollider = surface.gameObject.name.Equals("scrollView_bg_unit"); if ((surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI == null) || isScrllViewCollider) { ExitBattleFormation(); attachSlotUI.dragItemUI = null; UpdateUnitScrollView(); DestroyImmediate(this.gameObject); return; } } // 拖动到其他区域 if (attachSlotUI != null) { this.transform.position = attachSlotUI.transform.position; StartCoroutine(PlayEffect(this.gameObject)); return; } break; } } base.OnDragDropRelease(surface); }
public void UpdateUnitList(int index) { // 获取排序后的UI列表 List <FormationUnitCategory.Unit> units = formationUnitCategory.GetSortUnit(index); for (int i = 0; i < BOTTOM_TAB_COUNT; ++i) { GameObject sv = unit_scView_list[i].gameObject; sv.SetActive(false); if (i == index) { sv.SetActive(true); } } if (!_isInit [index]) { _isInit [index] = true; int id = 0; foreach (FormationUnitCategory.Unit unit in units) { GameObject prefab = Resources.Load(UNIT_ITEM_PATH) as GameObject; GameObject obj = NGUITools.AddChild(unit_grid_list [index].gameObject, prefab); unit_grid_list [index].AddChild(obj.transform); obj.name = UIHelper.GetItemSuffix(++id); UIDragScrollView dragScrollView = obj.GetComponent <UIDragScrollView>(); if (dragScrollView == null) { dragScrollView = obj.AddComponent <UIDragScrollView>(); dragScrollView.scrollView = unit_scView_list[index]; } FormationScrollViewItemUI scViewItemUI = obj.GetComponent <FormationScrollViewItemUI> (); scViewItemUI.UpdateUI(unit); FormationSlotItemUI slotItemUI = obj.GetComponent <FormationSlotItemUI> (); slotItemUI.UpdateUI(unit.id); FormationDragItemUI itemDrag = obj.GetComponent <FormationDragItemUI>(); itemDrag.battlePanel = this; obj.transform.Find("formation_unit_slot").gameObject.SetActive(false); obj.transform.Find("formation_unit_scrollview").gameObject.SetActive(true); } // scrollView cell 排序 unit_grid_list [index].animateSmoothly = false; unit_grid_list [index].repositionNow = true; // 小于单行最多显示 停止滑动 if (units.Count < UNIT_SHOW_MAX) { unit_scView_list[index].enabled = false; } else { unit_scView_list[index].enabled = true; } } else { int id = 0; foreach (FormationUnitCategory.Unit unit in units) { string cellPath = UIHelper.GetItemSuffix(++id); GameObject cell = unit_grid_list[index].transform.Find(cellPath).gameObject; FormationScrollViewItemUI scViewItemUI = cell.GetComponent <FormationScrollViewItemUI> (); scViewItemUI.UpdateUI(unit); FormationSlotItemUI slotItemUI = cell.GetComponent <FormationSlotItemUI> (); if (unit.isOnDuty) { int teamId = model_Formation.GetSelectTeamId(); Model_UnitGroup unitGroup = model_Formation.GetUnitGroupByUnitId(teamId, unit.id); if (unitGroup != null) { slotItemUI.UpdateUI(unitGroup); } } else { slotItemUI.UpdateUI(unit.id); } } } }