升级生成工具
This commit is contained in:
Assets/MindPowerSdk/EditorWindow
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
using MindPowerSdk;
|
||||
@ -14,9 +15,10 @@ public static class TerrainGenerator
|
||||
/// <param name="parent">生成的 Terrain 父节点</param>
|
||||
/// <param name="isSmoothing"></param>
|
||||
/// <param name="entryMapName"></param>
|
||||
public static void GenTerrain(MPMap map, int chunkSize, Material terrainMaterial, Transform parent,
|
||||
string entryMapName, bool isSmoothing = true)
|
||||
public static List<Texture> GenTerrain(MPMap map, int chunkSize, Material terrainMaterial, Transform parent,
|
||||
string entryMapName, bool isSmoothing = true)
|
||||
{
|
||||
List<Texture> textureList = new List<Texture>();
|
||||
// 计算全局高度范围(归一化用)
|
||||
(float globalMin, float globalMax) = ComputeGlobalHeightRange(map);
|
||||
|
||||
@ -55,7 +57,8 @@ public static class TerrainGenerator
|
||||
Debug.LogWarning($"{startX} {startY} {chunkSize}");
|
||||
(Texture2D texNo, Texture2D maskNo) = map.GenTxtNoTexture((short)startX, (short)startY, chunkSize);
|
||||
|
||||
|
||||
textureList.Add(texNo);
|
||||
textureList.Add(maskNo);
|
||||
// 设置每个 tile 在辅助 baked UV 贴图中希望的像素尺寸(建议不小于 4)
|
||||
int cellPixelSize = 7;
|
||||
|
||||
@ -80,7 +83,7 @@ public static class TerrainGenerator
|
||||
GameObject terrainGO = Terrain.CreateTerrainGameObject(terrainData);
|
||||
terrainGO.name = $"terrain_{i}_{j}";
|
||||
terrainGO.transform.parent = terrainMap.transform;
|
||||
terrainGO.transform.position = new Vector3(startX, globalMin, startY - chunkSize);
|
||||
terrainGO.transform.position = new Vector3(startX, globalMin, startY - chunkSize + 1);
|
||||
Debug.Log($"terrainGO: {terrainGO.name} | pos: {terrainGO.transform.position}");
|
||||
// 设置 Terrain 为自定义材质模式,并赋予生成的材质实例
|
||||
Terrain terrainComponent = terrainGO.GetComponent<Terrain>();
|
||||
@ -88,6 +91,8 @@ public static class TerrainGenerator
|
||||
terrainComponent.materialTemplate = matInstance;
|
||||
}
|
||||
}
|
||||
|
||||
return textureList;
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user