public override void BuildDefaultMap() { // Clear existing map if (flatMap != null) { for (int i = 0; i < flatMap.Length; i++) { if (flatMap[i] != null) { GameObject.DestroyImmediate(flatMap[i].gameObject); } } } // Generate new default map flatMap = new TerrainNode[sizeX * sizeY]; for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { // Instantiate and place default prefab TerrainNode newNode = (TerrainNode)PrefabUtility.InstantiatePrefab(defaultNodePrefab, transform); newNode.transform.localPosition = new Vector3(x * nodeSpacingX, y * nodeSpacingY, 0); newNode.transform.localRotation = defaultNodePrefab.transform.rotation; newNode.name = $"{newNode.name} ({x}, {y})"; // Move along x axis first? flatMap[(y * sizeX) + x] = newNode; newNode.ApplyTerrainTypeSettings(typeSettings); } } // Connect paths together for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { TerrainNode theNode = GetNode(x, y); // Connect paths right, left, up, down theNode.paths.Add(GetNode(x + 1, y)); theNode.paths.Add(GetNode(x - 1, y)); theNode.paths.Add(GetNode(x, y + 1)); theNode.paths.Add(GetNode(x, y - 1)); } } // Tell Unity the object/scene has changed EditorUtility.SetDirty(this.gameObject); EditorSceneManager.MarkSceneDirty(EditorSceneManager.GetActiveScene()); }
public void ModifyTerrain(TerrainTypeSettings typeSettings) { RaycastHit[] hits = Physics.CapsuleCastAll(pointOne.position, pointTwo.position, castRadius, castDir, castDist); for (int i = 0; i < hits.Length; i++) { TerrainNode node = hits[i].collider.GetComponent <TerrainNode> (); if (node == null) { continue; } node.type = type; node.ApplyTerrainTypeSettings(typeSettings); } }