Example #1
0
    void ShowItem()
    {
        if (PlayerData.BagInfos == null)
        {
            return;
        }
        int count = 0;

        foreach (var item in PlayerData.BagInfos)
        {
            if (item.Value.slot < 1201 && item.Value.num > 0)
            {
                var     prop = ResourceMgr.CreateObj("GUIs/Bag/Prop");
                BagProp bp   = prop.GetComponent <BagProp>();
                bp.SetPropInfo(item.Value);
                prop.transform.SetParent(blocks[count].transform, false);
                props.Add(bp);
                bp.gameObject.name = item.Value.id.ToString();
                count++;
            }
        }
    }
Example #2
0
    public void OnEndDrag(PointerEventData eventData)
    {
        GameObject hitObject  = eventData.pointerCurrentRaycast.gameObject;
        int        instanceId = Convert.ToInt32(gameObject.name);
        int        propId     = PlayerData.BagInfos[instanceId].propId;

        Debug.LogError(hitObject);

        if (hitObject == null)
        {
            ResetParent(father.gameObject);
        }
        else
        {
            BagBlock block = hitObject.GetComponent <BagBlock>();

            if (block != null)
            {
                if (block.type == BagBlock.BlockType.CharacterBag)
                {
                    if (hitObject.name == ConfigInfo.GetProp(info.propId.ToString()).Type)
                    {
                        ResetParent(hitObject, true);
                        SendPropEquipInfo(instanceId, propId, Convert.ToInt32(block.name));
                    }
                    else
                    {
                        ResetParent(father.gameObject);
                    }
                }
                else if (block.type == BagBlock.BlockType.Bag)
                {
                    ResetParent(hitObject, true);
                    SendPropEquipInfo(instanceId, propId, Convert.ToInt32(block.name));
                }
                else
                {
                    ResetParent(father.gameObject);
                }
            }
            else
            {
                BagProp bp = hitObject.GetComponent <BagProp>();
                if (bp != null)
                { ///替换装备
                    if (bp.transform.parent.GetComponent <BagBlock>().type == BagBlock.BlockType.CharacterBag)
                    {
                        ResetParent(hitObject.transform.parent.gameObject, true);
                        BagInfoEquipReq request = new BagInfoEquipReq();

                        PropInfo swapedInfo = PlayerData.BagInfos[Convert.ToInt32(hitObject.name)];
                        PropInfo dragInfo   = PlayerData.BagInfos[Convert.ToInt32(gameObject.name)];

                        EquipPropInfo reprop = new EquipPropInfo();
                        reprop.id     = swapedInfo.id;
                        reprop.propId = swapedInfo.propId;


                        EquipPropInfo prop = new EquipPropInfo();
                        prop.id     = dragInfo.id;
                        prop.propId = dragInfo.propId;

                        reprop.slot = dragInfo.slot;
                        int swapSlot = swapedInfo.slot;
                        prop.slot = swapSlot;


                        request.playerId = PlayerData.Me.info.id;
                        request.equipedProps.Add(reprop);
                        request.equipedProps.Add(prop);

                        MobaNetwork.Send((ushort)MessageId.EBagInfoEquipReq, request);
                    }
                    else
                    {
                        ResetParent(father.gameObject);
                    }
                }
                else
                {
                    ResetParent(father.gameObject);
                }
            }
        }
        icon.raycastTarget = true;
    }