public override GameObject cloneObj(GameObject model, Placeable data, RaycastHit hit) { int[] flowerGridLoc = WorldManager.instance.worldPointToFlowerGrid(hit.point); //find what grid the point is in GameObject newFlower = GameObject.Instantiate(model, posClamp(hit), Quaternion.identity, hit.transform); //make a copy newFlower.GetComponent <setCurvaturePosition>().baseYPosition = hit.point.y; newFlower.name = flowerGridLoc[0] + " " + flowerGridLoc[1];//placement stuff //Makes sure the flower is active and all of its components are enabled newFlower.SetActive(true); newFlower.GetComponent <FlowerObj>().enabled = true; newFlower.GetComponent <setCurvaturePosition>().enabled = true; newFlower.transform.LookAt(transform.position); newFlower.transform.eulerAngles = new Vector3(0, newFlower.transform.eulerAngles.y, 0); newFlower.transform.Rotate(new Vector3(0, -90, 0)); newFlower.SetActive(true); FlowerObj currentFlowerObj = newFlower.GetComponent <FlowerObj>(); WorldManager.instance.placableGrid[flowerGridLoc[0], flowerGridLoc[1]] = currentFlowerObj;//move the flower data over ((FlowerObj)WorldManager.instance.placableGrid[flowerGridLoc[0], flowerGridLoc[1]]).flowerGridPos = new int[] { flowerGridLoc[0], flowerGridLoc[1] }; WorldManager.instance.RecalcAfterAdd(flowerGridLoc[0], flowerGridLoc[1]); //This is to limit where in the cell the player can place the flower //clearPos(x, y); return(newFlower); }
/*int IComparable.CompareTo(object y) * { * FlowerObj yObj = (FlowerObj)y; * if (timeToSpawn > yObj.timeToSpawn) * { * return 1; * } * if (timeToSpawn < yObj.timeToSpawn) * { * return -1; * } * return 0; * }*/ public int CompareTo(object y)//objects are equal if the x and y are the same { FlowerObj yObj = (FlowerObj)y; if (flowerGridPos[0] == yObj.flowerGridPos[0] && flowerGridPos[1] == yObj.flowerGridPos[1]) { return(0); } return(1); }
//Constructor with a flower public void init(FlowerObj f) { this.petalIndex = f.petalIndex; this.stemIndex = f.stemIndex; this.pistilIndex = f.pistilIndex; this.leafIndex = f.leafIndex; this.flowerGridPos = f.flowerGridPos; this.parent = f.parent; //uiScale = 1f; id = getFlowerIndex(); isFlower = true; this.timeToSpawn = f.timeToSpawn; }
public void rebuildFlower()//William { GameObject flower = this.gameObject; FlowerObj flowerObj = this; GameObject world = GameObject.Find("World"); FlowerProperties fp = world.GetComponent <FlowerProperties>(); GameObject stemObject = transform.GetChild(0).gameObject; //Destroy the flower before building a new one //Destroy the stem that destroys everything if (stemObject != null) { GameObject.DestroyImmediate(stemObject); } try { //Instantiate the given stem object stemObject = Instantiate(fp.flowerStem[flowerObj.stemIndex[0]], flower.transform); } catch { //Instantiate the given stem object stemObject = Instantiate(fp.flowerStem[flowerObj.stemIndex[0]], flower.transform); } stemObject.layer = LayerMask.NameToLayer("Placeable"); Material stemMat = fp.stemMaterial; stemObject.GetComponent <MeshRenderer>().material = stemMat; stemObject.GetComponent <MeshRenderer>().material.color = fp.flowerColors[flowerObj.stemIndex[1]]; GameObject petalObject = null; //Add leaves and petal to the stem bool petalHasBeenFound = false; foreach (Transform child in stemObject.transform) { if (!petalHasBeenFound && child.gameObject.name.ToString().Equals("spetal")) { //It's the petal so it has been found petalHasBeenFound = true; //Now spawn it petalObject = Instantiate(fp.flowerPetal[flowerObj.petalIndex[0]], child); petalObject.layer = LayerMask.NameToLayer("Placeable"); Material petalMat = fp.petalMaterial; petalObject.GetComponent <MeshRenderer>().material = petalMat; petalObject.GetComponent <MeshRenderer>().material.color = fp.flowerColors[flowerObj.petalIndex[1]]; } else { //It's a leaf so spawn it GameObject leaf = Instantiate(fp.flowerLeaf[flowerObj.leafIndex[0]], child); leaf.layer = LayerMask.NameToLayer("Placeable"); Material leafMat = fp.leafMaterial; leaf.GetComponent <MeshRenderer>().material = leafMat; leaf.GetComponent <MeshRenderer>().material.color = fp.flowerColors[flowerObj.leafIndex[1]]; } } //Add pistil to the petal GameObject pistilObject = Instantiate(fp.flowerPistil[flowerObj.pistilIndex[0]], petalObject.transform.GetChild(0)); pistilObject.layer = LayerMask.NameToLayer("Placeable"); Material pistilMat = fp.pistilMaterial; pistilObject.GetComponent <MeshRenderer>().material = pistilMat; pistilObject.GetComponent <MeshRenderer>().material.color = fp.flowerColors[flowerObj.pistilIndex[1]]; flower.name = flowerObj.flowerGridPos[0] + " " + flowerObj.flowerGridPos[1]; world.GetComponent <WorldManager>().combineMeshes(flower.transform); world.GetComponent <WorldManager>().resizeBoxCollider(flower.gameObject); flower.layer = LayerMask.NameToLayer("Placeable"); }
/// <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); } } } }