private IEnumerable DoCheckTerrains(string prefabName, GameObject scenePrefab) { var _Config = scenePrefab.GetComponent <SceneConfig>(); if (null == _Config) { yield break; } List <TerrainsManager.CTerrainEntry> _CurrentSceneTerrain = new List <TerrainsManager.CTerrainEntry>(); SceneConfig.LightmapsConfig cacheTerrainConfig = _Config._LightmapConfig; int curTerrainCount = cacheTerrainConfig._TerrainLightmapInfos.Length; _CurrentSceneTerrain.Clear(); for (int i = 0; i < curTerrainCount; i++) { Terrain terrain = cacheTerrainConfig._TerrainLightmapInfos[i]._Terrain; if (terrain == null) { continue; } if (terrain.terrainData != null) { TerrainsManager.CTerrainEntry entry = new TerrainsManager.CTerrainEntry(); entry.TerrainComp = terrain; entry.Position = terrain.transform.position; entry.SizeH = (terrain.terrainData.size.x + terrain.terrainData.size.z) * 0.5f; _CurrentSceneTerrain.Add(entry); } } //检查terrainData if (_CurrentSceneTerrain.Count > 0) //有分块 { int count = 0; int total = _CurrentSceneTerrain.Count; foreach (var entry in _CurrentSceneTerrain) { string name = entry.TerrainComp.name; TerrainData terrainData = entry.TerrainComp.terrainData; ++count; string shortName = System.IO.Path.GetFileNameWithoutExtension(prefabName); GameDataCheckMan.Instance.SetDesc(string.Format("{0} 检查Terrain: {1}", shortName, name)); GameDataCheckMan.Instance.SetPartProgress((float)count / total); yield return(null); //会导致basemap过大 if (terrainData.baseMapResolution > TerrainBaseMapSizeLimit) { //AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 BaseTextureResolution 为 {2}, 大于 {3},建议减小到{4}以内!\n", prefabName, name, terrainData.baseMapResolution, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit); } for (int i = 0; i < terrainData.splatPrototypes.Length; ++i) { var splat = terrainData.splatPrototypes[i]; var tex = splat.texture; if (tex != null) { //if (tex.width > 512 || tex.height > 512) // _ErrorString += string.Format("{0} terrain 的 splatTexture 大小 大于 512,建议减小到512以内: {1}\n", prefabName, tex.name); bool bValid = true; string errorMsg = ""; for (int level = 0; level < tex.mipmapCount; ++level) { if (!CUnityUtil.CanGetPixel32(tex, level, out errorMsg)) { bValid = false; break; } } if (!bValid) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 splatTexture {2} 无法读取像素,请确保Texture开启read/write权限: {3}, Message:{4}\n", prefabName, name, i, tex.name, errorMsg); } //else // _ErrorString += string.Format("{0} terrain 的 splatTexture {1} 正常读取像素: {2}\n", prefabName, i, tex.name); } else { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 splatTexture {2} 为空!\n", prefabName, name, i); } } if (terrainData.alphamapLayers > 4) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 alphamapLayers 大于 4,必须减小到4以内!\n", prefabName, name); } if (terrainData.alphamapResolution > TerrainBaseMapSizeLimit) { //AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 ControlTextureResolution 为{2}, 大于 {3},建议减小到 {4}以内!\n", prefabName, name, terrainData.alphamapResolution, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit); } for (int i = 0; i < terrainData.alphamapTextures.Length; ++i) { var tex = terrainData.alphamapTextures[i]; if (tex != null) { //if (tex.width > TerrainBaseMapSizeLimit || tex.height > TerrainBaseMapSizeLimit) // _ErrorString += string.Format("{0} 的 terrain {1} 的 alphamapTexture 长宽 大于 {2},建议减小到{3}以内: 宽:{4} 高:{5} {6}\n", prefabName, name, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit, tex.width, tex.height, tex.name); } else { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 alphamapTexture {2} 为空!\n", prefabName, name, i); } } if (terrainData.detailPrototypes != null && terrainData.detailPrototypes.Length > 0) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 包含detailMap(草地??) 个数: {2},建议去掉!\n", prefabName, name, terrainData.detailPrototypes.Length); } } } else { List <GameObject> rendererList = new List <GameObject>(); CUnityUtil.FindChildLeaf(typeof(Terrain), scenePrefab, rendererList); //检查terrainData int count = 0; int total = rendererList.Count; foreach (var go in rendererList) { Terrain terrain = go.GetComponent <Terrain>(); string name = terrain.name; TerrainData terrainData = terrain.terrainData; ++count; string shortName = System.IO.Path.GetFileNameWithoutExtension(prefabName); GameDataCheckMan.Instance.SetDesc(string.Format("{0} 检查Terrain: {1}", shortName, name)); GameDataCheckMan.Instance.SetPartProgress((float)count / total); yield return(null); //会导致basemap过大 if (terrainData.baseMapResolution > TerrainBaseMapSizeLimit) { //AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 BaseTextureResolution 大于 {2},建议减小到{3}以内!\n", prefabName, name, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit); } for (int i = 0; i < terrainData.splatPrototypes.Length; ++i) { var splat = terrainData.splatPrototypes[i]; var tex = splat.texture; if (tex != null) { //if (tex.width > 512 || tex.height > 512) // _ErrorString += string.Format("{0} terrain 的 splatTexture 大小 大于 512,建议减小到512以内: {1}\n", prefabName, tex.name); bool bValid = true; string errorMsg = ""; for (int level = 0; level < tex.mipmapCount; ++level) { if (!CUnityUtil.CanGetPixel32(tex, level, out errorMsg)) { bValid = false; break; } } if (!bValid) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 splatTexture {2} 无法读取像素,请确保Texture开启read/write权限: {3}, Message: {4}\n", prefabName, name, i, tex.name, errorMsg); } //else // _ErrorString += string.Format("{0} terrain 的 splatTexture {1} 正常读取像素: {2}\n", prefabName, i, tex.name); } else { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 splatTexture {2} 为空!\n", prefabName, name, i); } } if (terrainData.alphamapLayers > 4) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 alphamapLayers 大于 4,必须减小到4以内!\n", prefabName, name); } if (terrainData.alphamapResolution > TerrainBaseMapSizeLimit) { //AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 ControlTextureResolution 大于 {2},建议减小到{3}以内!\n", prefabName, name, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit); } for (int i = 0; i < terrainData.alphamapTextures.Length; ++i) { var tex = terrainData.alphamapTextures[i]; if (tex != null) { //if (tex.width > TerrainBaseMapSizeLimit || tex.height > TerrainBaseMapSizeLimit) // _ErrorString += string.Format("{0} terrain 的 alphamapTextures大小 大于 {1},建议减小到{2}以内: {3}\n", prefabName, TerrainBaseMapSizeLimit, TerrainBaseMapSizeLimit, tex.name); } else { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 的 alphamapTexture {2} 为空!\n", prefabName, name, i); } } if (terrainData.detailPrototypes != null && terrainData.detailPrototypes.Length > 0) { AddErrorStringFormat(shortName, "{0} 的 terrain {1} 包含detailMap(草地??) 个数: {2},建议去掉!\n", prefabName, name, terrainData.detailPrototypes.Length); } } } yield return(null); }