Ejemplo n.º 1
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        if (surface != null)
        {
            if (surface.tag == Tags.inventoryItemGrid)
            {
                if (surface != this.transform.parent.gameObject)    // 拖拽到空格子
                {
                    InventoryItemGrid oldGrid = this.transform.parent.GetComponent <InventoryItemGrid>();
                    InventoryItemGrid newGrid = surface.GetComponent <InventoryItemGrid>();
                    newGrid.SetId(oldGrid.GetId(), oldGrid.GetNum());
                    oldGrid.ClearInfo();
                }
            }
            else if (surface.tag == Tags.inventoryItem)             // 拖拽到有物体的格子
            {
                InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>();
                int id  = grid1.GetId();
                int num = grid1.GetNum();
                grid1.SetId(grid2.GetId(), grid2.GetNum());
                grid2.SetId(id, num);
            }
        }

        ResetPos();
    }
Ejemplo n.º 2
0
    public bool UseItem()
    {
        ItemDes._Instance.Hide(itemId);
        ObjectInfo info = ObjectsInfo._Instance.GetObjectInfo(itemId);

        if (info.type == ObjectType.Equip)
        {
            bool dressSuccess = Equipment._Instance.Dress(itemId);
            if (dressSuccess)
            {
                InventoryItemGrid itemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>();
                itemGrid.SubNum();
            }
        }
        else if (info.type == ObjectType.Drug)
        {
            InventoryItemGrid itemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>();
            if (itemGrid.SubNum())
            {
                playerStatus.PlusHpAndMp(info.hp, info.mp);
                return(true);
            }
        }
        return(false);
    }
Ejemplo n.º 3
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        if (surface != null)
        {
            if (surface.tag == Tags.Inventory_item_grid)                 //当拖放到了一个空的格子里面
            {
                if (surface == this.transform.parent.gameObject)         //拖放到了自己的格子里面

                {
                }
                else
                {
                    InventoryItemGrid oldParent = this.transform.parent.GetComponent <InventoryItemGrid> ();
                    this.transform.parent = surface.transform;
                    ResetPosition();
                    InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid> ();
                    newParent.SetId(oldParent.id, oldParent.num);
                    oldParent.ClearInfo();
                }
            }
            else if (surface.tag == Tags.Inventory_item)                   //当拖放到了一个有物品的格子里面
            {
                InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid> ();
                InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid> ();
                int id  = grid1.id;
                int num = grid1.num;
                grid1.SetId(grid2.id, grid2.num);
                grid2.SetId(id, num);
            }
        }
        ResetPosition();
    }
Ejemplo n.º 4
0
 void OnItemPointerEnter(int id, InventoryItemGrid inventoryItemGrid, GameObject inventoryItemGo)
 {
     this.id = id;
     this.inventoryItemGrid = inventoryItemGrid;
     this.inventoryItemGo   = inventoryItemGo;
     isPointEnter           = true;
     labelUI.ShowLabel(id);
 }
Ejemplo n.º 5
0
 void IPointerEnterHandler.OnPointerEnter(PointerEventData eventData)
 {
     if (PointerEnter != null)
     {
         InventoryItemGrid inventoryItemGrid = transform.GetComponentInParent <InventoryItemGrid>();
         PointerEnter(inventoryItemGrid.id, inventoryItemGrid, gameObject);
     }
 }
Ejemplo n.º 6
0
    //拾取到id物品,并添加到物品栏里面
    public void AddItemToBag(string id, int count = 1)
    {
        InventoryItemGrid grid = null;

        //查找是否存在该物品,
        foreach (InventoryItemGrid temp in itemGrid)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }

        //存在物品数量+1
        if (grid != null)
        {
            grid.PlusNumber(count);
        }
        else
        {
            //不存在,判断背包是否满
            foreach (InventoryItemGrid temp in itemGrid)
            {
                //当前格子id为空,则未满
                if (temp.id == "")
                {
                    grid = temp;
                    break;
                }
            }

            //背包未满,则创建物体
            if (grid != null)
            {
                InventoryItem item = grid.GetComponentInChildren <InventoryItem>();

                //如果不存在隐藏的Item则创建
                if (item == null)
                {
                    //NGUI的实例化
                    GameObject itemGo = grid.gameObject.AddChild(inventoryItem);
                    itemGo.transform.localPosition = Vector3.zero;

                    //格子深度为5,数量为7,物品为6
                    itemGo.GetComponent <UISprite>().depth = 6;
                    grid.SetId(id, count);
                }
                else
                {
                    item.GetComponent <UISprite>().enabled = true;
                    grid.SetId(id, count);
                }
            }
        }
    }
Ejemplo n.º 7
0
        private void ViewInventoryDetailTab(int id, bool isInventoryItemIncluded)
        {
            using (var repository = new InventoryRepository())
            {
                if (id > 0)
                {
                    IsWork     = false;
                    RibbonMode = RibbonMode.Detail;

                    ChangeControlsEnabled(DetailTab.Controls, false, false);

                    var inventory = repository.GetInventory(id);

                    IDTextBox.Text = inventory.ID.ToString();
                    if (inventory.IsApproved)
                    {
                        EnteredDatePicker.ResetMinDate();
                    }
                    else
                    {
                        EnteredDatePicker.MinDate = repository.GetMinEntered();
                    }
                    EnteredDatePicker.Value = inventory.Entered;

                    if (isInventoryItemIncluded)
                    {
                        InventoryItemGrid.DataSource = repository.GetInventoryItems(id);
                        IsInventoryItemChanged       = false;
                        InventoryItemGrid.Enabled    = !inventory.IsApproved;
                    }

                    InventoryTabControl.SelectedTab = DetailTab;

                    InventoryItemGrid.ClearSelection();
                }
                else
                {
                    IsWork     = true;
                    RibbonMode = RibbonMode.Edit;

                    ChangeControlsEnabled(DetailTab.Controls, true, true);

                    IDTextBox.Enabled         = false;
                    IDTextBox.Text            = repository.GetNextInventoryID().ToString();
                    EnteredDatePicker.MinDate = repository.GetMinEntered();

                    InventoryTabControl.SelectedTab = DetailTab;
                }
            }
        }
Ejemplo n.º 8
0
    /// <summary>
    /// 查找是否存在该物品
    /// </summary>
    public InventoryItemGrid CheckItemNum(string id)
    {
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGrid)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }

        return(grid);
    }
Ejemplo n.º 9
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        Debug.Log(surface.tag);
        if (surface != null)
        {
            if (surface.tag == Tags.inventoryItemGrid)      //当拖放到空格子里
            {
                if (surface == transform.parent.gameObject) //当拖动到自己的格子里
                {
                }
                else
                {
                    InventoryItemGrid oldParent = transform.parent.GetComponent <InventoryItemGrid>();
                    InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>();
                    transform.parent = surface.transform;
                    newParent.SetId(oldParent.id, oldParent.num);

                    oldParent.ClearInfo();  //清空信息
                }
            }
            else if (surface.tag == Tags.inventoryItem)  //当拖放到有物品的格子里
            {
                InventoryItemGrid grid1 = transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>();
                int id  = grid1.id;
                int num = grid1.num;
                grid1.SetId(grid2.id, grid2.num);
                grid2.SetId(id, num);
            }
            else if (surface.tag == Tags.shortCut)  //当拖放到快捷栏时
            {
                surface.GetComponent <ShortCutGrid>().SetInventory(id);
            }
            else //当拖放到空白的地方时
            {
            }

            ResetPosition();
        }
        else
        {
            ResetPosition();
        }
    }
Ejemplo n.º 10
0
    /// <summary>
    /// 拾取到Id的物品,并添加到物品栏里面
    /// 处理拾取物品的功能
    /// </summary>
    /// <param name="id"></param>
    public void GetId(int id, int count = 1)
    {
        //第一步 查找在所有的物品中是否存在该物品
        //第二步 如果存在,让num +1;

        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }

        //存在的情况
        if (grid != null)
        {
            grid.PlusNumber(count);
        }

        //不存在的情况
        else
        {
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == 0)
                {
                    grid = temp;
                    break;
                }
            }
            if (grid != null)
            {
                //第三步 如果不存在,查找空的方格,然后把新创建的Inventory放到这个空的方格中;
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItem);
                itemGo.transform.localPosition         = Vector3.zero;
                itemGo.GetComponent <UISprite>().depth = 8;
                grid.SetId(id, count);
            }
        }
    }
Ejemplo n.º 11
0
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        if (surface != null)
        {
            if (surface.tag == Tags.inventory_item_grid)
            {
                InventoryItemGrid oldItemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid newItemGrid = surface.GetComponent <InventoryItemGrid>();
                if (newItemGrid != oldItemGrid)
                {
                    this.transform.parent = surface.transform;
                    newItemGrid.SetId(oldItemGrid.id, oldItemGrid.currentNumb);
                    oldItemGrid.ClearInfo();
                }
            }
            else if (surface.tag == Tags.inventory_item)
            {
                InventoryItemGrid oldItemGrid = gameObject.transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid newItemGrid = surface.transform.parent.GetComponent <InventoryItemGrid>();

                int tempId  = newItemGrid.id;
                int tempNum = newItemGrid.currentNumb;

                newItemGrid.ClearInfo();
                this.transform.parent = newItemGrid.gameObject.transform;
                newItemGrid.SetId(oldItemGrid.id, oldItemGrid.currentNumb);

                oldItemGrid.ClearInfo();
                InventoryItem newItem = newItemGrid.GetComponentInChildren <InventoryItem>();
                newItem.gameObject.transform.parent = oldItemGrid.gameObject.transform;
                oldItemGrid.SetId(tempId, tempNum);
                newItem.ResetPosition();
            }
            else if (surface.tag == Tags.shortcut)
            {
                ShortcutGrid shortcutGrid = surface.GetComponent <ShortcutGrid>();
                shortcutGrid.SetInventory(itemId);
            }
            isHover = false;
        }
        ResetPosition();
    }
Ejemplo n.º 12
0
    public void OnEndDrag(PointerEventData eventData)
    {
        transform.SetParent(originalParent);
        if (eventData.pointerCurrentRaycast.gameObject != null)
        {
            if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.Inventory_item_grid.ToString()) //当拖放到空格子中
            {
                if (eventData.pointerCurrentRaycast.gameObject == originalParent.gameObject)           //拖放到自己原本的格子中
                {
                }
                else
                {
                    InventoryItemGrid oldParent = originalParent.GetComponent <InventoryItemGrid>();

                    this.transform.parent = eventData.pointerCurrentRaycast.gameObject.transform;
                    InventoryItemGrid newParent = eventData.pointerCurrentRaycast.gameObject.GetComponent <InventoryItemGrid>();
                    newParent.SetId(oldParent.id, oldParent.num);

                    transform.localPosition = Vector3.zero;

                    oldParent.ClearInfo();
                }
            }
            else if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.Inventory_item.ToString())//拖放到一个有物品的格子里
            {
                InventoryItemGrid gird1 = originalParent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid gird2 = eventData.pointerCurrentRaycast.gameObject.transform.parent.GetComponent <InventoryItemGrid>();

                int id = gird1.id, num = gird1.num;

                gird1.SetId(gird2.id, gird2.num);
                gird2.SetId(id, num);
            }
            else if (eventData.pointerCurrentRaycast.gameObject.tag == Tags.ShortCut.ToString())
            {
                eventData.pointerCurrentRaycast.gameObject.GetComponent <ShortCutGird>().SetInventory(id);
            }
        }

        ResetPosition();

        GetComponent <CanvasGroup>().blocksRaycasts = true;
    }
Ejemplo n.º 13
0
    /// <summary>
    /// 拾取物品
    /// </summary>
    /// <param name="id"></param>
    public void GetId(int id)
    {
        //查找是否存在该物品
        //存在 num+1
        //不存在 查找空的方格存放进去
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in items)
        {
            if (temp.id == id)
            {
                grid = temp; break;
            }
        }

        if (grid != null)
        {
            //存在
            grid.AddNum();
        }
        else
        {
            //不存在,查找空的方格
            foreach (InventoryItemGrid temp in items)
            {
                if (temp.id == 0)
                {
                    grid = temp; break;
                }
            }

            if (grid != null)
            {
                //有足够的格子
                grid.SetId(id);
            }
            else
            {
                print("没有多的格子了");
            }
        }
    }
Ejemplo n.º 14
0
    // 拾取物品
    public void GetId(int id, int count = 1)
    {
        // 第一步查找是否存在该物品
        // 第二,存在num+1
        // 第三,不存在,查找空格,追加物品
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            // 已存在
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }
        // 存在情况
        if (grid != null)
        {
            grid.PlusNumber();
        }
        // 不存在的情况
        else
        {
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == 0)
                {
                    grid = temp;
                    break;
                }
            }
            if (grid != null)
            {
                // 不存在,查找空格,追加物品
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItem);
                itemGo.transform.localPosition         = Vector3.zero; // 初始位置,确保正中间
                itemGo.GetComponent <UISprite>().depth = 4;
                grid.SetId(id, count);
            }
        }
    }
Ejemplo n.º 15
0
    /// <summary>
    /// 拾取到id的物品,并添加到物品栏里面
    /// 处理拾取物品的功能
    /// </summary>
    /// <param name="id"></param>
    public void GetId(int id)
    {
        //第一步 在所有的物品中是否存在该物品
        //第二 若存在,则物品num+1
        //第三 若不存在,查找空的方格,然后把新创建的inventoryItem放到这个空的方格里面
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }
        //存在的情况
        if (grid != null)
        {
            grid.PlusNum();
        }
        //不存在的情况
        else
        {
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == 0)
                {
                    grid = temp;
                    break;
                }
            }
            //第三 若不存在,查找空的方格,然后把新创建的inventoryItem放到这个空的方格里面
            if (grid != null)
            {
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItem);
                itemGo.transform.localPosition         = Vector3.zero;
                itemGo.GetComponent <UISprite>().depth = 9;
                grid.SetId(id);
            }
        }
    }
Ejemplo n.º 16
0
    public bool MinusId(int id, int count = 1)
    {
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.id == id)
            {
                grid = temp; break;
            }
        }
        if (grid == null)
        {
            return(false);
        }
        else
        {
            bool isSuccess = grid.MinusNumber(count);
            return(isSuccess);
        }
    }
Ejemplo n.º 17
0
    //拾取到物品,并添加到物品栏里面
    public void GetId(int id, int num = 1)
    {
        //第一步:查找在所有物品中是否存在该物品
        //第二步:如果存在,让numLabel+1
        //第三步:如果不存在,查找空的格子,然后创建新的Iventory-item放入里面
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }

        if (grid != null)  //存在的情况
        {
            grid.PlusNumber(num);
        }
        else  //不存在的情况
        {
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == 0)
                {
                    grid = temp;
                    break;
                }
            }
            if (grid != null)
            {
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItem);
                itemGo.transform.localPosition         = Vector3.zero;
                itemGo.GetComponent <UISprite>().depth = 3;
                grid.SetId(id, num);
            }
        }
    }
Ejemplo n.º 18
0
    //拾取id物品的功能,并添加到物品栏里面
    public void GetId(int id, int count = 1)
    {
        //第一步查找所有的物品是否存在该物品
        // 第二,如果存在,num+1
        InventoryItemGrid grid = null;

        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.id == id)
            {
                grid = temp;
                break;
            }
        }
        if (grid != null) //存在的情况
        {
            grid.PlusNumber(count);
        }
        else
        {
            //不存在的话,找个新的格子
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == 0)
                {
                    grid = temp;
                    break;
                }
            }
            if (grid != null) //第三 查找新的方格,然后把新创建的 放到新的空格去
            {
                //添加空的物体
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItem);
                itemGo.transform.localPosition         = Vector3.zero;
                itemGo.GetComponent <UISprite>().depth = 4;
                grid.SetId(id, count);
            }
        }
    }
Ejemplo n.º 19
0
    public void GetId(int id, int number)
    {
        InventoryItemGrid grid = null;

        if (itemGridList.Count < 1 && number > 0)
        {
            GameObject itemGo = GameObject.Instantiate(InventoryItem);
            itemGo.transform.SetParent(this.transform);
            grid = itemGo.GetComponent <InventoryItemGrid>();
            grid.SetId(id, number);
            itemGridList.Add(grid);
        }
        else
        {
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.id == id)
                {
                    grid = temp;
                    break;
                }
            }
            if (grid != null && number > 0)
            {
                grid.PlusNumber(number);
            }
            else
            {
                if (number > 0)
                {
                    GameObject itemGo = GameObject.Instantiate(InventoryItem);
                    itemGo.transform.SetParent(this.transform);
                    grid = itemGo.GetComponent <InventoryItemGrid>();
                    grid.SetId(id, number);
                    itemGridList.Add(grid);
                }
            }
        }
    }
Ejemplo n.º 20
0
 protected override void OnDragDropRelease(GameObject surface)
 {
     base.OnDragDropRelease(surface);
     if (surface != null)
     {
         // 拖放到空格子
         if (surface.tag == Tags.inventory_item_grid)
         {
             // 拖放到自己的格子
             if (surface == this.transform.parent.gameObject)
             {
             }
             else
             {
                 InventoryItemGrid oldParent = transform.parent.GetComponent <InventoryItemGrid>();
                 this.transform.parent = surface.transform;
                 InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>();
                 newParent.SetId(oldParent.id, oldParent.num);
                 oldParent.ClearInfo();
             }
         }
         else if (surface.tag == Tags.inventory_item)
         {
             InventoryItemGrid grid1 = this.transform.parent.GetComponent <InventoryItemGrid>();
             InventoryItemGrid grid2 = surface.transform.parent.GetComponent <InventoryItemGrid>();
             int id  = grid1.id;
             int num = grid1.num;
             grid1.SetId(grid2.id, grid2.num);
             grid2.SetId(id, num);
         }
         else if (surface.tag == Tags.shortcut)
         {
             surface.GetComponent <ShortCutGrid>().SetInventory(id);
         }
     }
     ResetPosition();
 }
Ejemplo n.º 21
0
    /// <summary>
    /// 拾取到Id的物品,并添加到物品栏里
    /// </summary>
    /// <param name="id"></param>
    public void GetId(int id, int count = 1)
    {
        InventoryItemGrid grid = null;

        foreach (var item in itemGridList)
        {
            if (item.id == id)
            {
                grid = item;
                break;
            }
        }

        if (grid != null)
        {
            grid.PlusNumber(count);
        }
        else
        {
            foreach (var item in itemGridList)
            {
                if (item.id == 0)
                {
                    grid = item;
                    break;
                }
            }

            if (grid != null)
            {
                var tempItem = GameObject.Instantiate(inventoryItem);
                tempItem.transform.SetParent(grid.transform);
                tempItem.transform.localPosition = Vector3.zero;
                grid.SetId(id, count);
            }
        }
    }
Ejemplo n.º 22
0
    // 根据 id 拾取物品
    public void GetId(int id)
    {
        InventoryItemGrid grid = null;

        // 查找是否已有该物品
        foreach (InventoryItemGrid temp in itemGridList)
        {
            if (temp.GetId() == id)         // 已有
            {
                grid = temp;
                break;
            }
        }
        if (grid != null)
        {
            grid.PlusNum();                 // 该物品数目+1
        }
        else
        {
            // 查找是否有空格子
            foreach (InventoryItemGrid temp in itemGridList)
            {
                if (temp.GetId() == 0)      // 有空格子
                {
                    grid = temp; break;
                }
            }
            if (grid != null)               // 往空格子里放物品
            {
                GameObject itemGo = NGUITools.AddChild(grid.gameObject, inventoryItemPrefab);
                itemGo.transform.localPosition         = Vector3.zero;
                itemGo.GetComponent <UISprite>().depth = 4;
                grid.SetId(id);             // 改变各自装的物品
            }
        }
    }
Ejemplo n.º 23
0
    //拖拽结束时调用
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);
        if (surface != null)
        {
            //拖放到了空的格子里
            if (surface.tag == Tags.inventory_item_grid)
            {
                //拖放到了自己的格子里
                if (surface == this.transform.parent.gameObject)
                {
                }
                //拖放到了其它空的格子里
                else
                {
                    InventoryItemGrid oldParent = this.transform.parent.GetComponent <InventoryItemGrid>();

                    this.transform.parent = surface.transform;
                    InventoryItemGrid newParent = surface.GetComponent <InventoryItemGrid>();
                    newParent.SetId(oldParent.id, oldParent.num);

                    oldParent.ClearInfo();
                }
            }
            //拖放到了有物品的格子里
            else if (surface.tag == Tags.inventory_item)
            {
                InventoryItemGrid thisParent = this.transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid surgaceParent = surface.transform.parent.GetComponent <InventoryItemGrid>();
                int id = thisParent.id; int num = thisParent.num;
                thisParent.SetId(surgaceParent.id, surgaceParent.num);
                surgaceParent.SetId(id, num);
            }
        }
        ResetPosition();
    }
Ejemplo n.º 24
0
    //surface本质上传过来的是UICamera.hoveredObject,也就是图片下面的是那个ui物体
    protected override void OnDragDropRelease(GameObject surface)
    {
        base.OnDragDropRelease(surface);

        bool isCleanChildren = false;

        //拖放到空格子
        if (surface.tag == Tags.inventoryItemGrid)
        {
            //拖放到非自身的空格子
            if (surface != transform.parent.gameObject)
            {
                InventoryItem     hideItem = surface.GetComponentInChildren <InventoryItem>();
                InventoryItemGrid oldGrid  = transform.parent.GetComponent <InventoryItemGrid>();
                InventoryItemGrid newGrid  = surface.GetComponent <InventoryItemGrid>();

                //判断这个空格子是真的没有物体,还是有一个隐藏的InventoryItem
                if (hideItem == null)
                {
                    //必须把设置放在SetId之前,SetId会获取子组件
                    transform.parent = surface.transform;

                    newGrid.SetId(oldGrid.id, oldGrid.itemNum);

                    oldGrid.CleanInfo();
                }
                else
                {
                    hideItem.GetComponent <UISprite>().enabled = true;
                    newGrid.SetId(oldGrid.id, oldGrid.itemNum);

                    oldGrid.CleanInfoInChildren();
                    isCleanChildren = true;
                }
            }
        }
        //拖放到有物品的格子,两个格子信息交换
        else if (surface.tag == Tags.inventoryItem)
        {
            InventoryItemGrid originalGrid = transform.parent.GetComponent <InventoryItemGrid>();
            InventoryItemGrid targetGrid   = surface.transform.parent.GetComponent <InventoryItemGrid>();

            string id  = targetGrid.id;
            int    num = targetGrid.itemNum;

            targetGrid.SetId(originalGrid.id, originalGrid.itemNum);
            originalGrid.SetId(id, num);
        }
        //拖放到快捷栏
        else if (surface.tag == Tags.shortCut)
        {
            surface.GetComponent <ShortCutGrid>().SetInventoryItem(m_id);
        }

        ResetItemPosition();

        //因为如果清空格子的子物体代表会执行隐藏操作,这里把它显示有不合理
        if (isCleanChildren == false)
        {
            transform.parent.GetComponentInChildren <UILabel>().enabled = true;
        }

        sprite.depth = originalDepth;
    }
Ejemplo n.º 25
0
    /// <summary>
    /// 减去物品
    /// </summary>
    public bool MinusItem(string id, int count = 1)
    {
        InventoryItemGrid grid = CheckItemNum(id);

        return(grid == null ? false : grid.MinusNumber(count));
    }
Ejemplo n.º 26
0
 private void SelectAllContextMenuItem_Click(object sender, EventArgs e)
 {
     InventoryItemGrid.SelectAll();
 }
Ejemplo n.º 27
0
 public void EquipGood(InventoryItemGrid grid)
 {
     equipGrid.EquipItemGrid_OnEnter(grid.id);
     itemGridList.Remove(grid);
     Destroy(grid.gameObject);
 }
Ejemplo n.º 28
0
 void Start()
 {
     parent_grid = GetComponentInParent<InventoryItemGrid>();
 }