/// <summary> /// 对事件OnLeftBeginDrag的响应 /// 在物品被拖动时执行 /// </summary> /// <param name="gridTransfrom"></param> public void GridUI_OnLeftBeginDrag(Transform gridTransfrom) { //判断起始格子 if (gridTransfrom.gameObject.GetComponent <GridUI>().Type.Equals(GridUI.GridType.Bag))//如果是背包格,从背包中读取物品 { if (InventoryManager.GetItem(gridTransfrom.gameObject.GetComponent <GridUI>().Index) == null) { return; } else { Item item = InventoryManager.GetItem(gridTransfrom.gameObject.GetComponent <GridUI>().Index); dragItemUI.UpdateItemImage(item.Icon); isDrag = true; gridTransfrom.gameObject.GetComponent <GridUI>().ItemUIGo.SetActive(false); //隐藏原有物品 dragItemUI.Show(); } } else if (gridTransfrom.gameObject.GetComponent <GridUI>().Type.Equals(GridUI.GridType.Shop)) //如果是商店格,从商店中读取物品 { if (ShopManager.instance.GetItem(gridTransfrom.gameObject.GetComponent <GridUI>().Index) == null) { return; } else { Item item = ShopManager.instance.GetItem(gridTransfrom.gameObject.GetComponent <GridUI>().Index); dragItemUI.UpdateItemImage(item.Icon); isDrag = true; //商店的东西不隐藏(临时设定) //gridTransfrom.gameObject.GetComponent<GridUI>().ItemUIGo.SetActive(false); dragItemUI.Show(); } } }
private void Update() { Vector3 position; RectTransformUtility.ScreenPointToWorldPointInRectangle(GameObject.Find("BagUI").transform as RectTransform, Input.mousePosition, null, out position); if (isDrag) { DragITemUI.Show(); DragITemUI.setLocalposition(position); } }
private void Update() { Vector2 position; RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("Canvas").transform as RectTransform, Input.mousePosition, Camera.main, out position); if (isDrag) { DragItemUI.Show(); DragItemUI.SetLocalPosition(position); } }
/// <summary> /// 拖拽物品开始时的处理 /// </summary> /// <param name="gridTransform">被拖拽物所在的格子</param> private void BagItemGrid_OnLeftBeginDrag(Transform gridTransform) { if (gridTransform.childCount == 1) { return; } else { dragItem.Show(); BagItemGrid bagItemGrid = gridTransform.gameObject.GetComponent <BagItemGrid>(); //获取gridT染上form身上的gridItemGrid dragItem.setImage(bagItemGrid.id); //Destroy(gridTransform.GetChild(1).gameObject); gridTransform.GetChild(1).gameObject.GetComponent <Image>().enabled = false; isDrag = true; } }
void Update() { Vector2 position; RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").transform as RectTransform, Input.mousePosition, null, out position); if (isDrag) { DragItemUI.Show(); DragItemUI.SetLocalPosition(position); } else if (isShow) { TooltipUI.Show(); TooltipUI.SetLocalPosition(position); } }
private void Update() { Vector2 position; RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("Canvas").transform as RectTransform, Input.mousePosition, null, out position); if (isDrag) { dragItemUI.Show(); dragItemUI.SetLocalPostion(position); } else if (isShow) { tooltipUI.Show(); tooltipUI.SetLocalPostion(position); } }
void Update() { Vector2 position; //屏幕坐标转化为Canvas相对坐标 RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find ("Canvas").transform as RectTransform, Input.mousePosition, null, out position); if (isShow) { tooltipUI.Show(); tooltipUI.SetTooltipPosition(position); } if (isDrag) { dragItem.Show(); dragItem.SetDragItemPosition(position); } }
private void OnBeginDragEvent(Transform transform) { //空格子不处理 if (transform.childCount == 0) { return; } if (packPackItemDic.ContainsKey(transform)) { BaseItem item = packPackItemDic[transform]; dragItemUI.UpdateItem(item); Destroy(transform.GetChild(0).gameObject); dragItemUI.Show(); isDrag = true; } }
void Update() { Vector2 position; //将鼠标指向的屏幕上的位置的坐标转化为物体坐标并赋值给position RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").transform as RectTransform, Input.mousePosition, null, out position); if (isDrag) { DragItemUI.Show(); //另外创建的DragItemUI显示 DragItemUI.SetLocalPosition(position); } else if (isShow) { TooltipUI.Show(); TooltipUI.SetLocalPosition(position); //设置TooltipUI显示时的坐标 } }
private void Update() { if (IsDrag) { Vector2 position; //使用转换工具,将鼠标位置坐标转化为UI控件的相对坐标 RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").transform as RectTransform, Input.mousePosition, null, out position); DragItemUI.Show(); DragItemUI.SetLocalPosition(position); } else if (IsShow) { Vector2 position; //使用转换工具,将鼠标位置坐标转化为UI控件的相对坐标 RectTransformUtility.ScreenPointToLocalPointInRectangle(GameObject.Find("KnapsackUI").transform as RectTransform, Input.mousePosition, null, out position); ItemInfoUI.Show(); ItemInfoUI.SetLocalPosition(position); //这里需要将ItemInfo的UI组件的中心设置在左上角 } }