5

Unity3D研究院之Prefab不挂脚本保存数据

 3 years ago
source link: https://www.xuanyusong.com/archives/4227
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Unity3D研究院之Prefab不挂脚本保存数据

雨松MOMO 【Unity杂文】 围观283178 条评论 编辑日期:2016-08-02 字体:

今天和同事一起发现了一个新科技,我们想在Editor下不给Prefab挂脚本,但是又想保存一些信息到Prefab上。

通过AssetImporter可以把数据保存在userData上,它是get set属性。

    [MenuItem("1/1")]
    static public void Test()
        string path = AssetDatabase.GetAssetPath(Selection.activeObject);
        AssetImporter  import = AssetImporter.GetAtPath(path);
        import.userData = "xuanyusong : MOMO!!!!";
        import.SaveAndReimport();

这样最终数据会记录在Prefab对应的.meta上。

Unity3D研究院之Prefab不挂脚本保存数据 - 雨松MOMO程序研究院 - 1

作者:雨松MOMO
专注移动互联网,Unity3D游戏开发
捐 赠写博客不易,如果您想请我喝一杯星巴克的话?就进来看吧!

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK