Exemple #1
0
        public void CreateUI(Inventory inventory, PageUI page)
        {
            this.inventory = inventory;

            if (inventoryPrefab == null)
            {
                inventoryPrefab = Resources.Load("Prefabs/Inventory") as GameObject;
            }
            SceneManager.sceneManager.StartCoroutine(CreateInventory(page));
        }
        public static bool AddComponentDisplay(Inventory inventory)
        {
            PageUI page = CreatePage(inventory.GetName(), inventory);

            if (page == null)
            {
                return(false);
            }
            InventoryUI inventoryUI = new InventoryUI();

            inventoryUI.CreateUI(inventory, page);
            return(true);
        }
        public static void CreateHUD(Player player)
        {
            // Create inventory page
            PageUI            page            = CreatePage("Inventory", player);
            PlayerInventoryUI playerInventory = new PlayerInventoryUI();

            playerInventory.CreateUI(player, page);

            // WorkBenchUI workBench = new WorkBenchUI();
            // workBench.CreateUI(new Inventory(8, 2, "input"), new Inventory(1, 1, "output"), CreatePage("Workbench"));

            // Create hotbar
            hotbar = new HotbarUI();
            hotbar.CreateUI(player);
        }
        public static PageUI CreatePage(string name, System.Object obj)
        {
            if (pages.Count >= 10)
            {
                return(null);
            }
            foreach (PageUI p in pages)
            {
                if (p.obj == obj)
                {
                    return(null);
                }
            }
            PageUI page = new PageUI(name, obj);

            pages.Add(page);
            return(page);
        }
Exemple #5
0
        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);
            }
        }
Exemple #6
0
        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);
        }
Exemple #7
0
        public void CreateUI(CraftingData craftingData, Inventory craftingInventory, Inventory resultInventory, PageUI page)
        {
            this.craftingData      = craftingData;
            this.craftingInventory = craftingInventory;
            this.resultInventory   = resultInventory;

            if (craftingPrefab == null)
            {
                craftingPrefab = Resources.Load("Prefabs/Crafting") as GameObject;
            }
            SceneManager.sceneManager.StartCoroutine(CreateCrafting(page));
        }