public void Init(UIInventory uiInventory, UnityAction <UIInventoryItem> onHoverUIInventoryItem = null, UnityAction <UIInventoryItem> onHoverEndUIInventoryItem = null) { UIInventory = uiInventory; OnHoverUIInventoryItem = onHoverUIInventoryItem; OnHoverEndUIInventoryItem = onHoverEndUIInventoryItem; UIInventoryDragAreaIndicator.Init(uiInventory); UIInventory.UIInventoryPanel = this; UIInventoryTitle.text = uiInventory.InventoryName; UIInventoryDragMoveHandle.EnableScreenClamp = uiInventory.EnableScreenClamp; ((RectTransform)UIInventoryTitleContainer).sizeDelta = new Vector2(uiInventory.GridSize * UIInventory.Columns, ((RectTransform)UIInventoryTitleContainer).sizeDelta.y); ((RectTransform)Container).sizeDelta = new Vector2(uiInventory.GridSize * UIInventory.Columns, uiInventory.GridSize * UIInventory.Rows); ItemContainerGridLayout.constraintCount = uiInventory.Columns; ItemContainerGridLayout.cellSize = new Vector2(uiInventory.GridSize, uiInventory.GridSize); uiInventoryGridMatrix = new UIInventoryGrid[UIInventory.Columns, UIInventory.Rows]; for (int row = 0; row < UIInventory.Rows; row++) { for (int col = 0; col < UIInventory.Columns; col++) { UIInventoryGrid bg = UIInventory.CreateUIInventoryGrid(UIInventoryGridContainer); bg.Init(UIInventory.InventoryGridMatrix[col, row], new GridPos(col, row)); uiInventoryGridMatrix[col, row] = bg; } } UIInventory.OnAddItemSucAction = OnAddItemSuc; UIInventory.OnRemoveItemSucAction = OnRemoveItemSuc; uiInventory.RefreshInventoryGrids(); }
public UIInventoryGrid CreateUIInventoryGrid(Transform transform) { if (InstantiateUIInventoryGridHandler != null) { MonoBehaviour mono = InstantiateUIInventoryGridHandler?.Invoke(transform); if (mono != null) { try { UIInventoryGrid res = (UIInventoryGrid)mono; return(res); } catch (Exception e) { LogError(e.ToString()); } } } return(null); }