关于AssetBundle禁用TypeTree之后的一些可序列化的问题

1)关于AssetBundle禁用TypeTree之后的一些可序列化的问题
2)启动Unity导入变动的资源时,Singleton ScriptableObject 加载不到
3)Xcode15构建Unity 2022.3的Xcode工程,报错没有兼容的iPhone SDK


这是第361篇UWA技术知识分享的推送,精选了UWA社区的热门话题,涵盖了UWA问答、社区帖子等技术知识点,助力大家更全面地掌握和学习。

AssetBundle

Q:如果AssetBundle禁用了TypeTree,Unity在加载的时候会对其引用的脚本进行"签名"校验(Property Hash和FulIName),而包内的脚本信息只在打包的时候生成,并不能直接更新。因此,在禁用TypeTree的时候,貌似不能对可序列化脚本进行变动更新。

于是,想要咨询两个问题:
1、包内的脚本"签名"信息存放在哪里,存放了什么内容? 猜测是在assets/bin/Data,但具体的位置与内容不清楚。

2、能否在禁用TypeTree的情况下实现可序列化脚本的变化更新(自行保证代码与资源一致)。

A:1、脚本"签名"信息是存在MonoScript上,保存了Assembly、Namespace、Class的名称,以及它的可序列化字段的Hash128,用AssetStudio可以看到。

2、在支持热更动态库的平台上(安卓)直接热更libil2cpp.so及元数据应该就可以。若寻求通用方案,恐怕要上HybridCLR这种深度定制IL2CPP的方案,因为引擎需要使用IL2CPP的API以类似反射的方式获取脚本的可序列化字段。

注意:HybridCLR对禁用TypeTree的情况参考以下说明:
MonoBehaviour支持 | HybridCLR

感谢littlesome@UWA问答社区提供了回答


Asset

Q:当有资源变动时,启动Unity,在导入资源时,Singleton ScriptableObject 加载不到,有解决办法么?

问题出现:
把ScriptableObject封装成单例,当配置文件,在别的资源导入的时候需要读单例配置。

已知现象:
加载不到的原因是当有新资源变化时,Asset Database要等新资源初始化完才能初始化完成,这个阶段,很多东西都加载不上来;Resource接口也是不能用的。

A1:可以参考Spine的做法:
https://github.com/EsotericSoftware/spine-runtimes/blob/b09e189c6438cb9358005771c3304b8f52bc4e30/spine-unity/Assets/Spine/Editor/spine-unity/Editor/Utility/AssetUtility.cs#L114

见这段注释:

复制代码
`public static void HandleOnPostprocessAllAssets (string[] imported, List<string> texturesWithoutMetaFile) {
    // In case user used "Assets -> Reimport All", during the import process,
    // asset database is not initialized until some point. During that period,
    // all attempts to load any assets using API (i.e. AssetDatabase.LoadAssetAtPath)
    // will return null, and as result, assets won't be loaded even if they actually exists,
    // which may lead to numerous importing errors.
    // This situation also happens if Library folder is deleted from the project, which is a pretty
    // common case, since when using version control systems, the Library folder must be excluded.
    //
    // So to avoid this, in case asset database is not available, we delay loading the assets
    // until next time.
    //
    // Unity *always* reimports some internal assets after the process is done, so this method
    // is always called once again in a state when asset database is available.
    //
    // Checking whether AssetDatabase is initialized is done by attempting to load
    // a known "marker" asset that should always be available. Failing to load this asset
    // means that AssetDatabase is not initialized.
    AssetUtility.assetsImportedInWrongState.UnionWith(imported);
    if (AssetDatabaseAvailabilityDetector.IsAssetDatabaseAvailable()) {
        string[] combinedAssets = AssetUtility.assetsImportedInWrongState.ToArray();
        AssetUtility.assetsImportedInWrongState.Clear();
        AssetUtility.ImportSpineContent(combinedAssets, texturesWithoutMetaFile);
    }
}
`

感谢littlesome@UWA问答社区提供了回答

A2:将ScriptableObject序列化(例如json)保存到本地,资源导入时候直接读取本地配置反序列化。

感谢zerolj@UWA问答社区提供了回答


Platform

Q:最近不小心升级了Mac的版本,随之Xcode也要求升级到15.0,然而升级后,Unity 2022.3构建的Xcode工程无法构建,报错如下图所示,就是找不到兼容的iPhone SDK,这个问题尝试了很多方法无法解决,求问除了降低版本之外还有没有其他解决方案,万分感谢!

A:建议尝试将/Applications/Xcode.app/Contents/version.plist里的

复制代码
`<key>ProjectName</key>
<string>IDEApplication</string>
`

改成

复制代码
`<key>ProjectName</key>
<string>IDEFrameworks</string>
`

我看了下我在2022.3.10f1里的相关逻辑,已经改为判断是否是IDE开头:

确认了下,2022.3.10f1确实有提及对Xcode15兼容的支持:
Unity 2022.3.10

Unity Issue Tracker - Building projects with IL2CPP scripting backend for Apple platforms fails with Xcode 15.0b6 or newer

感谢littlesome@UWA问答社区提供了回答

封面图来源于网络


今天的分享就到这里。生有涯而知无涯,在漫漫的开发周期中,我们遇到的问题只是冰山一角,UWA社区愿伴你同行,一起探索分享。欢迎更多的开发者加入UWA社区。

UWA官网:www.uwa4d.com
UWA社区:community.uwa4d.com

相关推荐
UWA7 天前
iOS包ShaderVariantCollection预热慢问题
ios·rendering·assetbundle
千松1 个月前
[Unity] 实现AssetBundle资源加载管理器
unity·assetbundle
UWA2 个月前
如何优化Unity发布iOS编译出来的Framework文件过大问题
unity·ios·游戏引擎·lua·memory·assetbundle·sequence
cr72582 个月前
Crossplane 实战:构建统一的云原生控制平面
kubernetes·platform·crossplane
UWA3 个月前
内置管线升级到SBP,如何复用之前打包的AssetBundle
script·rendering·assetbundle
UWA5 个月前
如何在FBX剔除Lit.shader依赖
lua·shader·assetbundle·asset
UWA5 个月前
Unity出AAB包资源加载过慢
unity·游戏引擎·lua·shader·il2cpp·assetbundle
UWA7 个月前
Unity升级到2022版本后,打开Spine会卡住
unity·游戏引擎·spine·platform
UWA7 个月前
如何拆解Unity 2022.3版本的AssetBundle
unity·游戏引擎·platform·assetbundle