// Use this for initialization void Start() { Transform turningPointsObject = GameObject.FindGameObjectWithTag("routeTurningPoints").transform; int i = 0; routeTurningPoints.Add(GameObject.FindGameObjectWithTag("startPoint").transform); gridTurningPoints.Add(TerrainInfo.TransformToGrid(GameObject.FindGameObjectWithTag("startPoint").transform.position)); while (i < turningPointsObject.childCount) { routeTurningPoints.Add(turningPointsObject.GetChild(i).transform); gridTurningPoints.Add(TerrainInfo.TransformToGrid(turningPointsObject.GetChild(i).transform.position)); //Debug.Log ("Turning Points" + gridTurningPoints[i]); i++; } loadElevation(12, 6); loadMap(); buildMap(); }
public void loadMap() { for (int x = 0; x < 20; x++) { for (int z = 0; z < 20; z++) { gridInfo[x, z] = 0; placeItemInfo[x, z] = 0; } } Vector2 prev = gridTurningPoints[0]; for (int i = 1; i < gridTurningPoints.Count; i++) { loadRoute(prev, gridTurningPoints[i]); prev = gridTurningPoints[i]; } //Detect the palce of all turbines, pumps and transformers that already in the scene GameObject[] allTurbines = GameObject.FindGameObjectsWithTag("turbine"); GameObject[] allPumps = GameObject.FindGameObjectsWithTag("waterTower"); GameObject[] allTransformers = GameObject.FindGameObjectsWithTag("transformer"); GameObject[] allTransformerForTurbines = GameObject.FindGameObjectsWithTag("transformerForTurbine"); for (int i = 0; i < allTurbines.Length; i++) { Transform currentTransform = allTurbines[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TurbineInfo currentTurbine = allTurbines[i].transform.GetComponent <TurbineInfo>(); currentTurbine.x = (int)gridPlace.x; currentTurbine.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allPumps.Length; i++) { Transform currentTransform = allPumps[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); PumpInfo currentPump = allPumps[i].transform.GetComponent <PumpInfo>(); currentPump.x = (int)gridPlace.x; currentPump.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allTransformers.Length; i++) { Transform currentTransform = allTransformers[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TransformerInfo currentTransformer = allTransformers[i].transform.GetComponent <TransformerInfo>(); currentTransformer.x = (int)gridPlace.x; currentTransformer.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } for (int i = 0; i < allTransformerForTurbines.Length; i++) { Transform currentTransform = allTransformerForTurbines[i].transform; Vector2 gridPlace = TerrainInfo.TransformToGrid(currentTransform.position); TransformerForTurbineInfo currentTransformerForTurbine = allTransformerForTurbines[i].transform.GetComponent <TransformerForTurbineInfo>(); currentTransformerForTurbine.x = (int)gridPlace.x; currentTransformerForTurbine.z = (int)gridPlace.y; placeItemInfo[(int)gridPlace.x, (int)gridPlace.y] = 1; } }