private void GridUI_OnLeftEndDrag(Transform preTransform, Transform nowTransform)
    {
        isDrag = false;
        dragItem.Hide();

        if (nowTransform == null)                 //拖到背包外面,扔掉
        {
            ItemModel.DelItem(preTransform.name); //删掉背包数据库中原来格子里的数据
        }
        else if (nowTransform.tag == "Grid")      //拖到了另一个格子
        {
            if (nowTransform.childCount == 0)     //是空格子,放入
            {
                Item preItem = ItemModel.GetItem(preTransform.name);
                CreateItem(preItem, nowTransform);
                ItemModel.DelItem(preTransform.name);
            }
            else                               //不是空格子,交换
            {
                Destroy(nowTransform.GetChild(0).gameObject);
                Item preItem = ItemModel.GetItem(preTransform.name);
                Item nowItem = ItemModel.GetItem(nowTransform.name);

                CreateItem(preItem, nowTransform);
                CreateItem(nowItem, preTransform);
            }
        }
        else                                //不在背包的格子里面,放回去
        {
            Item item = ItemModel.GetItem(preTransform.name);
            CreateItem(item, preTransform);
        }
    }
示例#2
0
 private void GridUI_OnLeftEndDrag(Transform beginGrid, Transform endGrid)
 {
     if (endGrid == null)//丢弃物品
     {
         ItemModel.DeleteItem(beginGrid.name);
     }
     else if (endGrid.tag == "Grid")  //放入一个空的或有物体的格子中
     {
         if (endGrid.childCount == 0) //该格子为空
         {
             Item item = ItemModel.GetItem(beginGrid.name);
             this.PutIntoGrid(item, endGrid);
             //在完成物品转移以后移除数据
             ItemModel.DeleteItem(beginGrid.name);
         }
         else//目标格子中已有物品
         {
             Item beginItem = ItemModel.GetItem(beginGrid.name);
             Item endItem   = ItemModel.GetItem(endGrid.name);
             //把目标格子中的已有物品先删除掉
             Destroy(endGrid.GetChild(0).gameObject);
             this.PutIntoGrid(beginItem, endGrid);
             this.PutIntoGrid(endItem, beginGrid);
         }
     }
     else//放到背包外面
     {
         Item item = ItemModel.GetItem(beginGrid.name);
         this.PutIntoGrid(item, beginGrid);
     }
     IsDrag = false;
     DragItemUI.Hide();
 }
示例#3
0
    private void GridUI_OnLeftEndDrag(Transform prevTransform, Transform endTransform)
    {
        isDrag = false;
        DragItemUI.Hide();
        Item item = ItemModel.GetItem(prevTransform.name);


        if (endTransform == null)//拖动到没UI的地方
        {
            CreateNewItem(item, prevTransform);
        }
        //拖动到指定的监视器里
        else if (endTransform.tag == "ItemArea")
        {
            string TargetName = endTransform.name;
            //Debug.Log(TargetName);
            if (item.AttentionStates.Contains(TargetName))
            {
                if (!m_GameModel.HandleItem(item, TargetName))
                {
                    CreateNewItem(item, prevTransform);
                }
            }
            else
            {
                CreateNewItem(item, prevTransform);
            }
        }
        else//拖动到无效的UI地方
        {
            //Debug.Log(endTransform.name);
            CreateNewItem(item, prevTransform);
        }
    }
示例#4
0
 private void GridUI_OnLeftEndDrag(Transform prevTransform, Transform enterTransform)
 {
     isDrag = false;
     DragItemUI.Hide();
     if (enterTransform == null)
     {
         ItemModel.DeleteItem(prevTransform.name);
     }
     else if (enterTransform.tag == "Grid")
     {
         if (enterTransform.childCount == 0)
         {
             Item item = ItemModel.GetItem(prevTransform.name);
             this.CreateNewItem(item, enterTransform);
             ItemModel.DeleteItem(prevTransform.name);
         }
         else
         {
             //删除原来的物品
             Destroy(enterTransform.GetChild(0).gameObject);
             //获取数据
             Item prevGirdItem  = ItemModel.GetItem(prevTransform.name);
             Item enterGirdItem = ItemModel.GetItem(enterTransform.name);
             //交换的两个物体
             this.CreateNewItem(prevGirdItem, enterTransform);
             this.CreateNewItem(enterGirdItem, prevTransform);
         }
     }
     else
     {
         Item item = ItemModel.GetItem(prevTransform.name);
         this.CreateNewItem(item, prevTransform);
     }
 }
示例#5
0
    private void GridUI_OnLeftEndDrag(Transform oldTransform, Transform enterTransform)
    {
        isDrag = false;
        dragItemUI.Hide();
        if (enterTransform == null)
        {
            ItemModel.DeleteItem(oldTransform.name);
        }
        else if (enterTransform.tag == "Grid")
        {
            if (enterTransform.childCount == 0)
            {
                Item item = ItemModel.GetItem(oldTransform.name);
                CreatNewItem(item, enterTransform);
                ItemModel.DeleteItem(oldTransform.name);
            }
            else
            {
                Destroy(enterTransform.GetChild(0).gameObject);

                Item oldGridItem   = ItemModel.GetItem(oldTransform.name);
                Item enterGridItem = ItemModel.GetItem(enterTransform.name);

                this.CreatNewItem(oldGridItem, enterTransform);
                this.CreatNewItem(enterGridItem, oldTransform);
            }
        }
        else
        {
            Item item = ItemModel.GetItem(oldTransform.name);
            CreatNewItem(item, enterTransform);
        }
    }
示例#6
0
    private void GridUI_OnLeftEndDrag(Transform preTransform, Transform enterTransform)
    {
        isDrag = false;
        DragItemUI.Hide();

        if (enterTransform == null)   //扔东西
        {
            ItemModel.DeleteItem(preTransform.name);
            Debug.LogWarning("物品已扔");
        }
        else if (enterTransform.tag == "Grid")   //拖到格子里
        {
            if (enterTransform.childCount == 0)  //直接扔进去
            {
                Item item = ItemModel.GetItem(preTransform.name);
                this.CreateNewItem(item, enterTransform);
                ItemModel.DeleteItem(preTransform.name);
            }
            else  //交换
            {
                Destroy(enterTransform.GetChild(0).gameObject);
                Item preGridItem   = ItemModel.GetItem(preTransform.name);
                Item enterGridItem = ItemModel.GetItem(enterTransform.name);
                this.CreateNewItem(preGridItem, enterTransform);
                this.CreateNewItem(enterGridItem, preTransform);
            }
        }
        else   //拖到缝隙里就还原
        {
            Item item = ItemModel.GetItem(preTransform.name);
            this.CreateNewItem(item, preTransform);
        }
    }
示例#7
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;
            }
        }
    }
示例#8
0
    private void OnEndDragEvent(Transform preTransform, Transform curTransform)
    {
        //丢掉物品
        if (curTransform == null)
        {
            packPackItemDic.Remove(preTransform);
        }
        else if (curTransform.CompareTag("grid"))//交换物品
        {
            if (curTransform.childCount == 0)
            {
                //拖拽到空格子
                if (packPackItemDic.ContainsKey(preTransform))
                {
                    BaseItem item = packPackItemDic[preTransform];
                    packPackItemDic.Remove(preTransform);
                    CreateItem(item, curTransform);
                }
            }
            else
            {
                //交换两个格子item
                if (packPackItemDic.ContainsKey(preTransform) && packPackItemDic.ContainsKey(curTransform))
                {
                    Destroy(curTransform.GetChild(0).gameObject);

                    BaseItem preItem = packPackItemDic[preTransform];
                    BaseItem curItem = packPackItemDic[curTransform];

                    CreateItem(preItem, curTransform);
                    CreateItem(curItem, preTransform);
                }
            }
        }
        else //回到原位
        {
            if (packPackItemDic.ContainsKey(preTransform))
            {
                BaseItem item = packPackItemDic[preTransform];
                CreateItem(item, preTransform);
            }
        }


        dragItemUI.Hide();
        isDrag = false;
    }
示例#9
0
 private void GridUI_OnLeftEndDrag(Transform preTransform, Transform gridTransform)
 {
     isDrag = false;
     dragItemUI.Hide();
     if (gridTransform == null)
     {
         //丢弃当前Item
         ItemModel.DeleteItem(preTransform.name);
         Debug.Log("丢弃");
     }
     else
     {
         //如果拖到另外一个或者当前的格子里面
         if (gridTransform.tag == "Grid")
         {
             //如果Grid下面没有子物体则直接扔进去
             if (gridTransform.childCount == 0)
             {
                 Item item = ItemModel.GetItem(preTransform.name);
                 this.CreateNewItem(item, gridTransform);
                 ItemModel.DeleteItem(preTransform.name);
             }
             //执行交换
             else
             {
                 Destroy(gridTransform.GetChild(0).gameObject);
                 //获取数据
                 Item prevGirdItem  = ItemModel.GetItem(preTransform.name);
                 Item enterGirdItem = ItemModel.GetItem(gridTransform.name);
                 //交换的两个物体
                 this.CreateNewItem(prevGirdItem, gridTransform);
                 this.CreateNewItem(enterGirdItem, preTransform);
             }
         }
         //如果拖到UI的其他地方则还原
         else
         {
             Item item = ItemModel.GetItem(preTransform.name);
             this.CreateNewItem(item, preTransform);
         }
     }
 }
示例#10
0
    /// <summary>
    /// 配置表或者数据库加载所有道具到list
    /// 加载draguiItem
    /// </summary>
    private void Load()
    {
        itemDic = new Dictionary <int, BaseItem>();
        var item1 = new SkillItem(0, "技能1", 10);
        var item2 = new WeaponItem(1, "武器1", 99);
        var item3 = new WeaponItem(3, "武器2", 99);
        var item4 = new WeaponItem(4, "技能2", 99);

        itemDic[item1.Id] = item1;
        itemDic[item2.Id] = item2;
        itemDic[item3.Id] = item3;
        itemDic[item4.Id] = item4;

        var        res         = Resources.Load("backPack/dragItem");
        GameObject dragItemObj = Instantiate(res) as GameObject;

        dragItemUI = dragItemObj.GetComponent <DragItemUI>();
        dragItemUI.transform.SetParent(transform);
        dragItemUI.Hide();
    }
示例#11
0
    public void GridUI_OnLeftEndDrag(Transform GridTransform, Transform GridEndTransform)
    {
        isDrag = false;
        DragItemUi.Hide();

        /*判断拖拽结束时指着的格子上有没有物体,如果有就进行交换,没有就把物品直接放上去*/


        if (GridEndTransform == null)                 //扔东西
        {
            ItemModel.DeleteItem(GridTransform.name); //删除之前格子的信息
            Debug.LogWarning("物品已扔");
        }


        else if (GridEndTransform.tag == "Grid")                   //如果拖到另一个格子或者当前格子里里
        {
            if (GridEndTransform.childCount == 0)                  //直接扔进去
            {
                Item item = ItemModel.GetItem(GridTransform.name); //获得之前的数据
                this.CreateNewItem(item, GridEndTransform);        //创建出新的Item
                ItemModel.DeleteItem(GridTransform.name);          //删除之前格子的信息
            }
            else//交换
            {
                Item item1 = ItemModel.GetItem(GridTransform.name);    //获得之前的数据
                Item item2 = ItemModel.GetItem(GridEndTransform.name); //获得之后的数据
                Destroy(GridEndTransform.GetChild(0).gameObject);      //将该位置的物体删除
                ItemModel.DeleteItem(GridTransform.name);              //删除之后格子的信息
                ItemModel.DeleteItem(GridTransform.name);              //删除之前格子的信息
                this.CreateNewItem(item1, GridEndTransform);           //创建出新的Item
                this.CreateNewItem(item2, GridTransform);              //创建出新的Item
            }
        }
        else//如果拖到UI其他地方
        {
            Item item = ItemModel.GetItem(GridTransform.name);//获得之前的数据
            this.CreateNewItem(item, GridTransform);//创建出新的Item
        }
    }
示例#12
0
    private void GridUI_OnLeftEndDrag(Transform prevTransform, Transform enterTransform)
    {
        isDrag = false;
        DragItemUI.Hide();

        if (enterTransform == null)//扔东西
        {
            ItemModel.DeleteItem(prevTransform.name);
            Debug.LogWarning("物品已扔");
        }
        else if (enterTransform.tag == "Grid")  //拖到另一个或者当前格子里
        {
            if (enterTransform.childCount == 0) //直接扔进去
            {
                Item item = ItemModel.GetItem(prevTransform.name);
                this.CreatNewItem(item, enterTransform);
                ItemModel.DeleteItem(prevTransform.name);
            }
            else //交换
            {
                //删除原来的物品
                Destroy(enterTransform.GetChild(0).gameObject);
                //获取数据
                Item prevGirdItem  = ItemModel.GetItem(prevTransform.name);
                Item enterGirdItem = ItemModel.GetItem(enterTransform.name);
                //交换的两个物体
                this.CreatNewItem(prevGirdItem, enterTransform);
                this.CreatNewItem(enterGirdItem, prevTransform);
            }
        }
        else//拖到UI的其他地方,让他还原
        {
            Item item = ItemModel.GetItem(prevTransform.name);
            this.CreatNewItem(item, prevTransform);
        }
    }
示例#13
0
 private void Start()
 {
     DragITemUI.Hide();
     tooltipUI.Hide();
 }
示例#14
0
    /// <summary>
    /// 结束拖拽,实现物品的交换或者恢复原位置
    /// </summary>
    /// <param name="prevTransform"></param>
    /// <param name="enterTransform"></param>
    void GridUI_OnLeftEndDrag(Transform prevTransform, Transform enterTransform)
    {
        isDrag = false;

        m_DragItemUI.Hide();

        if (enterTransform == null) //拖到其他位置,丢弃
        {
            ItemModel.DeleteItem(prevTransform.name);
            Debug.Log("物品已扔");
        }
        else if (enterTransform.tag == "Grid")      //和别的网格交换或者自己交换
        {
            if (prevTransform == enterTransform)    //和自己交换
            {
                Debug.Log("果然是同一位置!");

                Item item = ItemModel.GetItem(prevTransform.name);

                if (item != null)
                {
                    this.CreateNewItem(item, prevTransform);
                }
            }
            else                                    //和别的网格交换
            {
                if (enterTransform.childCount == 0) //如果拖拽到的位置为空
                {
                    Item item = ItemModel.GetItem(prevTransform.name);

                    //保证拖拽的网格内部有物体,如果没有,则不会创建新的物体
                    if (item == null)
                    {
                        return;
                    }

                    ItemModel.DeleteItem(prevTransform.name);
                    this.CreateNewItem(item, enterTransform);
                }
                else   //有物体
                {
                    Destroy(enterTransform.FindChild("Item(Clone)").gameObject);

                    Item curItem  = ItemModel.GetItem(prevTransform.name);
                    Item nextItem = ItemModel.GetItem(enterTransform.name);

                    this.CreateNewItem(curItem, enterTransform);
                    this.CreateNewItem(nextItem, prevTransform);
                }
            }
        }
        else //拖到别的位置,恢复到自身状态
        {
            Item item = ItemModel.GetItem(prevTransform.name);

            if (item != null)
            {
                this.CreateNewItem(item, prevTransform);
            }
        }
    }
示例#15
0
    /// <summary>
    /// 对事件OnLeftEndDrag的响应
    /// 在物品拖动结束时执行
    /// </summary>
    /// <param name="prevGridTransfrom"></param>
    /// <param name="enterTransfrom"></param>
    public void GridUI_OnLeftEndDrag(Transform prevGridTransfrom, Transform enterTransfrom)
    {
        isDrag = false;
        dragItemUI.Hide();

        //判断是否进入了有意义的格子
        if (enterTransfrom == null)
        {
            //prevGridTransfrom.gameObject.GetComponent<GridUI>().ItemUIGo.SetActive(true);
        }
        else
        {
            if (enterTransfrom.tag == "Grid")//假如进入了格子
            {
                //获取前后两个GridUI的引用
                prevgrid  = prevGridTransfrom.gameObject.GetComponent <GridUI>();
                entergrid = enterTransfrom.gameObject.GetComponent <GridUI>();

                //判断起始格
                if (prevgrid.Type.Equals(GridUI.GridType.Bag) && InventoryManager.GetItem(prevgrid.Index) != null)//如果是背包格且该格有物品
                {
                    //判断进入格
                    if (entergrid.Type.Equals(GridUI.GridType.Bag))//如果进入背包格,则交换位置
                    {
                        InventoryManager.SwitchItem(prevgrid.Index, entergrid.Index);
                    }
                    else if (entergrid.Type.Equals(GridUI.GridType.Shop))//如果是商店格,则调用方法出售道具
                    {
                        string warnStr = string.Format("即将以 {0} Gold 出售 ", InventoryManager.GetItem(prevgrid.Index).BasePrice) + InventoryManager.GetItem(prevgrid.Index).Name + " \n是否确定";
                        EventCenter.Broadcast <string, WarningMsg.TargetMethod>(EventCode.ShowWarningMsg, warnStr, SellItem);
                    }
                    else if (entergrid.Type.Equals(GridUI.GridType.Hand))                                                                                                           //如果是手部装备格
                    {
                        if (InventoryManager.GetItem(prevgrid.Index).Type.Equals(Item.ItemType.Tool) || InventoryManager.GetItem(prevgrid.Index).Type.Equals(Item.ItemType.Weapon)) //物品必须是工具或武器
                        {
                            if (StateManager.instance.Hand == null)                                                                                                                 //如果手上没东西,直接装备
                            {
                                StateManager.instance.Hand = InventoryManager.GetItem(prevgrid.Index);
                                Debug.Log(StateManager.instance.Hand.Name);
                                InventoryManager.DeleteItem(prevgrid.Index);
                            }
                            else //如果手上有东西,交换
                            {
                                Item buf = InventoryManager.GetItem(prevgrid.Index);
                                InventoryManager.DeleteItem(prevgrid.Index);
                                InventoryManager.SaveItem(StateManager.instance.Hand);
                                StateManager.instance.Hand = buf;
                            }
                        }
                    }
                    else //其他地方无事发生
                    {
                    }
                }
                else if (prevgrid.Type.Equals(GridUI.GridType.Shop) && ShopManager.instance.GetItem(prevgrid.Index) != null)//如果是商店格且该格有物品
                {
                    //判断进入格
                    if (entergrid.Type.Equals(GridUI.GridType.Bag))//如果进入背包格,则调用方法购买道具
                    {
                        string warnStr = string.Format("即将以 {0} Gold 购买 ", ShopManager.instance.GetItem(prevgrid.Index).BasePrice) + ShopManager.instance.GetItem(prevgrid.Index).Name + " \n是否确定";
                        EventCenter.Broadcast <string, WarningMsg.TargetMethod>(EventCode.ShowWarningMsg, warnStr, BuyItem);
                    }
                    else //其他格子无事发生
                    {
                    }
                }
            }
            else
            {
                //prevGridTransfrom.gameObject.GetComponent<GridUI>().ItemUIGo.SetActive(true);
            }
        }


        EventCenter.Broadcast(EventCode.OnBagUIUpdate);
    }