Exemplo n.º 1
0
 /// <summary>
 /// 从鼠标上拿走一个物品
 /// </summary>
 public void RemoveItem()
 {
     PickedItem.ReduceAmount();
     if (pickedItem.Amount <= 0)
     {
         isPickedItem = false;
         pickedItem.Hide();
     }
 }
Exemplo n.º 2
0
 private void Start()
 {
     toolTip    = GameObject.FindObjectOfType <ToolTip>();
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();
 }
Exemplo n.º 3
0
 void Start()
 {
     toolTip    = GameObject.FindObjectOfType <ToolTip>();//根据类型获取
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();//开始为隐藏状态
 }
Exemplo n.º 4
0
 public void Start()
 {
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     toolTip    = canvas.transform.Find("ItemUI/ToolTip").GetComponent <ToolTip>();
     pickedItem = canvas.transform.Find("ItemUI/PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();
 }
Exemplo n.º 5
0
    void Update()
    {
        if (isPickedItem == true)
        {
            Vector2 pos;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out pos);
            pickedItem.SetLocalPosition(pos);
        }
        //控制提示面板的跟随 箱子面板 角色面板 背包面板
        if (isPickedItem == false)
        {
            Vector2 position;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
            toolTip.SetLocalPostion(position);

            //面板跟随
            //if (Input.GetMouseButton(0))
            //{
            //    Vector2 pos2;
            //    RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out pos2);
            //    ChestPanel.Instance.SetLocalPostion(pos2);
            //    //Vector2 pos3;
            //    //RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out pos3);
            //    //PlayerPanel.Instance.SetLocalPostion(pos3);
            //}
        }
        //丢东西的处理
        if (isPickedItem == true && Input.GetMouseButtonDown(0) && UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(-1) == false)
        {
            isPickedItem = false;
            PickedItem.Hide();
        }
    }
    void Update()
    {
        if (isPickedItem)
        {
            //如果我们捡起了物品,我们就要让物品跟随鼠标
            Vector2 position;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                    Input.mousePosition, null, out position);

            pickedItem.SetLocalPosition(position);
        }
        else if (isToolTipShow)
        {
            //控制提示面板跟随鼠标
            Vector2 position;
            RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                    Input.mousePosition, null, out position);

            toolTip.SetLocalPosition(position + toolTipPositionOffset);
        }
        //物品丢弃的处理
        //鼠标上是否有UI
        if (isPickedItem && Input.GetMouseButtonDown(0) && EventSystem.current.IsPointerOverGameObject(-1) == false)
        {
            isPickedItem = false;
            pickedItem.Hide();
        }
    }
Exemplo n.º 7
0
 void Start()
 {
     ParseItemJson();
     tip        = GameObject.FindObjectOfType <Tip>();
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();
 }
Exemplo n.º 8
0
 public override void OnInit()
 {
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
     EventCenter.AddListener(EventType.OverGame, ClearItem);
     EventCenter.AddListener(EventType.ReturnMenuPanel, ClearItem);
     pickedItem.Hide();
 }
 public void PlacedItem(int amount = 1)
 {
     pickedItemUI.ReduceAmount(amount);
     if (PickedItemUI.Amount <= 0)
     {
         isPickedItem = false;
         pickedItemUI.Hide();
     }
 }
Exemplo n.º 10
0
 public void RemoveItem(int number) //从拖拽框去掉一定数量放在格子中
 {
     pickItem.ReduceAmount(number); //减少拖拽框的数量
     if (pickItem.amount <= 0)
     {
         isPickItem = false;
         pickItem.Hide();
     }
 }
Exemplo n.º 11
0
 private void Start()
 {
     isToolTipShow = false;
     ParseItemJson();
     toolTip    = GameObject.FindObjectOfType <ToolTip>();
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();
 }
Exemplo n.º 12
0
    void Start()
    {
        //itemJson = JsonMapper.ToObject(File.ReadAllText(Application.dataPath + "/item.json"));

        toolTip    = GameObject.Find("ToolTip").GetComponent <ToolTip>();
        canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
        pickedItem = GameObject.Find("PickedItem").GetComponent <ItemUI>();
        pickedItem.Hide();//让pickeditem 默认不显示
    }
Exemplo n.º 13
0
 private void Start()
 {
     canvas     = GetComponent <Canvas>();
     player     = GameObject.FindWithTag("Player").GetComponent <Player>();
     toolTip    = transform.FindChild("Tooltip").GetComponent <ToolTip>();
     pickedItem = transform.FindChild("PickedItem").GetComponent <ItemUI>();
     pickedItem.Hide();
     SplitUI = transform.FindChild("Panel_BatchTransItems").GetComponent <SplitUI>();
     SplitUI.Hide();
     throwAwayUI = transform.FindChild("Panel_ThrowAwayItem").GetComponent <ThrowAwayUI>();
     throwAwayUI.Hide();
 }
Exemplo n.º 14
0
 void Update()
 {
     if (isPickedItem)
     {
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                 Input.mousePosition, null, out position);
         pickedItem.SetLocalPosition(position);
     }
     else if (isToolTipShow)
     {
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                 Input.mousePosition, null, out position);
         toolTip.SetLocalPosition(position + toolTipPositionOffset);
     }
     if (isPickedItem && Input.GetMouseButtonDown(0) &&
         UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(-1) == false)
     {
         isPickedItem = false;
         pickedItem.Hide();
     }
 }
Exemplo n.º 15
0
    private void StoreItem(Notification <BagItems> notific)
    {
        BagItems param = notific.param;

        if (null == param || "" == param.ItemName || 0 == param.count)
        {
            if (ItemUI != null)
            {
                ItemUI.Hide();
            }
            return;
        }
        StoreItem(param);
    }
Exemplo n.º 16
0
 void Update()
 {
     if (isToolTipShow == true && isPickedItem == false) //控制提示框跟随鼠标移动
     {
         Vector2 postionToolTip;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out postionToolTip);
         toolTip.SetLocalPosition(postionToolTip + toolTipOffset); //设置提示框的位置,二维坐标会自动转化为三维坐标但Z坐标为0
     }
     else if (isPickedItem == true)                                //控制盛放物品的容器UI跟随鼠标移动
     {
         Vector2 postionPickeItem;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out postionPickeItem);
         pickedItem.SetLocalPosition(postionPickeItem);//设置容器的位置,二维坐标会自动转化为三维坐标但Z坐标为0
     }
     //物品丢弃功能:
     if (isPickedItem == true && Input.GetMouseButtonDown(0) && UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(-1) == false) //UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(-1) == false 表示判断鼠标是否正在在UI上
     {
         isPickedItem = false;
         pickedItem.Hide();
     }
 }
Exemplo n.º 17
0
 private void Update()
 {
     if (isPickedItem)
     {
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
         pickedItem.SetLocalPosition(position);
     }
     if (isToolTipShow)
     {
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
         toolTip.SetLocalPostion(position + toolTipPositionOffset);
     }
     //丢弃物品
     if (isPickedItem && Input.GetMouseButtonDown(0) && UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject(-1) == false)//鼠标下面没有组件
     {
         isPickedItem = false;
         pickedItem.Hide();
     }
     isControl = Input.GetKey(KeyCode.LeftControl) ? true : false;
 }
Exemplo n.º 18
0
 private void Update()
 {
     if (isToolTipShow)
     {
         //控制提示面板跟随鼠标
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
         toolTip.SetLocalPosition(position + toolTipOffset);
     }
     //如果物品被拾取,则让物品跟随鼠标移动
     if (isPicked)
     {
         Vector2 position;
         RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
         pickedItem.SetLocalPosition(position);
     }
     if (isPicked && Input.GetMouseButtonDown(0) && IsPointerOverUI() == false)
     {
         throwAwayUI.Show();
         throwAwayUI.PlayAnimation();
         throwAwayUI.SetThrowAwayNumDes(pickedItem);
         pickedItem.Hide();
     }
 }
Exemplo n.º 19
0
    void Update()
    {
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            GetOverUI(GameObject.Find("Canvas"));
        }
#endif
        if (IsPickedItem)
        {
            if (Input.GetMouseButton(0))
            {
                showItemUI.Show();
                showInfo.Hide();
                showItemUI.transform.position = Input.mousePosition;
            }
            if (Input.GetMouseButtonUp(0))
            {
                List <GameObject> objects = GetOverUI(GameObject.Find("Canvas"));
                for (int i = 0; i < objects.Count; i++)
                {
                    if (objects[i].name.Contains("Grid"))
                    {
                        //1,是玩家的装备格子
                        if (objects[i].name.Contains("EquipmentGrid"))
                        {
                            EquipmentGrid equipmentGrid = objects[i].GetComponent <EquipmentGrid>();
                            if (showItemUI.currentItem.itemType == ItemType.Weapon && equipmentGrid.equipmentType == EquipmentType.Weapon)
                            {
                                if (equipmentGrid.CurrentItem == null)
                                {
                                    equipmentGrid.AddItem(showItemUI.currentItem);
                                    equipmentGrid.CurrentItem = showItemUI.currentItem;
                                }
                                else//替换掉 替换掉,原来的装备放回背包
                                {
                                    Knapsack.Instance.AddItemToGrid(equipmentGrid.CurrentItem);
                                    equipmentGrid.RemoveItem(equipmentGrid.CurrentItem);
                                    equipmentGrid.AddItem(showItemUI.currentItem);
                                    equipmentGrid.CurrentItem = showItemUI.currentItem;
                                }
                            }
                            else if (showItemUI.currentItem.itemType == ItemType.Equipment && equipmentGrid.equipmentType == (showItemUI.currentItem as Equipment).equipmentType)
                            {
                                if (equipmentGrid.CurrentItem == null)
                                {
                                    equipmentGrid.AddItem(showItemUI.currentItem);
                                    equipmentGrid.CurrentItem = showItemUI.currentItem;
                                }
                                else //替换掉,原来的装备放回背包
                                {
                                    Knapsack.Instance.AddItemToGrid(equipmentGrid.CurrentItem);
                                    equipmentGrid.RemoveItem(equipmentGrid.CurrentItem);
                                    equipmentGrid.AddItem(showItemUI.currentItem);
                                    equipmentGrid.CurrentItem = showItemUI.currentItem;
                                }
                            }
                            else //放回原处
                            {
                                bePickGrid.AddItem(showItemUI.currentItem);
                            }
                        }
                        else
                        {
                            //2,不是玩家装备格子
                            Grid grid = objects[i].GetComponent <Grid>();
                            if (grid.IsEmpty)//格子为空时
                            {
                                grid.AddItem(showItemUI.currentItem);
                            }
                            else if (showItemUI.currentItem.id == grid.ItemStoredId && grid.CurrentStorageNum < grid.StorageSpaceMax)//格子中有物品但未达到该类物品的存储上限
                            {
                                grid.AddItem(showItemUI.currentItem);
                            }
                            else//格子中有物品且达到该类物品的存储上限
                            {
                                //回到背包TODO
                                bePickGrid.AddItem(showItemUI.currentItem);
                            }
                        }

                        break;
                    }
                    else
                    {
                        //出售掉装备 跟新玩家的金币数量
                        //TODO
                    }
                }

                IsPickedItem = false;
            }
        }
        else
        {
            showItemUI.Hide();
            BePickGrid = null;
        }
        if (IsPickedItem == false && IsShowItmInfo)
        {
            showInfo.SetPosition(Input.mousePosition);
        }
        else
        {
            showInfo.Hide();
        }
    }
Exemplo n.º 20
0
    public override void OnUpdate()
    {
        //if (isPickedItem)
        //{
        //    //如果我们捡起了物品,我们就要让物品跟随鼠标
        //    Vector2 position;
        //    RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform, Input.mousePosition, null, out position);
        //    pickedItem.SetLocalPosition(position);
        //}

#if UNITY_EDITOR
        if (true)
        {
            if (isPickedItem)
            {
                //如果我们捡起了物品,我们就要让物品跟随鼠标
                Vector2 position;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                        Input.mousePosition, null, out position);
                pickedItem.SetLocalPosition(position);
                if (Input.GetMouseButtonUp(0))
                {
#else
        if (Input.touchCount > 0)
        {
            Touch myTouch = Input.touches[0];
            if (isPickedItem)
            {
                //if (myTouch.phase != TouchPhase.Ended && myTouch.phase != TouchPhase.Canceled)
                //{
                //如果我们捡起了物品,我们就要让物品跟随鼠标
                Vector2 position;
                RectTransformUtility.ScreenPointToLocalPointInRectangle(canvas.transform as RectTransform,
                                                                        Input.touches[0].position, null, out position);
                pickedItem.SetLocalPosition(position);
                if (myTouch.phase == TouchPhase.Ended)
                {
#endif
                    isPickedItem = false;
                    PointerEventData pointerEventData = new PointerEventData(EventSystem.current);
                    pointerEventData.position = Input.mousePosition;
                    GraphicRaycaster     gr      = canvas.GetComponent <GraphicRaycaster>();
                    List <RaycastResult> results = new List <RaycastResult>();
                    gr.Raycast(pointerEventData, results);
                    if (results.Count <= 0)
                    {
                        isPickedItem = false;
                        PickedItem.Hide();
                        return;
                    }
                    GameObject go = results[0].gameObject;
                    if (go.tag == "Slot")
                    {
                        Slot slot = go.GetComponent <Slot>();
                        if (slot is EquipmentSlot)
                        {
                            EquipmentSlot equipmentSlot = slot as EquipmentSlot;
                            if (equipmentSlot.IsRightItem(pickedItem.Item))
                            {
                                if (slot.transform.childCount > 0)
                                {
                                    int  amount = slot.transform.GetChild(0).GetComponent <ItemUI>().Amount;
                                    Item item   = slot.transform.GetChild(0).GetComponent <ItemUI>().Item;
                                    for (int i = 0; i < pickedItem.Amount; i++)
                                    {
                                        GameObject.DestroyImmediate(slot.transform.GetChild(0).gameObject);
                                        slot.StoreItem(pickedItem.Item);
                                    }

                                    for (int i = 0; i < amount; i++)
                                    {
                                        knapsackPanel.StoreItem(item);
                                    }
                                }
                                else
                                {
                                    slot.StoreItem(pickedItem.Item);
                                }
                            }
                            else
                            {
                                knapsackPanel.StoreItem(pickedItem.Item);
                            }

                            isPickedItem = false;
                            PickedItem.Hide();
                        }
                        else if (slot is ShopSlot)
                        {
                            knapsackPanel.GetComponent <KnapsackPanel>().SellItem(pickedItem);
                            isPickedItem = false;
                            pickedItem.Hide();
                        }
                        else
                        {
                            if (slot.transform.childCount > 0)
                            {
                                int  amount = slot.transform.GetChild(0).GetComponent <ItemUI>().Amount;
                                Item item   = slot.transform.GetChild(0).GetComponent <ItemUI>().Item;
                                for (int i = 0; i < pickedItem.Amount; i++)
                                {
                                    GameObject.DestroyImmediate(slot.transform.GetChild(0).gameObject);
                                    slot.StoreItem(pickedItem.Item);
                                }

                                for (int i = 0; i < amount; i++)
                                {
                                    knapsackPanel.StoreItem(item);
                                }

                                isPickedItem = false;
                                PickedItem.Hide();
                            }
                            else
                            {
                                for (int i = 0; i < pickedItem.Amount; i++)
                                {
                                    slot.StoreItem(pickedItem.Item);
                                }

                                isPickedItem = false;
                                PickedItem.Hide();
                            }
                        }
                    }
                    else
                    {
                        if (go.tag == "ShopPanel")
                        {
                            knapsackPanel.SellItem(pickedItem);
                        }
                        else
                        {
                            for (int i = 0; i < pickedItem.Amount; i++)
                            {
                                knapsackPanel.StoreItem(pickedItem.Item);
                            }
                        }
                        isPickedItem = false;
                        PickedItem.Hide();
                    }
                }
            }
        }
    }
Exemplo n.º 21
0
 public void PutDownItem()
 {
     m_isPickedItem = false;
     m_pickedItem.Hide();
 }