当前位置:   article > 正文

unity3d保存代码生成的Mesh到Assets目录下_unity保存mesh

unity保存mesh

Unity-MeshSaver/MeshSaverEditor.cs at master · pharan/Unity-MeshSaver · GitHub

使用时在meshFilter上点右键,选择Save Mesh即可。

 

  1. using UnityEditor;
  2. using UnityEngine;
  3. public class MeshSaverEditor : MonoBehaviour
  4. {
  5. [MenuItem("CONTEXT/MeshFilter/Save Mesh...")]
  6. public static void SaveMeshInPlace(MenuCommand menuCommand)
  7. {
  8. MeshFilter mf = menuCommand.context as MeshFilter;
  9. Mesh m = mf.sharedMesh;
  10. SaveMesh(m, m.name, false, true);
  11. }
  12. [MenuItem("CONTEXT/MeshFilter/Save Mesh As New Instance...")]
  13. public static void SaveMeshNewInstanceItem(MenuCommand menuCommand)
  14. {
  15. MeshFilter mf = menuCommand.context as MeshFilter;
  16. Mesh m = mf.sharedMesh;
  17. SaveMesh(m, m.name, true, true);
  18. }
  19. public static void SaveMesh(Mesh mesh, string name, bool makeNewInstance, bool optimizeMesh)
  20. {
  21. string path = EditorUtility.SaveFilePanel("Save Separate Mesh Asset", "Assets/", name, "asset");
  22. if (string.IsNullOrEmpty(path)) return;
  23. path = FileUtil.GetProjectRelativePath(path);
  24. Mesh meshToSave = (makeNewInstance) ? Object.Instantiate(mesh) as Mesh : mesh;
  25. if (optimizeMesh)
  26. MeshUtility.Optimize(meshToSave);
  27. AssetDatabase.CreateAsset(meshToSave, path);
  28. AssetDatabase.SaveAssets();
  29. }
  30. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/weixin_40725706/article/detail/580272
推荐阅读
相关标签
  

闽ICP备14008679号