Exemple #1
0
        private void OnAddItemSuc(InventoryItem ii)
        {
            UIInventoryItem uiInventoryItem = UIInventory.CreateUIInventoryItem(ItemContainer);

            uiInventoryItem.Initialize(UIInventory, ii, delegate { OnHoverUIInventoryItem?.Invoke(uiInventoryItem); }, delegate { OnHoverEndUIInventoryItem?.Invoke(uiInventoryItem); });
            uiInventoryItems.Add(ii.GUID, uiInventoryItem);
        }
Exemple #2
0
        private void OnRemoveItemSuc(InventoryItem ii)
        {
            UIInventoryItem bi = uiInventoryItems[ii.GUID];

            Destroy(bi.gameObject);
            uiInventoryItems.Remove(ii.GUID);
        }
        public UIInventoryItem CreateUIInventoryItem(Transform transform)
        {
            if (InstantiateUIInventoryItemHandler != null)
            {
                MonoBehaviour mono = InstantiateUIInventoryItemHandler?.Invoke(transform);
                if (mono != null)
                {
                    try
                    {
                        UIInventoryItem res = (UIInventoryItem)mono;
                        return(res);
                    }
                    catch (Exception e)
                    {
                        LogError(e.ToString());
                    }
                }
            }

            return(null);
        }
        public void Draggable_OnMousePressed(DragAreaIndicator dragAreaIndicator, Vector3 diffFromStart, Vector3 deltaFromLastFrame)
        {
            void ResumePausedDrag()
            {
                InventoryItem.GridPos_Matrix = dragStartGridPos_Matrix;
                UIInventory.RemoveItem(InventoryItem, true);
                Destroy(gameObject);
                DragManager.Instance.ResumePausedDrag();
            }

            if (dragAreaIndicator == UIInventory.DragAreaIndicator)
            {
                if (UIInventory.RotateItemKeyDownHandler != null && UIInventory.RotateItemKeyDownHandler.Invoke())
                {
                    Rotate();
                }

                if (diffFromStart.magnitude > Draggable_DragMinDistance)
                {
                    Vector2  diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                    Vector2  currentLocalPos = dragStartLocalPos + diffLocal;
                    GridPosR diff_world      = GridPos.GetGridPosByPointXY(diffLocal, UIInventory.GridSize);
                    diff_world.orientation = InventoryItem.GridPos_Matrix.orientation;
                    GridPosR diff_matrix = UIInventory.CoordinateTransformationHandler_FromPosToMatrixIndex(diff_world);
                    GridPosR gp_matrix   = dragStartGridPos_Matrix + diff_matrix;
                    gp_matrix.orientation        = InventoryItem.GridPos_Matrix.orientation;
                    InventoryItem.GridPos_Matrix = gp_matrix;
                    SetVirtualGridPos(InventoryItem.GridPos_World);
                    RectTransform.anchoredPosition = currentLocalPos;
                }
            }
            else
            {
                Vector2 diffLocal       = RectTransform.parent.InverseTransformVector(diffFromStart);
                Vector2 currentLocalPos = dragStartLocalPos + diffLocal;
                RectTransform.anchoredPosition = currentLocalPos;
                UIInventory.UIInventoryPanel.UIInventoryVirtualOccupationQuadRoot.Clear();
                if (dragAreaIndicator != null) // drag to other DragAreas
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                    else
                    {
                        // only when mouse move to available grid then generate previewItem
                        if (dragAreaIndicator is UIInventoryDragAreaIndicator uiDAI)
                        {
                            uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.GetMousePosOnThisArea(out Vector3 pos_world, out Vector3 pos_local, out Vector3 pos_matrix, out GridPos gp_matrix);
                            GridPosR gpr = gp_matrix;
                            gpr.orientation = InventoryItem.GridPos_Matrix.orientation;
                            InventoryItem previewItem = new InventoryItem(InventoryItem.Clone().ItemContentInfo, uiDAI.UIInventory, gpr);
                            uiDAI.UIInventory.AddPreviewItem(previewItem);
                            UIInventoryItem uiInventoryItem = uiDAI.UIInventory.UIInventoryPanel.GetUIInventoryItem(previewItem.GUID);
                            DragManager.Instance.PauseDrag();
                            DragManager.Instance.CurrentDrag = uiInventoryItem.Draggable;
                            uiInventoryItem.Draggable.SetOnDrag(true, uiDAI.UIInventory.UIInventoryPanel.UIInventoryDragAreaIndicator.BoxCollider, UIInventory.DragProcessor);
                        }
                    }
                }
                else // drag to non-DragArea
                {
                    if (DragManager.Instance.PausedDrag != null)
                    {
                        ResumePausedDrag();
                    }
                }
            }
        }