コード例 #1
0
        public virtual void Update()
        {
            // If the item is no longer visible but still hovering
            if (InventoryUIUtility.hoveringItem != null && InventoryUIUtility.hoveringItem.gameObject.activeInHierarchy == false)
            {
                InventoryUIUtility.ExitItem(InventoryUIUtility.hoveringItem, InventoryUIUtility.hoveringItem.index, InventoryUIUtility.hoveringItem.itemCollection, null);
            }

            if (InventoryUIUtility.hoveringItem != null && InventoryUIUtility.hoveringItem.item != null)
            {
                #region Handling borders

                if (InventorySettingsManager.instance.isUIWorldSpace == false)
                {
                    if (moveWhenHitBorderHorizontal)
                    {
                        // Change the box if its about to fall of the screen
                        if (Input.mousePosition.x + currentTransform.sizeDelta.x > Screen.width - borderMargins.x)
                        {
                            // Falls of the right
                            currentTransform.pivot = new Vector2(defaultPivot.y, currentTransform.pivot.x); // Swap
                        }
                        else
                        {
                            currentTransform.pivot = new Vector2(defaultPivot.x, currentTransform.pivot.y); // Swap
                        }
                    }
                    if (moveWhenHitBorderVertical)
                    {
                        if (Input.mousePosition.y - currentTransform.sizeDelta.y < 0.0f - borderMargins.y)
                        {
                            // Falls of the bottom
                            currentTransform.pivot = new Vector2(currentTransform.pivot.x, defaultPivot.x); // Swap
                        }
                        else
                        {
                            currentTransform.pivot = new Vector2(currentTransform.pivot.x, defaultPivot.y); // Swap
                        }
                    }
                }

                #endregion

                if (InventorySettingsManager.instance.isUIWorldSpace)
                {
                    var     r = InventorySettingsManager.instance.guiRoot.GetComponent <UnityEngine.UI.GraphicRaycaster>();
                    var     l = new List <RaycastResult>();
                    Vector3 p = Input.mousePosition;
                    if (Application.isMobilePlatform && Input.touchCount > 0)
                    {
                        p = Input.GetTouch(0).position;
                    }

                    r.Raycast(new PointerEventData(null)
                    {
                        position = p, pressPosition = p
                    }, l);
                    p = Camera.main.ScreenToWorldPoint(p);
                    if (l.Count > 0)
                    {
                        transform.position = new Vector3(p.x, p.y, l[0].gameObject.transform.position.z);
                    }
                }
                else
                {
                    transform.position = Input.mousePosition;
                }


                if (InventoryUIUtility.hoveringItem != cacheItem)
                {
                    cacheItem = InventoryUIUtility.hoveringItem;
                    Repaint(cacheItem, cacheItem.item.GetInfo());
                }

                //if (lastWindow != null)
                //{
                //    if (lastWindow.animator.enabled || lastWindow.isVisible == false)
                //        return;
                //}

                if (window.isVisible == false)
                {
                    window.Show();
                }
            }
            else
            {
                if (window.isVisible)
                {
                    window.Hide();
                }
            }
        }
 public virtual void OnPointerExit(PointerEventData eventData)
 {
     InventoryUIUtility.ExitItem(this, index, itemCollection, eventData);
 }