Exemplo n.º 1
0
    /// <summary>
    /// 拖拽结束后的处理
    /// </summary>
    /// <param name="oldTransform">被拖拽物品原所在的格子</param>
    /// <param name="enterTransform">被拖拽物品现所在的格子</param>
    private void BagItemGrid_OnLeftEndDrag(Transform oldTransform, Transform enterTransform)
    {
        if (isDrag == true)
        {
            isDrag = false;

            dragItem.Hide();
            if (enterTransform == null)  //将物品扔出背包
            {
                Destroy(oldTransform.GetChild(1).gameObject);
                BagItemGrid bagItemGrid = oldTransform.gameObject.GetComponent <BagItemGrid>();
                bagItemGrid.Clear();
            }
            else if (enterTransform.tag == Tags.grid)
            {
                BagItemGrid bagItemGrid = oldTransform.gameObject.GetComponent <BagItemGrid>();
                BagItemGrid enterGrid   = enterTransform.gameObject.GetComponent <BagItemGrid>();
                if (enterTransform.childCount == 1) //将物品拖到一个新的地方
                {
                    GameObject itemGo = Instantiate(bagItem, enterTransform);
                    itemGo.transform.localPosition = Vector3.zero;
                    enterGrid.SetByID(bagItemGrid.id, bagItemGrid.count);
                    Destroy(oldTransform.GetChild(1).gameObject);
                    bagItemGrid.Clear();
                }
                else //物品位置交换
                {
                    int oldID    = bagItemGrid.id;
                    int oldCount = bagItemGrid.count;
                    oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
                    bagItemGrid.SetByID(enterGrid.id, enterGrid.count);

                    enterGrid.SetByID(oldID, oldCount);
                }
            }
            else if (enterTransform.tag == Tags.shotCutGrid)
            {
                ShotCutGrid shotCutGrid = enterTransform.GetComponent <ShotCutGrid>();
                BagItemGrid bagItemGrid = oldTransform.GetComponent <BagItemGrid>();
                if (bagItemGrid.info.type == objectType.Drug)
                {
                    shotCutGrid.id = bagItemGrid.id;
                    oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
                    Image      image = shotCutGrid.transform.FindChild("Image").GetComponent <Image>();
                    ObjectInfo info  = ObjectsInfo._instance.GetObjectInfoById(shotCutGrid.id);
                    image.gameObject.SetActive(true);
                    string path = "Icon/" + info.name_Icon;
                    image.sprite = Resources.Load(path, typeof(Sprite)) as Sprite;
                }
            }
            else //拖到了背包的其他地方,位置复原
            {
                oldTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = true;
            }
        }
    }
Exemplo n.º 2
0
    private void Update()
    {
        if (Input.GetKeyDown(KeyCode.X))
        {
            GetID(Random.Range(2001, 2023));
        }

        Vector2 position;

        RectTransformUtility.ScreenPointToLocalPointInRectangle
            (GameObject.Find("Bag").transform as RectTransform, Input.mousePosition, uiCamera, out position);
        if (isDrag)
        {
            dragItem.SetLocalPositon(position);
        }
        if (showingDec)
        {
            itemDecUI.SetLocalPosition(position);
        }


        //按下右键穿戴装备 or 使用药水
        if (Input.GetMouseButtonDown(1) && dressGrid != null)
        {
            if (dressGrid.id != 0)
            {
                switch (dressGrid.info.type)
                {
                case objectType.Drug:
                    break;

                case objectType.Equip:      //穿戴装备

                    dressSuccess = Equipment._instanceEquip.DressEquipment(dressGrid.info);
                    if (dressSuccess)
                    {
                        if (dressGrid.count > 1)      //判断装备数量  大于1则数量减一更新显示
                        {
                            dressGrid.count--;
                            dressGrid.itemCount.text = dressGrid.count.ToString()
                            ;
                        }
                        else
                        {      //如果装备数量为1  则删除图标并清空格子
                            Destroy(dressGrid.transform.GetChild(1).gameObject);
                            dressGrid.Clear();
                        }
                    }
                    break;
                }
            }
        }
    }