// Calculate the building's stats. public void calcStats() { List <GameObject> conPieces = grid.GetComponent <ConGrid>().getBuilding(); materialCounts = new Dictionary <string, int>(); pieceCount = 0; // The number of construction pieces on the grid. highHeight = 0f; // The highest piece height of the building. float height; // The height of an object. int amt; // The amount of blocks in an object (determined by size classification). foreach (Transform label in compLabel.transform) { Destroy(label.gameObject); } // Calculate the building stats foreach (GameObject obj in conPieces) { ConstructionPiece piece = obj.GetComponent <ConstructionPiece>(); switch (piece.blockSize) { case 2: amt = 1; break; case 3: amt = 4; break; case 4: amt = 16; break; case 5: amt = 32; break; case 6: amt = 64; break; case 7: amt = 128; break; default: amt = 0; break; } pieceCount += amt; countMaterial(materialCounts, piece.bldgMat, amt); height = obj.transform.position.y + obj.renderer.bounds.size.y / 2f; if (height > highHeight) { highHeight = height; } } blockLabel.GetComponent <UILabel>().text = pieceCount + " blocks"; heightLabel.GetComponent <UILabel>().text = highHeight + " units"; int numLabels = 0; foreach (KeyValuePair <string, int> pair in materialCounts) { numLabels++; GameObject matLabel = (GameObject)Instantiate(statLabel, compLabel.transform.position, compLabel.transform.rotation); matLabel.transform.parent = compLabel.transform; matLabel.transform.localScale = compLabel.transform.localScale; matLabel.transform.localPosition = new Vector3(matLabel.transform.localPosition.x, matLabel.transform.localPosition.y - 100f * numLabels, matLabel.transform.localPosition.z); // The 100f is static to save time. matLabel.GetComponent <UILabel>().text = pair.Key + ": " + pair.Value; } NGUITools.SetActive(menu, true); Time.timeScale = 0; Screen.lockCursor = false; if (checkReqs()) { NGUITools.SetActive(menu.transform.Find("Panel - Stats").Find("End Construction").gameObject, true); calcRatings(); } else { NGUITools.SetActive(menu.transform.Find("Panel - Stats").Find("End Construction").gameObject, false); } }
void Update() { if (Input.GetMouseButtonDown(0) && hitObject != null) { GameObject projectile = hitObject; dropObject(); projectile.rigidbody.AddExplosionForce(500f, cam.transform.position, 10f); } RaycastHit hit; if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, rigDist, ~((1 << 12) + (1 << 9) + (1 << 13)))) { reticule.transform.position = hit.point; if (hitObject != null) { // || (reticule.transform.position - hitObject.transform.position).magnitude < 0.5f if (hit.distance < 0.5f) //if it's too close or too far from cursor, drop it { dropObject(); } } } else { reticule.transform.position = cam.transform.TransformDirection(Vector3.forward) * rigDist + cam.transform.position; //reticule is always rigDist in front of the camera } if (hitObject != null) { hitObject.rigidbody.angularVelocity = new Vector3(0, 0, 0); } if (Input.GetKeyDown(KeyCode.E) && Time.timeScale > 0 && !conMode) { if (hitObject != null) //if it isn't null, it must be what the player is carrying. toggle off { dropObject(); } else if (Physics.Raycast(cam.transform.position, cam.transform.TransformDirection(Vector3.forward), out hit, rigDist, (1 << 14) + (1 << 11))) { //Debug.Log("yus"); if (hit.collider.tag == "ComboMachine") { hit.collider.GetComponent <ComboMachine>().displayRecipes(); } else if (hit.collider.tag == "ClearGrid") { GameObject invisCube = GameObject.FindGameObjectWithTag("InvisCube"); GameObject conGrid = GameObject.FindGameObjectWithTag("ConGrid"); invisCube.transform.position = new Vector3(conGrid.transform.position.x, invisCube.transform.position.y, conGrid.transform.position.z + conGrid.renderer.bounds.size.z / 2f); StartCoroutine(moveClearer(invisCube, -conGrid.renderer.bounds.size.z, 3f, 300)); } else if (hit.collider.tag == "EndConstruction") { GetComponent <Ratings>().calcStats(); } else if (hit.rigidbody != null) { pickupObject(hit.collider.gameObject); //otherwise get what the character is trying to get } } } if (grid != null || conMode) { if (Input.GetKeyDown(KeyCode.Tab)) { if (conMode) { conMode = false; if (placingObject != null) { placingObject.GetComponent <ConstructionPiece>().endPlacement(); placingObject = null; } else { reactivateCam(); } } else { conMode = true; if (hitObject != null) { placingObject = hitObject; dropObject(); ConstructionPiece conPiece = placingObject.GetComponent <ConstructionPiece>(); conPiece.StartPlacement(conPiece.curGrid); } else { rigidbody.velocity = Vector3.zero; disableMovement(); ConCam(grid); } } } } if (conMode) { if (Input.GetKeyDown(KeyCode.LeftArrow)) { activeCam.enabled = false; activeCam = getRotCam(activeCam, "left"); activeCam.enabled = true; placingObject.GetComponent <ConstructionPiece>().setAdjs(activeCam.transform.eulerAngles.y); } else if (Input.GetKeyDown(KeyCode.RightArrow)) { activeCam.enabled = false; activeCam = getRotCam(activeCam, "right"); activeCam.enabled = true; placingObject.GetComponent <ConstructionPiece>().setAdjs(activeCam.transform.eulerAngles.y); } } else { if (Input.GetMouseButtonUp(0) && Time.timeScale > 0) { Screen.lockCursor = lockCursor; } } }