修改 window 工具
This commit is contained in:
parent
c5877622c8
commit
5419e9b08f
@ -46,6 +46,11 @@ namespace MindPowerSdk.Editor
|
||||
GUILayout.Label("文件夹路径设置", EditorStyles.boldLabel);
|
||||
// 数据源文件夹选择
|
||||
EditorGUILayout.BeginHorizontal();
|
||||
|
||||
// 从持久化文件中读取
|
||||
mapDataFolder = EditorPrefs.GetString("MapDataFolder", mapDataFolder);
|
||||
resourceDataFolder = EditorPrefs.GetString("ResourceDataFolder", resourceDataFolder);
|
||||
|
||||
mapDataFolder = EditorGUILayout.TextField("数据源文件夹", mapDataFolder);
|
||||
if (GUILayout.Button("选择", GUILayout.Width(60)))
|
||||
{
|
||||
@ -70,6 +75,11 @@ namespace MindPowerSdk.Editor
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
EditorPrefs.SetString("ResourceDataFolder", resourceDataFolder);
|
||||
EditorPrefs.SetString("MapDataFolder", mapDataFolder);
|
||||
|
||||
|
||||
EditorGUILayout.EndHorizontal();
|
||||
|
||||
GUILayout.Space(10);
|
||||
@ -335,12 +345,53 @@ namespace MindPowerSdk.Editor
|
||||
AssetDatabase.Refresh();
|
||||
AssetDatabase.CreateAsset(terrain.materialTemplate, materialDir);
|
||||
AssetDatabase.CreateAsset(terrainCollider.terrainData, terrainDataPath);
|
||||
|
||||
// 把 terrain.materialTemplate 中所有的图片保存下来
|
||||
foreach (var texturePropertyName in terrain.materialTemplate.GetTexturePropertyNames())
|
||||
{
|
||||
var texture = terrain.materialTemplate.GetTexture(texturePropertyName);
|
||||
if (texture)
|
||||
{
|
||||
Debug.Log($"保存材质贴图:{texturePropertyName} | {texture.name}");
|
||||
string texturePath = texturesDir.Replace(@"\", "/");
|
||||
texturePath = texturePath.Replace(Application.dataPath, "Assets");
|
||||
var textName = texturePropertyName;
|
||||
texturePath = $"{texturePath}/{textName}.png";
|
||||
|
||||
// 检查纹理是否已经是项目中的资产
|
||||
string originalPath = AssetDatabase.GetAssetPath(texture);
|
||||
if (!string.IsNullOrEmpty(originalPath))
|
||||
{
|
||||
// 如果是已存在的资产,复制到目标位置
|
||||
if (!File.Exists(texturePath))
|
||||
{
|
||||
AssetDatabase.CopyAsset(originalPath, texturePath);
|
||||
Debug.Log($"复制材质贴图:{originalPath} -> {texturePath}");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果是运行时生成的纹理,保存为PNG文件
|
||||
if (texture is Texture2D texture2D)
|
||||
{
|
||||
byte[] bytes = texture2D.EncodeToPNG();
|
||||
if (bytes != null)
|
||||
{
|
||||
File.WriteAllBytes(texturePath.Replace("Assets", Application.dataPath), bytes);
|
||||
AssetDatabase.ImportAsset(texturePath);
|
||||
Debug.Log($"导出材质贴图:{texturePath}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PrefabUtility.SaveAsPrefabAssetAndConnect(mapTransform.gameObject, prefabPath,
|
||||
InteractionMode.UserAction);
|
||||
|
||||
|
||||
Debug.Log($"保存预制体:{prefabPath}");
|
||||
}
|
||||
#else
|
||||
|
Loading…
x
Reference in New Issue
Block a user