Ejemplo n.º 1
0
        public void Init(Backpack backPack, UnityAction <BackpackItem> onHoverBackpackItem = null, UnityAction <BackpackItem> onHoverEndBackpackItem = null)
        {
            Backpack               = backPack;
            OnHoverBackpackItem    = onHoverBackpackItem;
            OnHoverEndBackpackItem = onHoverEndBackpackItem;
            BackpackDragArea.Init(backPack);
            Backpack.BackpackPanel = this;

            BackpackTitle.text = backPack.InventoryName;
            ((RectTransform)BackpackTitle.transform).sizeDelta = new Vector2(backPack.GridSize * Backpack.Columns, ((RectTransform)BackpackTitle.transform).sizeDelta.y);
            ((RectTransform)Container).sizeDelta    = new Vector2(backPack.GridSize * Backpack.Columns, backPack.GridSize * Backpack.Rows);
            ItemContainerGridLayout.constraintCount = backPack.Columns;

            backpackGridMatrix = new BackpackGrid[Backpack.Columns, Backpack.Rows];
            for (int row = 0; row < Backpack.Rows; row++)
            {
                for (int col = 0; col < Backpack.Columns; col++)
                {
                    BackpackGrid bg = Backpack.CreateBackpackGrid(GridContainer);
                    bg.Init(Backpack.InventoryGridMatrix[col, row], new GridPos(col, row));
                    backpackGridMatrix[col, row] = bg;
                }
            }

            Backpack.OnAddItemSucAction    = OnAddItemSuc;
            Backpack.OnRemoveItemSucAction = OnRemoveItemSuc;
            backPack.RefreshInventoryGrids();
        }
Ejemplo n.º 2
0
        public BackpackGrid CreateBackpackGrid(Transform transform)
        {
            if (InstantiateBackpackGridHandler != null)
            {
                MonoBehaviour mono = InstantiateBackpackGridHandler?.Invoke(transform);
                if (mono != null)
                {
                    try
                    {
                        BackpackGrid res = (BackpackGrid)mono;
                        return(res);
                    }
                    catch (Exception e)
                    {
                        LogError(e.ToString());
                    }
                }
            }

            return(null);
        }