private void buildDecoration(uint inIndex) { FlowerProperties flowerProperties = GameObject.Find("World").GetComponent <FlowerProperties>(); /* * Decoration ID codes: * (all decorations should be negative and should never have an ID of 0) * (flower ids take up the entire positive range of longs (including 0)) * 0 ... 9: Japanese style path, bench, fence, archway, and then some extra IDs for padding in case more need added * 10...19: Urban style path, bench, fence, archway... * 20...29: Suburban style- path, bench, fence, archway... * 30...99: Padding for other styles that might be added in the future * 100+... misc IDs */ isFlower = false; //Destroy the flower or decoration before building a new one //Destroy the root destroys everything if (rootObject != null) { GameObject.Destroy(rootObject); rootObject = null; } rootObject = Instantiate(flowerProperties.getDecorationObject(inIndex), transform); //The root object is a prefab not meant for UI so it needs to be fixed up fixDecorationForUI(rootObject); }
public GameObject getDecorationObjectFromIndex(uint index) { if (flowerProperties == null) { flowerProperties = GameObject.Find("World").GetComponent <FlowerProperties>(); } return(flowerProperties.getDecorationObject(index)); }
/// <summary> /// Syncs the player inventory with the flowers in the player inventory home base panel /// </summary> private void PlayerInventorySync() { FlowerProperties fp = GameObject.Find("World").GetComponent <FlowerProperties>(); UIControllerScript uic = otherCanvas.GetComponent <UIControllerScript>(); //Now fill the other canvas and the UI inventory with the right items //Loop through the entire inventory for (int ii = 0; ii < fpc.inventorySize; ii++) { MenuSlot hInventoryItem = playerInventoryContainer.GetChild(ii).GetComponent <MenuSlot>(); Placeable slotPlaceable = uic.getInventoryDataAtSlot(ii); uint currentSlotID = 0; bool currentSlotIsFlower = false; if (slotPlaceable != null) { currentSlotID = slotPlaceable.id; currentSlotIsFlower = slotPlaceable.isFlower; } //If there's an item in the home base player inventory if (hInventoryItem.getItem() != null) { uic.inventoryClearSlot(ii); GameObject newObj; //Create a placeable based on the slot's id if (hInventoryItem.getItem().isFlower) { //Make a flower newObj = Instantiate(Resources.Load("Prefabs/FlowerPrefab", typeof(GameObject)) as GameObject); FlowerObj p = newObj.GetComponent <FlowerObj>(); p.id = hInventoryItem.getItem().id; int[] petal = new int[2] { fp.getPetalIndexFromIndex(p.id), fp.getPetalColorIndexFromIndex(p.id) }; int[] pistil = new int[2] { fp.getPistilIndexFromIndex(p.id), fp.getPistilColorIndexFromIndex(p.id) }; int[] leaf = new int[2] { fp.getLeafIndexFromIndex(p.id), fp.getLeafColorIndexFromIndex(p.id) }; int[] stem = new int[2] { fp.getStemIndexFromIndex(p.id), fp.getStemColorIndexFromIndex(p.id) }; int[] position = new int[2] { -1, -1 }; p.init(petal, stem, pistil, leaf, position, transform.root); p.alive = true; uic.setSlot(ii, p); uic.setSlotCount(ii, hInventoryItem.getItem().count); Destroy(newObj); } else { //Make a decoration newObj = Instantiate(fp.getDecorationObject(hInventoryItem.getItem().id)); Placeable p = newObj.GetComponent <Placeable>(); p.id = hInventoryItem.getItem().id; p.isFlower = hInventoryItem.getItem().isFlower; p.flowerGridPos = new int[2] { -1, -1 }; uic.setSlot(ii, p); uic.setSlotCount(ii, hInventoryItem.getItem().count); Destroy(newObj); } } else //If there's not an item in the home base player inventory slot { //Check to see if the player has an item in the inventory slot if (uic.getInventoryDataAtSlot(ii) != null) { //The player had an item in the slot but moved it to the home base //So clear the slot uic.inventoryClearSlot(ii); } } } }