Example #1
0
    static public UIHeroSlot GetHeroSlotFromPool()
    {
        UIHeroSlot heroSlot = null;//  = Instance.heroSlotPool.Find(x => !x.gameObject.activeSelf);

        for (int i = 0; i < Instance.heroSlotPool.Count; i++)
        {
            if (Instance.heroSlotPool[i].gameObject.activeSelf == false)
            {
                heroSlot = Instance.heroSlotPool[i];
                break;
            }
        }

        if (!heroSlot)
        {
            GameObject go = Instantiate(Instance.heroSlotPrefab) as GameObject;
            //go.transform.SetParent(heroInventoryScrollViewContent.transform, false);
            //go.transform.localPosition = Vector3.zero;
            //go.transform.localScale = Vector3.one;
            heroSlot = go.GetComponent <UIHeroSlot>();

            Instance.heroSlotPool.Add(heroSlot);
        }

        return(heroSlot);
    }
    //----------------------- 初始化Slot

    public void InitSlotUI()
    {
        for (int i = 0; i < TEAM_COUNT; ++i)
        {
            Transform slots = UIHelper.FindChildInObject(gameObject, "Formation_Team_" + i).transform;
            for (int j = 0; j < SLOT_COUNT; ++j)
            {
                Model_UnitGroup model_UnitGroup = model_Formation.GetUnitGroup(i + 1, j + 1);

                Transform       slotTransUnit = slots.Find("tank_slot_" + j);
                FormationSlotUI slotUIUnit    = slotTransUnit.GetComponent <FormationSlotUI>();
                slotUIUnit.i = i;
                slotUIUnit.j = j;
                slotUIManager.SetUnitSlotUI(i, j, slotUIUnit);
                slotUIUnit.UpdateUI(model_UnitGroup, this);

                Transform  slotTransHero = slots.Find("hero_slot_" + j);
                UIHeroSlot slotUIHero    = slotTransHero.GetComponent <UIHeroSlot>();
                slotUIHero.i = i;
                slotUIHero.j = j;
                slotUIManager.SetHeroSlotUI(i, j, slotUIHero);
                slotUIHero.UpdateUI(model_UnitGroup, this._heroPanel);
            }
        }
    }
Example #3
0
 public HeroSlotUpdatableInventory(UIHeroSlot _heroSlot)
 {
     heroSlot = _heroSlot;
     if (heroSlot.AddPanel.activeSelf)
     {
         heroSlot.AddPanel.SetActive(false);
     }
 }
Example #4
0
    public void UpdateHeroSlotData(string id)
    {
        UIHeroSlot uIHero = heroSlotPool.Find(x => x.id == id);

        if (uIHero != null)
        {
            uIHero.SlotDataInit(id, HeroSlotState.Inventory);
        }
        //heroSlotList.Find(x => x.id == id).SlotDataInit(id, HeroSlotState.Inventory);
    }
Example #5
0
    public void RemoveSlot(string key)
    {
        UIHeroSlotContainer container = heroSlotContainerList.Find(x => x.heroInvenID == key);
        UIHeroSlot          slot      = container.GetComponentInChildren <UIHeroSlot>();

        container.isDestroy = true;

        if (slot != null)
        {
            slot.transform.SetParent(heroSlotStackArea.transform);
        }

        heroSlotContainerList.RemoveAt(heroSlotContainerList.FindIndex(x => x.heroInvenID == key));
        Destroy(container.gameObject);

        SizeControl();
    }
Example #6
0
    public UIHeroSlotContainer GetHeroContainerFromPool(HeroData heroData)
    {
        UIHeroSlotContainer heroSlot = null;

        for (int i = 0; i < heroContainerPool.Count; i++)
        {
            if (heroContainerPool[i].transform.parent == slotStackArea.transform)
            {
                heroSlot = heroContainerPool[i];
                break;
            }
        }

        if (!heroSlot)
        {
            heroSlot = InitSameHeroSlot(heroData);
            GameObject go   = Instantiate(heroSlotPrefab) as GameObject;
            UIHeroSlot slot = go.GetComponent <UIHeroSlot>();

            heroSlot.SetHeroSlot(slot);

            heroContainerPool.Add(heroSlot);
        }
        else
        {
            heroSlot.heroInvenID = heroData.id;
            heroSlot.ResetSlotData();

            string heroID = heroData.heroID;
            if (heroID.EndsWith("_Hero"))
            {
                heroSlot.transform.SetParent(battleScrollViewContent.transform, false);
            }
            else
            {
                heroSlot.transform.SetParent(territoryScrollViewContent.transform, false);
            }
        }

        return(heroSlot);
    }
    // 设置 hero 或 Unit 上阵 Item 是否可以拖动
    public void SetHeroOrUnitDragable(bool isHero)
    {
        for (int i = 0; i < TEAM_COUNT; ++i)
        {
            for (int j = 0; j < POSITION_COUNT; ++j)
            {
                FormationSlotUI     unitSlotUI = _unitSlotMap [i] [j];
                FormationDragItemUI unitDragUI = unitSlotUI.dragItemUI;
                if (unitDragUI != null)
                {
                    unitDragUI.GetComponent <BoxCollider> ().enabled = !isHero;
                }

                UIHeroSlot     heroSlotUI = _heroSlotMap [i] [j];
                UIHeroDragItem heroDragUI = heroSlotUI.dragItemUI;
                if (heroDragUI != null)
                {
                    heroDragUI.GetComponent <BoxCollider> ().enabled = isHero;
                }
            }
        }
    }
Example #8
0
 public HeroSlotUpdatableDefault(UIHeroSlot _heroSlot)
 {
     heroSlot = _heroSlot;
 }
Example #9
0
 public HeroSlotUpdatableTraining(UIHeroSlot _heroSlot)
 {
     heroSlot = _heroSlot;
 }
 public void SetHeroSlotUI(int teamId, int slotId, UIHeroSlot slotUI)
 {
     _heroSlotMap [teamId].Add(slotId, slotUI);
 }
Example #11
0
 public void SetHeroSlot(UIHeroSlot _heroSlot)
 {
     heroSlot = _heroSlot;
 }
Example #12
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        SetBoxColliderEnabled();
        ResetTeamSlotItemUI();

        if (surface != null)
        {
            switch (state)
            {
            case STATE.SCROLLVIEW:
            {
                // scrollView 移动空slot
                UIHeroSlot surfaceSlotUI = surface.GetComponent <UIHeroSlot>();
                if (surfaceSlotUI != null && !surfaceSlotUI.model_UnitGroup.HasHero())
                {
                    Model_UnitGroup model_UnitGroup = surfaceSlotUI.model_UnitGroup;

                    //上阵
                    Model_Formation.RESULT result = EnterBattleHero(model_UnitGroup);

                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        this.transform.position = surface.transform.position;
                        attachSlotUI            = surfaceSlotUI;
                        state = STATE.SLOT;
                        surfaceSlotUI.dragItemUI = this;

                        // 更新上阵Unit显示数量
                        _slotUIManager.UpdateBattleUnitNum(model_UnitGroup);

                        // 更新scrollView列表
                        UpdateHeroScrollView();

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        base.OnDragDropRelease(surface);
                        UpdateErrorPopupMsg(result);
                    }
                    return;
                }

//					// scrollView 移动到包含 item slot
                UIHeroDragItem dragItemUI = surface.GetComponent <UIHeroDragItem>();
                if (dragItemUI != null && dragItemUI.attachSlotUI != null)
                {
                    UIHeroSlot      slotUI          = dragItemUI.attachSlotUI;
                    Model_UnitGroup model_UnitGroup = slotUI.model_UnitGroup;

                    Model_Formation.RESULT result = EnterBattleHero(model_UnitGroup);
                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        dragItemUI.GetComponent <UIHeroHeadItem>().UpdateUI(model_UnitGroup.heroId);

                        // 更新上阵Unit显示数量
                        _slotUIManager.UpdateBattleUnitNum(model_UnitGroup);

                        // 更新scrollView列表
                        UpdateHeroScrollView();

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        UpdateErrorPopupMsg(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
            {
                UIHeroSlot surfaceSlotUI = surface.GetComponent <UIHeroSlot>();
                if (surfaceSlotUI != null && !surfaceSlotUI.model_UnitGroup.HasHero())
                {
                    Model_Formation.RESULT result = ExchangeBattleHero(surfaceSlotUI.model_UnitGroup);
                    if (result == Model_Formation.RESULT.SUCCESS)
                    {
                        // 更新上阵Unit显示数量 交换之前更新
                        _slotUIManager.UpdateBattleUnitNum(surfaceSlotUI.model_UnitGroup);
                        _slotUIManager.UpdateBattleUnitNum(attachSlotUI.model_UnitGroup);

                        this.transform.position = surfaceSlotUI.transform.position;

                        this.attachSlotUI.dragItemUI = null;
                        this.attachSlotUI            = surfaceSlotUI;
                        this.attachSlotUI.dragItemUI = this;

                        this.GetComponent <UIHeroHeadItem>().UpdateUI(surfaceSlotUI.model_UnitGroup.heroId);

                        // 更新Unit列表
                        _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                    }
                    else
                    {
                        base.OnDragDropRelease(surface);
                    }

                    UpdateHeroScrollView();
                    return;
                }
            }

                // (2) slot区域有item
                {
                    UIHeroDragItem surfaceDragItemUI = surface.GetComponent <UIHeroDragItem>();

                    if (surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI != null)
                    {
                        UIHeroSlot surfaceSlotUI = surfaceDragItemUI.attachSlotUI;

                        Model_Formation.RESULT result = ExchangeBattleHero(surfaceSlotUI.model_UnitGroup);
                        if (result == Model_Formation.RESULT.SUCCESS)
                        {
                            // 更显UI显示数据
                            UIHeroSlot     sourceSlotUI = this.attachSlotUI;
                            UIHeroDragItem sourceDragUI = this;

                            UIHeroSlot     targetSlotUI = surfaceDragItemUI.attachSlotUI;
                            UIHeroDragItem targetDragUI = surfaceDragItemUI;

                            UIHeroHeadItem sourceSlotItemUI = sourceDragUI.gameObject.GetComponent <UIHeroHeadItem>();
                            UIHeroHeadItem targetSlotItemUI = targetDragUI.gameObject.GetComponent <UIHeroHeadItem>();

                            Model_UnitGroup source = attachSlotUI.model_UnitGroup;
                            Model_UnitGroup target = targetSlotUI.model_UnitGroup;

                            sourceSlotItemUI.UpdateUI(source.heroId);
                            targetSlotItemUI.UpdateUI(target.heroId);

                            this.transform.position = sourceSlotUI.transform.position;

                            // 更新上阵Unit显示数量
                            _slotUIManager.UpdateBattleUnitNum(source);
                            _slotUIManager.UpdateBattleUnitNum(target);

                            // 更新Unit列表
                            _heroPanel._battleFormationPanel.UpdateCurrectUnitList();
                        }
                        else
                        {
                            base.OnDragDropRelease(surface);
                        }

                        UpdateHeroScrollView();

                        return;
                    }
                }

                // 2 移动到scrollView 下阵
                {
                    UIHeroDragItem surfaceDragItemUI   = surface.GetComponent <UIHeroDragItem>();
                    bool           isScrllViewCollider = surface.gameObject.name.Equals("scrollView_bg_hero");

                    if ((surfaceDragItemUI != null && surfaceDragItemUI.attachSlotUI == null) ||
                        isScrllViewCollider)
                    {
                        ExitBattleHero();

                        attachSlotUI.dragItemUI = null;

                        UpdateHeroScrollView();

                        _slotUIManager.UpdateBattleUnitNum(attachSlotUI.model_UnitGroup);

                        DestroyImmediate(this.gameObject);
                        return;
                    }
                }

                // 拖动到其他区域
                if (attachSlotUI != null)
                {
                    this.transform.position = attachSlotUI.transform.position;
                    return;
                }

                break;
            }
        }
        base.OnDragDropRelease(surface);
    }