Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created July 7, 2016 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unitycoder/2137d3f3015a7b39f1092b55941092d9 to your computer and use it in GitHub Desktop.
Save unitycoder/2137d3f3015a7b39f1092b55941092d9 to your computer and use it in GitHub Desktop.
Save Mesh In Editor
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
// Usage: Attach to gameobject, assign target gameobject (from where the mesh is taken), Run, Press savekey
public class SaveMeshInEditor : MonoBehaviour
{
public KeyCode saveKey = KeyCode.F12;
public string saveName = "SavedMesh";
public Transform selectedGameObject;
void Update()
{
if (Input.GetKeyDown(saveKey))
{
SaveAsset();
}
}
void SaveAsset()
{
var mf = selectedGameObject.GetComponent<MeshFilter>();
if (mf)
{
var savePath = "Assets/" + saveName + ".asset";
Debug.Log("Saved Mesh to:" + savePath);
AssetDatabase.CreateAsset(mf.mesh, savePath);
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment