Exemplo n.º 1
0
    // 从scrollView中 上阵 slot中包含item
    public Model_Formation.RESULT EnterExchangeBattleFormation(Model_UnitGroup model_UnitGroup)
    {
        Model_Formation.RESULT reslut = Model_Formation.RESULT.SUCCESS;

        FormationScrollViewItemUI scViewItem = this.GetComponent <FormationScrollViewItemUI>();
        int unitId      = scViewItem.unitId;
        int battleCount = 0;

        Model_Unit model_Unit;

        InstancePlayer.instance.model_User.unlockUnits.TryGetValue(unitId,out model_Unit);
        if (model_Unit != null)
        {
            battleCount = Mathf.Min(model_Unit.num,model_UnitGroup.maxNum);
        }

        Model_UnitGroup new_UnitGroup = new Model_UnitGroup();

        new_UnitGroup.unitId = unitId;
        new_UnitGroup.num    = battleCount;
        new_UnitGroup.teamId = model_UnitGroup.teamId;
        new_UnitGroup.posId  = model_UnitGroup.posId;

        reslut = battlePanel.model_Formation.AddExchange(new_UnitGroup,model_UnitGroup);

        return(reslut);
    }
Exemplo n.º 2
0
    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);
                }
            }
        }
    }