forked from Syomus/ProceduralToolkit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeshFilterExtension.cs
34 lines (30 loc) · 1 KB
/
MeshFilterExtension.cs
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
using UnityEngine;
using UnityEditor;
namespace ProceduralToolkit.Editor
{
/// <summary>
/// Mesh saving utility available at `MeshFilter context menu > Save Mesh`
/// </summary>
public class MeshFilterExtension
{
private const string menuPath = "CONTEXT/MeshFilter/Save Mesh";
[MenuItem(menuPath)]
private static void SaveMesh(MenuCommand menuCommand)
{
var meshFilter = (MeshFilter) menuCommand.context;
var mesh = meshFilter.sharedMesh;
var path = EditorUtility.SaveFilePanelInProject("Save Mesh", mesh.name, "asset", "Save Mesh");
if (string.IsNullOrEmpty(path))
{
return;
}
AssetDatabase.CreateAsset(mesh, path);
}
[MenuItem(menuPath, true)]
private static bool SaveMeshTest(MenuCommand menuCommand)
{
var meshFilter = (MeshFilter) menuCommand.context;
return meshFilter.sharedMesh != null;
}
}
}