Created
July 7, 2016 02:52
-
-
Save unitycoder/2137d3f3015a7b39f1092b55941092d9 to your computer and use it in GitHub Desktop.
Save Mesh In Editor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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