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");
	}
 
}


全文完。



相关文章:

  • 2021-12-02
  • 2021-05-06
  • 2021-08-15
  • 2022-01-13
  • 2022-02-22
  • 2022-12-23
  • 2022-12-23
  • 2021-07-28
猜你喜欢
  • 2021-12-08
  • 2022-12-23
  • 2022-03-04
  • 2021-09-13
  • 2021-07-27
  • 2022-12-23
  • 2021-08-20
相关资源
相似解决方案