Created
July 30, 2022 18:58
-
-
Save pinheadtf2/7804828d695b7e60157a6d70cccf3e32 to your computer and use it in GitHub Desktop.
Unity Editor Mesh Saver
This file contains hidden or 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; | |
using System.Collections; | |
// Usage: Attach to an object, assign target gameobject (from where the mesh is taken), Run, Press savekey | |
public class SaveMeshInEditor : MonoBehaviour | |
{ | |
public string saveName = "SavedMesh"; | |
public Transform selectedGameObject; | |
void Start() | |
{ | |
StartCoroutine(WaitFunc()); | |
} | |
IEnumerator WaitFunc() { | |
yield return new WaitForSeconds(5); | |
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