Creating multiple ItemShapeGrid on the same Inventory with UI Designer causes issues

Please when writing a question in the forum make the title very clear. "A bug was found if you create 3 fields at the same time" is way too generic.

"Creating multiple ItemShapeGrid on the same Inventory with UI Designer causes issues" (EDIT I changed the title for you) would be a much better title. Having good titles makes it much easier for you and other users to find answers to questions that have already been answered.

As for this particular issue. You are correct there are some issues. I have now added a new feature scene to showcase a wroking scene with multiple ItemShapeGrids. Please find the Feature scene 7_2 package below. This scene not only shows a working example, but also explains how it was setup.

When creating this scene I found some issues in the code. All of these will be available in a future update. But in the case you cannot wait here they are:

ItemShapeGridDesigner.cs line 126 replace the BuildInternal function:
Code:
protected override ItemShapeGrid BuildInternal()
        {
            var inventory = m_InventoryField.value as Inventory;
            //Create Shape Grid Data and Controller
            var itemShapeGridController = inventory.GetComponent<ItemShapeGridController>();
            if (itemShapeGridController == null) {
                itemShapeGridController = inventory.gameObject.AddComponent<ItemShapeGridController>();
                itemShapeGridController.m_ItemShapeGridData = new List<ItemShapeGridData>();
            }
            // Find a grid ID that is not already taken.
            var existingGridDatas = itemShapeGridController.m_ItemShapeGridData;
            var gridID = 0;
            if (existingGridDatas != null) {
                for (int i = 0; i < existingGridDatas.Count; i++) {
                    if (gridID != existingGridDatas[i].ID) { continue; }
                    gridID++;
                    i = 0;
                }
            }
            var itemShapeData = inventory.gameObject.AddComponent<ItemShapeGridData>();
            itemShapeData.m_ID = gridID;
            itemShapeData.m_GridSize = m_GridSize.value;
            itemShapeData.m_ItemCollections = new string[] {m_ItemCollectionField.value};
            itemShapeGridController.m_ItemShapeGridData.Add(itemShapeData);
            //Create UI Grid
            var rectParent = m_ParentTransform.value as RectTransform;
            var panelOption = (InventoryGridDisplayPanelOption)m_PanelOption.value;
            var displayPanel = UIDesignerManager.InstantiateSchemaPrefab<DisplayPanel>(UIDesignerSchema.GetPanelPrefab(panelOption), rectParent);
            displayPanel.SetName(m_PanelName.value);
            displayPanel.gameObject.name = m_PanelName.value;
            if (panelOption == InventoryGridDisplayPanelOption.MainMenu) {
                UIDesignerManager.GetTab<MainMenuDesigner>().AddInnerPanel(m_PanelName.value, displayPanel);
            }
            var itemShapeGrid = UIDesignerManager.InstantiateSchemaPrefab<ItemShapeGrid>(
                UIDesignerSchema.ItemShapeGrid, displayPanel.MainContent);
            itemShapeGrid.m_ItemShapeGridDataID = gridID;
            var drawer = itemShapeGrid.gameObject.GetComponent<ItemViewDrawer>();
            drawer.CategoryItemViewSet = UIDesignerSchema.ItemShapeCategoryItemViewSet;
            itemShapeGrid.ItemViewSlotPrefab = UIDesignerSchema.ItemShapeViewSlot;
            itemShapeGrid.SetGridSize(m_GridSize.value, false);
            SetItemShapeSize(itemShapeGrid, m_ItemShapeSize.value);
            itemShapeGrid.SetGridSize(m_GridSize.value, true);
            itemShapeGrid.SetName(m_ItemViewSlotContainerName.value);
            itemShapeGrid.gameObject.name = m_ItemViewSlotContainerName.value;
            var itemContainerPanelBinding = displayPanel.gameObject.AddComponent<ItemViewSlotsContainerPanelBinding>();
            itemContainerPanelBinding.ItemViewSlotsContainer = itemShapeGrid;
            itemContainerPanelBinding.Inventory = inventory;
            return itemShapeGrid;
        }


In ItemShapeGrid line 28:
Code:
[SerializeField] internal protected int m_ItemShapeGridDataID;

ItemShapeGrid line 232-234:
Code:
var gridDataCollection = m_ItemShapeGridData.GetItemCollectionToAddItemTo(itemInfo);

if (Inventory.CanAddItem(itemInfo, gridDataCollection) == null) { return false; }

ItemShapeGridController line 25
Code:
 [Tooltip("Prints a warning if an item can be part of multiple grids.")]
 [SerializeField] protected bool m_WarnIfMultipleMatch;

ItemShapeGridController line 196
Code:
if (index != -1) {
   if (m_WarnIfMultipleMatch) {
        Debug.LogWarning(
            $"The inventory has multiple grids which could contain the same item '{itemInfo}', this can cause many types of issues.");
   }
   continue;
}

I hope that helps
 

Attachments

  • Feature Scene 7_2.unitypackage
    34.3 KB · Views: 0
Top