-
-
Notifications
You must be signed in to change notification settings - Fork 231
Expand file tree
/
Copy pathMeshSaverEditor.cs
More file actions
42 lines (32 loc) · 1.22 KB
/
MeshSaverEditor.cs
File metadata and controls
42 lines (32 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEditor;
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public static class MeshSaverEditor
{
[MenuItem("CONTEXT/MeshFilter/Save Mesh...")]
public static void SaveMeshInPlace(MenuCommand menuCommand)
{
MeshFilter mf = menuCommand.context as MeshFilter;
Mesh m = mf.sharedMesh;
SaveMesh(m, m.name, false, true);
}
[MenuItem("CONTEXT/MeshFilter/Save Mesh As New Instance...")]
public static void SaveMeshNewInstanceItem(MenuCommand menuCommand)
{
MeshFilter mf = menuCommand.context as MeshFilter;
Mesh m = mf.sharedMesh;
SaveMesh(m, m.name, true, true);
}
public static void SaveMesh(Mesh mesh, string name, bool makeNewInstance, bool optimizeMesh)
{
string path = EditorUtility.SaveFilePanel("Save Separate Mesh Asset", "Assets/", name, "asset");
if (string.IsNullOrEmpty(path)) return;
path = FileUtil.GetProjectRelativePath(path);
Mesh meshToSave = (makeNewInstance) ? Object.Instantiate(mesh) as Mesh : mesh;
if (optimizeMesh)
MeshUtility.Optimize(meshToSave);
AssetDatabase.CreateAsset(meshToSave, path);
AssetDatabase.SaveAssets();
}
}