コード例 #1
0
 void Start()
 {
     toolTip    = GameObject.FindObjectOfType <_ToolTip>();//根据类型获取
     canvas     = GameObject.Find("Canvas").GetComponent <Canvas>();
     pickedItem = GameObject.Find("PickedItem").GetComponent <_ItemUI>();
     pickedItem.Hide();//开始为隐藏状态
 }
コード例 #2
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();
     }
 }