public IEnumerator CreateInventory(PageUI page) { yield return(new WaitForEndOfFrame()); GameObject inventoryUI = GameObject.Instantiate(inventoryPrefab); float width = page.viewport.GetComponent <RectTransform>().rect.width; Debug.Log("Inventory: " + width); inventoryUI.GetComponent <GridLayoutGroup>().cellSize = new Vector2(0.25f * width, 0.25f * width); page.SetContent(inventoryUI); RectTransform transform = inventoryUI.GetComponent <RectTransform>(); transform.offsetMax = transform.offsetMin = Vector2.zero; for (int i = 0; i < inventory.GetInventorySize(); ++i) { OpenSlotUI slot = new OpenSlotUI(i, inventory); slot.SetParent(inventoryUI.transform); } }
public IEnumerator CreateCrafting(PageUI page) { yield return(new WaitForEndOfFrame()); gameObject = GameObject.Instantiate(craftingPrefab); float width = page.viewport.GetComponent <RectTransform>().rect.width; input = gameObject.transform.GetChild(1).gameObject; output = gameObject.transform.GetChild(5).gameObject; gameObject.transform.GetChild(7).GetComponent <RectTransform>().sizeDelta = new Vector2(width, width); recipeGrid = gameObject.transform.GetChild(7).GetChild(0).GetChild(0).GetChild(0).gameObject; input.GetComponent <GridLayoutGroup>().cellSize = new Vector2(0.25f * width, 0.25f * width); output.GetComponent <GridLayoutGroup>().cellSize = new Vector2(0.25f * width, 0.25f * width); recipeGrid.GetComponent <GridLayoutGroup>().cellSize = new Vector2(0.5f * width, 0.25f * width); for (int i = 0; i < craftingInventory.GetInventorySize(); ++i) { OpenSlotUI slot = new OpenSlotUI(i, craftingInventory); slot.SetParent(input.transform); } for (int i = 0; i < resultInventory.GetInventorySize(); ++i) { TakeSlotUI slot = new TakeSlotUI(i, resultInventory); slot.SetParent(output.transform); } page.SetContent(gameObject); RectTransform transform = gameObject.GetComponent <RectTransform>(); transform.offsetMax = transform.offsetMin = Vector2.zero; craftingInventory.AddListener(OnInputChange); resultInventory.AddListener(OnOutputChange); }