From 5419e9b08ff13322590a5503f93103195ba833dc Mon Sep 17 00:00:00 2001 From: ZombieKitty Date: Tue, 10 Jun 2025 20:04:20 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20window=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../EditorWindow/MapDataEditorWindow.cs | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Assets/MindPowerSdk/EditorWindow/MapDataEditorWindow.cs b/Assets/MindPowerSdk/EditorWindow/MapDataEditorWindow.cs index 3ff73f3..5fc0f3a 100644 --- a/Assets/MindPowerSdk/EditorWindow/MapDataEditorWindow.cs +++ b/Assets/MindPowerSdk/EditorWindow/MapDataEditorWindow.cs @@ -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