保存网格(mesh)到磁盘上

Unity提供了很方便的工具来保存mesh之类的,下面的代码挂在GameObject上后,按下F键能把mesh(该GameObject必须有mesh组件)保存到磁盘的Assets目录下。在磁盘上是.asset的文件,在project中看到的是一个mesh符号的文件。代码完全是示意作用,没有做严格测试。


using UnityEngine;
using UnityEditor;
using System.Collections;
 
public class Save : MonoBehaviour
{
 
	public string name;
	public Transform obj;
	 
	void Update ()
	{
		if (Input.GetKeyDown("f"))
		{
			SaveAsset();
		}
	}
	 
	void SaveAsset()
	{
		Mesh m1 = obj.GetComponent<MeshFilter>().mesh;
		AssetDatabase.CreateAsset(m1, "Assets/" + name + ".asset");
	}
 
}


全文完。



原文地址:https://www.cnblogs.com/mengfanrong/p/3713870.html