void Awake() { x = (int)transform.position.x + 20; y = (int)transform.position.y; z = (int)transform.position.z + 20; cityManager = GridCityManager.Instance; }
// Start is called before the first frame update void Start() { GetComponent <Renderer>().material.color = Random.ColorHSV(); navCityManager = GridCityManager.Instance; navAgent = GetComponent <NavMeshAgent>(); Destroy(this.gameObject, 10f); navAgent.destination = navCityManager.startLocation.position; }
// Start is called before the first frame update void Start() { GameController.Instance.RegisterBaddie(); navCityManager = GridCityManager.Instance; navAgent = GetComponent <NavMeshAgent>(); audioSource = GetComponent <AudioSource>(); playerTransform = GameController.Instance.playerBody; StartCoroutine(BaddieLogic()); }
// Use this for internal initialization void Awake() { if (_instance == null) { _instance = this; } else { Destroy(gameObject); Debug.LogError("Multiple NavigationCityManager instances in Scene. Destroying clone!"); } }
// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 7.0f); int y = Mathf.RoundToInt(transform.position.y); int z = Mathf.RoundToInt(transform.position.z + 7.0f); cityManager = GridCityManager.Instance; treePrefab = cityManager.treePrefab; GameObject child; if (recursionLevel == 0) //initial foundation block { if (!cityManager.CheckSlot(x, y, z)) { cityManager.SetSlot(x, y, z, true); int meshNum = myProfile.groundBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.groundBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; } else { GameObject.Destroy(gameObject); } } myMeshFilter.mesh = myMesh; myRenderer.material = myMaterial; if (recursionLevel < maxLevel) { if (recursionLevel == maxLevel - 1) //the next segment placed will be a roof { if (!cityManager.CheckSlot(x, y + 1, z)) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.roofBlocks.Length; int matNum = myProfile.roofMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.roofMaterials[Random.Range(0, matNum)], myProfile.roofBlocks[Random.Range(0, meshNum)]); } } else //the next segment placed will be a main body segment { int random = Random.Range(0, 10); if ((y < 5) || (random < 6)) //the low altitude vertical tower section { if (!cityManager.CheckSlot(x, y + 1, z)) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } } else //here we start branching off our tree tower { //MODIFY THE CODE BELOW random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y, z + 1))) { cityManager.SetSlot(x, y, z + 1, true); child = Instantiate(treePrefab, transform.position + Vector3.forward * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum - 1)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x + 1, y, z))) { cityManager.SetSlot(x + 1, y, z, true); child = Instantiate(treePrefab, transform.position + Vector3.right * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum - 1)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y, z - 1))) { cityManager.SetSlot(x, y, z - 1, true); child = Instantiate(treePrefab, transform.position - Vector3.forward * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum - 1)]); } ; random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x - 1, y, z))) { cityManager.SetSlot(x - 1, y, z, true); child = Instantiate(treePrefab, transform.position - Vector3.right * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum - 1)]); } ; //END MODIFY CODE random = Random.Range(0, 10); if ((random < 5) && (!cityManager.CheckSlot(x, y + 1, z))) { cityManager.SetSlot(x, y + 1, z, true); child = Instantiate(treePrefab, transform.position + Vector3.up * 1.01f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; Debug.Log(child.GetComponents <TreeTowerBlock>().Length); child.GetComponent <TreeTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); } ; } } } }
// Use this for external initialization void Start() { cityManager = GridCityManager.Instance; Initialize(startPoint.position, endPoint.position); }
// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 20.01f); int y = Mathf.RoundToInt(transform.position.y); int z = Mathf.RoundToInt(transform.position.z + 20.01f); cityManager = GridCityManager.Instance; Transform child; if (recursionLevel == 0) { if (!cityManager.CheckSlot(x, y, z)) { int meshNum = myProfile.groundBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.groundBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); } else if (cityManager.RoadQuery(x, y, z) == 1) //Flat road present { Debug.Log("Tower base on road: " + x + ", " + y + ", " + z); int meshNum = myProfile.tunnelBlocks.Length; int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.tunnelBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); } else if (cityManager.RoadQuery(x, y, z) == 2) //Ramp present { Debug.Log("Tower base on road: " + x + ", " + y + ", " + z); int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.tunnelBlocks[1]; //Place columns, an arch will go above myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); } else if (cityManager.RoadQuery(x, y, z) == 3) //Clearance present { Debug.Log("Tower base on road: " + x + ", " + y + ", " + z); int matNum = myProfile.groundMaterials.Length; myMesh = myProfile.tunnelBlocks[0]; //Place an arch myMaterial = myProfile.groundMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y, z, true); } else { Debug.Log("Tower base blocked: " + x + ", " + y + ", " + z); Destroy(gameObject); } } myMeshFilter.mesh = myMesh; myRenderer.material = myMaterial; if (recursionLevel < maxLevel) { if (recursionLevel == maxLevel - 1) { if (!cityManager.CheckSlot(x, y + 1, z)) { child = Instantiate(basePrefab, transform.position + Vector3.up * 1f, Quaternion.identity, this.transform); int meshNum = myProfile.roofBlocks.Length; int matNum = myProfile.roofMaterials.Length; child.GetComponent <GridTowerBlock>().Initialize(recursionLevel + 1, myProfile.roofMaterials[Random.Range(0, matNum)], myProfile.roofBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); } else { Debug.Log("Tower roof blocked"); } } else { if (!cityManager.CheckSlot(x, y + 1, z)) { child = Instantiate(basePrefab, transform.position + Vector3.up * 1f, Quaternion.identity, this.transform); int meshNum = myProfile.mainBlocks.Length; int matNum = myProfile.mainMaterials.Length; child.GetComponent <GridTowerBlock>().Initialize(recursionLevel + 1, myProfile.mainMaterials[Random.Range(0, matNum)], myProfile.mainBlocks[Random.Range(0, meshNum)]); cityManager.SetSlot(x, y + 1, z, true); } else if (cityManager.RoadQuery(x, y + 1, z) == 1) //Flat road cuts through tower { Debug.Log("Road through tower: " + x + ", " + (y + 1) + ", " + z); int meshNum = myProfile.tunnelBlocks.Length; int matNum = myProfile.mainMaterials.Length; myMesh = myProfile.tunnelBlocks[Random.Range(0, meshNum)]; myMaterial = myProfile.mainMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y + 1, z, true); } else if (cityManager.RoadQuery(x, y + 1, z) == 2) { Debug.Log("Road through tower: " + x + ", " + (y + 1) + ", " + z); int matNum = myProfile.mainMaterials.Length; myMesh = myProfile.tunnelBlocks[1]; //Place columns, an arch will go above myMaterial = myProfile.mainMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y + 1, z, true); } else if (cityManager.RoadQuery(x, y + 1, z) == 3) //Provide clearance for the ramp below { Debug.Log("Road through tower: " + x + ", " + (y + 1) + ", " + z); int matNum = myProfile.mainMaterials.Length; myMesh = myProfile.tunnelBlocks[0]; //Place an arch myMaterial = myProfile.mainMaterials[Random.Range(0, matNum)]; cityManager.SetSlot(x, y + 1, z, true); } else { Debug.Log("Tower main blocked: " + x + ", " + (y + 1) + ", " + z); } } } }
// Use this for internal initialization void Awake() { inc_x = inc_y = inc_z = 0; cityManager = GridCityManager.Instance; gameController = GameController.Instance; }
// Use this for external initialization void Start() { int x = Mathf.RoundToInt(transform.position.x + 20.0f); int y = Mathf.RoundToInt(transform.position.y); if (mySlope == -1) { y = Mathf.RoundToInt(transform.position.y - 1f); } int z = Mathf.RoundToInt(transform.position.z + 20.0f); cityManager = GridCityManager.Instance; tilePrefab = cityManager.tilePrefab; slopeUpPrefab = cityManager.slopeUpPrefab; slopeDownPrefab = cityManager.slopeDownPrefab; Transform child; if (recursionCount == 0) //initial tile "crossroads" { for (int nextRotation = 0; nextRotation < 360; nextRotation += 90) { SetIncrements(nextRotation, 0); Vector3 incVector = Vector3.right * inc_x + Vector3.up * inc_y + Vector3.forward * inc_z; Quaternion nextQuat = Quaternion.Euler(0f, nextRotation, 0f); if (!cityManager.CheckSlot(x + inc_x, y + inc_y, z + inc_z)) { cityManager.SetSlot(x + inc_x, y + inc_y, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y + inc_y, z + inc_z, 1); //Crossroad tiles are flat Debug.Log("Crossroads, Road Type: " + cityManager.RoadQuery(x + inc_x, y + inc_y, z + inc_z)); child = Instantiate(tilePrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, 0, nextRotation); } else { GameObject.Destroy(gameObject); } } } else if (recursionCount < maxLevel) { if (mySlope == 0) { Instantiate(gameController.pointPrefab, transform.position, Quaternion.identity, gameController.dummyPivot); } int corrector = (maxLevel - recursionCount) / 15; //biasing randomization in the beginning to avoid extinction int random = Random.Range(0, 100); if (random < (80 + corrector)) //move forward (most likely): { int nextRotation = myRotation; random = Random.Range(0, 100); if ((random > 80) && (mySlope == 0)) //going up { SetIncrements(nextRotation, mySlope); Vector3 incVector = Vector3.right * inc_x + Vector3.up * inc_y + Vector3.forward * inc_z; Quaternion nextQuat = Quaternion.Euler(0f, nextRotation, 0f); if ((!cityManager.CheckSlot(x + inc_x, y, z + inc_z)) && (!cityManager.CheckSlot(x + inc_x, y + 1, z + inc_z))) { cityManager.SetSlot(x + inc_x, y, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y, z + inc_z, 2); //Ramp at this location Debug.Log("Ramp Up, Road Type: " + cityManager.RoadQuery(x + inc_x, y, z + inc_z)); cityManager.SetSlot(x + inc_x, y + 1, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y + 1, z + inc_z, 3); //Clearance above a ramp Debug.Log("Ramp Up Clearance, Road Type: " + cityManager.RoadQuery(x + inc_x, y + 1, z + inc_z)); child = Instantiate(slopeUpPrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, 1, nextRotation); } } else if ((random < 20) && (mySlope == 0)) //going down { SetIncrements(nextRotation, mySlope); Vector3 incVector = Vector3.right * inc_x + Vector3.up * inc_y + Vector3.forward * inc_z; Quaternion nextQuat = Quaternion.Euler(0f, nextRotation, 0f); if ((!cityManager.CheckSlot(x + inc_x, y, z + inc_z)) && (!cityManager.CheckSlot(x + inc_x, y - 1, z + inc_z))) { cityManager.SetSlot(x + inc_x, y, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y, z + inc_z, 3); //Clearance at this location Debug.Log("Ramp Down Clearance, Road Type: " + cityManager.RoadQuery(x + inc_x, y, z + inc_z)); cityManager.SetSlot(x + inc_x, y - 1, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y - 1, z + inc_z, 2); //Ramp at this location Debug.Log("Ramp Down, Road Type: " + cityManager.RoadQuery(x + inc_x, y - 1, z + inc_z)); child = Instantiate(slopeDownPrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, -1, nextRotation); } } else //flat path { SetIncrements(nextRotation, mySlope); Vector3 incVector = Vector3.right * inc_x + Vector3.up * inc_y + Vector3.forward * inc_z; Quaternion nextQuat = Quaternion.Euler(0f, nextRotation, 0f); if (mySlope == -1) { if (!cityManager.CheckSlot(x + inc_x, y + inc_y + 1, z + inc_z)) { cityManager.SetSlot(x + inc_x, y + inc_y + 1, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y + inc_y + 1, z + inc_z, 1); //Flat at this location Debug.Log("Flat at base of Ramp Down, Road Type: " + cityManager.RoadQuery(x + inc_x, y + inc_y + 1, z + inc_z)); child = Instantiate(tilePrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, 0, nextRotation); } } else { if (!cityManager.CheckSlot(x + inc_x, y + inc_y, z + inc_z)) { cityManager.SetSlot(x + inc_x, y + inc_y, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y + inc_y, z + inc_z, 1); //Flat at this location Debug.Log("Flat/Ramp Up, Road Type: " + cityManager.RoadQuery(x + inc_x, y + inc_y, z + inc_z)); child = Instantiate(tilePrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, 0, nextRotation); } } } } //end move forward //if tile is not sloped, we can make a left or right split every once in a while. let's keep it as simple as possible: random = Random.Range(0, 100); if (((random + corrector) > 70) && (mySlope == 0)) { int nextRotation = myRotation; random = Random.Range(0, 100); if (random > 50) //left turn { nextRotation = (int)Mathf.Repeat(nextRotation - 90, 360); } else //right turn { nextRotation = (int)Mathf.Repeat(nextRotation + 90, 360); } SetIncrements(nextRotation, 0); Vector3 incVector = Vector3.right * inc_x + Vector3.up * inc_y + Vector3.forward * inc_z; Quaternion nextQuat = Quaternion.Euler(0f, nextRotation, 0f); if (!cityManager.CheckSlot(x + inc_x, y + inc_y, z + inc_z)) { cityManager.SetSlot(x + inc_x, y + inc_y, z + inc_z, true); cityManager.RoadMapping(x + inc_x, y + inc_y, z + inc_z, 1); //Flat at this location Debug.Log("Intersection, Road Type: " + cityManager.RoadQuery(x + inc_x, y + inc_y, z + inc_z)); child = Instantiate(tilePrefab, transform.position + incVector, nextQuat); child.parent = this.transform; child.GetComponent <RouteTile>().Initialize(recursionCount + 1, 0, nextRotation); } } } }