Unity Editor下 修改 Prefab

来源:互联网 发布:软件编程工作工作状态 编辑:程序博客网 时间:2024/06/07 08:54
[MenuItem("所有Prefab添加PrefabInfoHerlper组件")]    static void AddPrefabInfoHelper()    {        UnityEngine.Object[] selObjs = Selection.GetFiltered(typeof(UnityEngine.Object), SelectionMode.DeepAssets);        for (int i = 0; i < selObjs.Length; i++)        {            Object selObj = selObjs[i];            string selfPath = AssetDatabase.GetAssetPath(selObj);            if (selfPath.EndsWith(".prefab"))            {                string[] dependPaths = AssetDatabase.GetDependencies(selfPath);                GameObject go = GameObject.Instantiate(selObj) as GameObject;                                PrefabInfoHelper pih = go.GetComponent<PrefabInfoHelper>();                if (pih == null)                {                    pih = go.AddComponent<PrefabInfoHelper>();                }                pih.isInstanced = false;                pih.selfPath = selfPath;                pih.dependPathList.Clear();                pih.dependPathList.AddRange(dependPaths);                PrefabUtility.ReplacePrefab(go, selObj, ReplacePrefabOptions.ConnectToPrefab);                GameObject.DestroyImmediate(go);            }                    }    }

0 0