/// <summary> /// Checks all tiles, and ajusts walls /// </summary> static public void RockProximty() { for (int x = 0; x < Map.GridXSize_; x++) { for (int y = 0; y < Map.GridYSize_; y++) { Tile tile = StaticMapInfo.Map.GetTileAtPos(x, y); if (tile.tag == "RockTile") { RockScript tileRockSript = tile.GetComponent <RockScript>(); tileRockSript.RockNorth = StaticMapInfo.isWall(x, y + 1); tileRockSript.RockNorthEast = StaticMapInfo.isWall(x + 1, y + 1); tileRockSript.RockEast = StaticMapInfo.isWall(x + 1, y); tileRockSript.RockSouthEast = StaticMapInfo.isWall(x + 1, y - 1); tileRockSript.RockSouth = StaticMapInfo.isWall(x, y - 1); tileRockSript.RockSouthWest = StaticMapInfo.isWall(x - 1, y - 1); tileRockSript.RockWest = StaticMapInfo.isWall(x - 1, y); tileRockSript.RockNorthWest = StaticMapInfo.isWall(x - 1, y + 1); } } } }
void RockProximty() { float navMeshSize = 5; float tilesize = StaticMapInfo.RockModleHolder.DefultTile.GetComponent <MeshRenderer>().bounds.size.x / 2; WorldController worldController = WorldController.GetWorldController; List <GameObject> ambientObjects = StaticMapInfo.RockModleHolder.AmbientObjects; List <Vector3> oldVector3 = new List <Vector3>(); List <float> oldSize = new List <float>(); worldController._landslideRocks.Clear(); worldController._defultTile.Clear(); for (int x = 0; x < _TileMap.GridXSize_; x++) { for (int y = 0; y < _TileMap.GridYSize_; y++) { Tile tile = StaticMapInfo.Map.GetTileAtPos(x, y); if (tile.tag == "RockTile") { RockScript tileRockSript = tile.GetComponent <RockScript>(); if (tileRockSript.RockType != RockScript.Type.SolidRock) { worldController._landslideRocks.Add(tileRockSript); } tileRockSript.RockNorth = StaticMapInfo.isWall(x, y + 1); tileRockSript.RockNorthEast = StaticMapInfo.isWall(x + 1, y + 1); tileRockSript.RockEast = StaticMapInfo.isWall(x + 1, y); tileRockSript.RockSouthEast = StaticMapInfo.isWall(x + 1, y - 1); tileRockSript.RockSouth = StaticMapInfo.isWall(x, y - 1); tileRockSript.RockSouthWest = StaticMapInfo.isWall(x - 1, y - 1); tileRockSript.RockWest = StaticMapInfo.isWall(x - 1, y); tileRockSript.RockNorthWest = StaticMapInfo.isWall(x - 1, y + 1); } else if (tile.tag == "Floor") { worldController._defultTile.Add(tile); int ambinetObjectsAmount = 0; if (!(StaticMapInfo.isWall(x, y + 1) || StaticMapInfo.isWall(x + 1, y + 1) || StaticMapInfo.isWall(x + 1, y) || StaticMapInfo.isWall(x + 1, y - 1) || StaticMapInfo.isWall(x, y - 1) || StaticMapInfo.isWall(x - 1, y - 1) || StaticMapInfo.isWall(x - 1, y) || StaticMapInfo.isWall(x - 1, y + 1))) { ambinetObjectsAmount = 3; } if (!StaticMapInfo.IsLevelInBuilt && WorldController.IsPlaying()) { GameObject ranAmbentObject = ambientObjects[UnityEngine.Random.Range(0, ambientObjects.Count)]; if (ranAmbentObject != null) { if (ranAmbentObject.tag == "LightAmbent") { float scale = UnityEngine.Random.Range(0.4f, 1.1f); ranAmbentObject.transform.localScale = new Vector3(scale, scale, scale); } MeshRenderer[] objectMeshRenders = ranAmbentObject.GetComponentsInChildren <MeshRenderer>(); float ranAmbentObjectSize = 0; for (int i = 0; i < objectMeshRenders.Length; i++) { Vector3 objectSize = objectMeshRenders[i].bounds.size; if (objectSize.x > ranAmbentObjectSize || objectSize.z > ranAmbentObjectSize) { ranAmbentObjectSize = Mathf.Max(objectSize.x, objectSize.z); } } if (ranAmbentObjectSize != 0) { ranAmbentObjectSize /= 2; for (int i = 0; i < ambinetObjectsAmount; i++) { bool foundPos = false; int reposisionTimes = 0; Vector3 vector3; do { float tileOutlier = tilesize - ranAmbentObjectSize; vector3 = new Vector3(UnityEngine.Random.Range(-tileOutlier, tileOutlier), 0, UnityEngine.Random.Range(-tileOutlier, tileOutlier)); vector3.x += tile.transform.position.x; vector3.z += tile.transform.position.z; if (oldVector3.Count == 0) { foundPos = true; } else { bool continueLoop = true; for (int n = 0; n < oldVector3.Count && continueLoop; n++) { if (Vector3.Distance(oldVector3[n], vector3) > oldSize[n] + navMeshSize + ranAmbentObjectSize) { foundPos = true; } else { foundPos = false; continueLoop = false; } } reposisionTimes++; } }while (reposisionTimes <= 10 && !foundPos); if (foundPos) { GameObject ambientObject = Instantiate(ranAmbentObject, vector3, new Quaternion(0, 0, 0, 0)); oldVector3.Add(vector3); oldSize.Add(ranAmbentObjectSize); ambientObject.transform.parent = tile.transform; ambientObject.transform.Rotate(0, UnityEngine.Random.Range(0, 360), 0); } } } } } } } } }