public void SetUp() { int childs = InventoryParent.childCount; for (int i = childs - 1; i >= 0; i--) { Destroy(InventoryParent.GetChild(i).gameObject); } childs = Parent.childCount; for (int i = childs - 1; i > 0; i--) { Destroy(Parent.GetChild(i).gameObject); } var worldObject = GetComponent <BuildingWorldObject>(); crafter = worldObject.myCrafter; inventory = worldObject.myInventory; inventory.drawInventoryEvent += SetUp; craftingProcesses.Clear(); timeoutCounters.Clear(); if (crafter != null) { for (int i = 0; i < crafter.myCraftingProcesses.Length; i++) { CraftingProcess curProcess = crafter.myCraftingProcesses[i] as CraftingProcess; if (curProcess != null) { GameObject pDisp = Instantiate(ProcessDisplayPrefab, Parent); craftingProcesses.Add(pDisp); timeoutCounters.Add(infoDisplayTimeoutTime - 1f); for (int input = 0; input < curProcess.inputItemIds.Length; input++) { GameObject pIn = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().InputsParent); pIn.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.inputItemIds[input]).GetSprite(); pIn.GetComponent <MiniGUI_InOutDisplay>().totalText.text = curProcess.inputItemAmounts[input].ToString(); } for (int output = 0; output < curProcess.outputItemIds.Length; output++) { GameObject pOut = Instantiate(ProcessinoutPrefab, pDisp.GetComponent <MiniGUI_CraftingProcess>().OutputsParent); pOut.GetComponent <MiniGUI_InOutDisplay>().itemImage.sprite = DataHolder.s.GetItem(curProcess.outputItemIds[output]).GetSprite(); pOut.GetComponent <MiniGUI_InOutDisplay>().totalText.text = curProcess.outputItemAmounts[output].ToString(); } //craftingProcesses[craftingProcesses.Count-1].SetActive(false); } } } foreach (InventoryItemSlot it in inventory.inventory) { Instantiate(InventoryListingPrefab, InventoryParent).GetComponent <MiniGUI_InventoryListing>().SetUp(it, inventory, true); } }
public void UpdateSelf(Building _building) { RemoveSelfFromTile(); // Only update if the building has changed if (myBuilding != null && !myBuilding.center.isValid() && myBuilding.myPositions != null && myBuilding.myPositions.Count > 0 && myBuilding.myPositions[0] == _building.myPositions[0]) { return; } myBuilding = _building; myData = _building.buildingData; isConstruction = false; /*if (isSpaceLanding) * GetComponentInChildren<SpriteGraphicsController>().DoSpaceLanding(null);*/ myRend = GetComponentInChildren <SpriteGraphicsController>(); GenericUpdateSelf(myBuilding.myPositions, _building.center); myRend.SetBuildState(SpriteGraphicsController.BuildState.built); myCrafter = myBuilding.craftController; myCrafter.continueAnimationsEvent -= ContinueAnimations; myCrafter.continueAnimationsEvent += ContinueAnimations; myCrafter.stopAnimationsEvent -= StopAnimations; myCrafter.stopAnimationsEvent += StopAnimations; myInventory = myBuilding.invController; isInventorySetup = true; buildingInventoryUpdatedCallback?.Invoke(); StopAnimations(); if (_building.buildingData.uniqueName == "bRocket" && !isSpaceLandingTriggered) { isSpaceLandingTriggered = true; GetComponentInChildren <SpriteGraphicsController>().DoSpaceLanding(null); } }
/// <summary> /// Sets up the building inventory with slots made for the possible inputs&outputs craftable by the building. /// Must be called after the crafting controller is set up /// </summary> /// <param name="mydat"></param> public void SetUp(Position location, BuildingCraftingController myCrafter, BuildingData myData, List <InventoryItemSlot> starterInventory) { myLocation = location; switch (myData.myType) { case BuildingData.ItemType.Base: myType = InventoryType.Base; break; case BuildingData.ItemType.Miner: //myType = InventoryType.Miner; myType = InventoryType.NormalBuilding; break; case BuildingData.ItemType.Storage: myType = InventoryType.Storage; break; default: myType = InventoryType.NormalBuilding; break; } inventory.Clear(); switch (myType) { case InventoryType.NormalBuilding: for (int i = 0; i < myCrafter.myCraftingProcesses.Length; i++) { var inputs = myCrafter.myCraftingProcesses[i].GetInputItems(); for (int m = 0; m < inputs.Length; m++) { AddSlot(inputs[m].Item1, inputs[m].Item2 * 2, InventoryItemSlot.SlotType.input, false); } var outputs = myCrafter.myCraftingProcesses[i].GetOutputItems(); for (int m = 0; m < outputs.Length; m++) { AddSlot(outputs[m].Item1, outputs[m].Item2 * 2, InventoryItemSlot.SlotType.output, false); } } break; case InventoryType.Miner: var ores = DataHolder.s.GetAllOres(); for (int i = 0; i < ores.Length; i++) { AddSlot(DataHolder.s.GetItem(ores[i].oreUniqueName), -1, InventoryItemSlot.SlotType.input, false); AddSlot(DataHolder.s.GetItem(ores[i].oreUniqueName), -1, InventoryItemSlot.SlotType.output, false); } break; case InventoryType.Storage: // only fill in as much as we need. some slots may be leftover from construction. for (int i = inventory.Count; i < myData.buildingGrade; i++) { AddSlot(Item.GetEmpty(), 99, InventoryItemSlot.SlotType.storage, false); } FactoryDrones.RegisterStorageBuilding(this); break; } if (starterInventory != null) { foreach (var slot in starterInventory) { RestoreSlot(slot, false, myData.myType == BuildingData.ItemType.Rocket); } } dwellerSlots.Clear(); for (int i = 0; i < myData.housingSlots; i++) { dwellerSlots.Add(AddSlot(Item.GetEmpty(), 1, InventoryItemSlot.SlotType.house, false)); } maxDwellers = myData.housingSlots; workerSlots.Clear(); for (int i = 0; i < myData.workerRequirement; i++) { workerSlots.Add(AddSlot(Item.GetEmpty(), 1, InventoryItemSlot.SlotType.worker, false)); } maxWorkers = myData.workerRequirement; drawInventoryEvent?.Invoke(); InventoryContentsChanged(); }