Unity 中关于Assetbundle的Editor操作

本文介绍了一组用于Unity项目的资源管理工具,包括打包AssetBundle、列出资源依赖、清理PlayerPrefs、展示所有AssetBundle名称及打开持久化数据路径等功能。这些工具通过菜单项的形式集成到Unity编辑器中,方便开发者进行资源管理和调试。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 //
    // 摘要:
    //   把资源打成AssetBundle包,

    //
 [MenuItem("Tools/Build Hall AssetBundles")]
    static void BuildHallAssetBundles()
    {
                //执行打包
        BuildPipeline.BuildAssetBundles(Application.streamingAssetsPath, BuildAssetBundleOptions.DeterministicAssetBundle, EditorUserBuildSettings.activeBuildTarget);

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

// // 摘要: // 列出编辑器Project窗口中选中的文件,它所依赖的资源 // // [MenuItem("Tools/List Dependencies")] static void ListDependencies() { string path = AssetDatabase.GetAssetPath(UnityEditor.Selection.activeObject); if (path != "") { string[] dps = AssetDatabase.GetDependencies(path); Debug.Log(string.Format("List dependencies:[{0}]", path)); for (int i = 0; i < dps.Length; i++) { Debug.Log(string.Format(" Item {0}:", i + 1)); Debug.Log(string.Format(" path:{0}", dps[i])); Debug.Log(string.Format(" GUID:{0}", AssetDatabase.AssetPathToGUID(dps[i]))); } } }
//
    // 摘要:
    //     清理游戏本地的设置数据,PlayerPrefs,
    //
    //
    [MenuItem("Tools/Clear PlayerPrefs")]
    public static void ClearPlayerPrefs()
    {
        PlayerPrefs.DeleteAll();
    }

    //
    // 摘要:
    //     显示PC中StreamingAssets下的所有assetbundle名字
    //
    //
    [MenuItem("Tools/Show All AssetBundles")]
    public static void ShowAllAssetBundles()
    {
        AssetBundle bundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "StreamingAssets"));
        AssetBundleManifest manifest = bundle.LoadAsset<AssetBundleManifest>("AssetBundleManifest");
        bundle.Unload(false);
        string[] BundleNames = manifest.GetAllAssetBundles();
        foreach (string name in BundleNames)
        {
            Debug.Log("ResTools: " + name);
        }
    }
    //
    // 摘要:
    //     打开PC的persistentDataPath目录
    //
    //
    [MenuItem("Tools/Show PersistentData in Explorer...")]
    public static void ShowPersistentDataInExplor()
    {
        string path = Application.persistentDataPath.Replace("/", "\\");
        System.Diagnostics.Process.Start(path);
    }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值