PropertyModification

作者:追风剑情 发布于:2018-12-18 10:55 分类:Unity3d

示例代码

[MenuItem("Assets/资源工具/Test", false, 100)]
public static void Test()
{
	//原文 https://blog.csdn.net/zgjllf1011/article/details/79304743
	//保存自定义参数到.meta文件中
	string path = AssetDatabase.GetAssetPath(Selection.activeObject);
	AssetImporter  import = AssetImporter.GetAtPath(path);
	import.userData = "this is user data";
	import.SaveAndReimport();

	//保存自定义参数到prefab文件中
	PropertyModification pm = new PropertyModification();
	pm.propertyPath = "custom";
	pm.value = "this is custom property";

	PropertyModification[] modifications = { pm };
	PrefabUtility.SetPropertyModifications(Selection.activeObject, modifications);

	AssetDatabase.SaveAssets();
	AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
}

文件截图

11111.png

2222.png

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号