8

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

 9 months ago
source link: https://blog.uwa4d.com/archives/TechSharing_361.html
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

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


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

UWA社区主页:community.uwa4d.com
UWA QQ群:465082844

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的情况参考以下说明:
https://hybridclr.doc.code-philosophy.com/docs/basic/monobehaviour#%E5%85%B6%E5%AE%83

感谢littlesome@UWA问答社区提供了回答,欢迎大家转至社区交流:
https://answer.uwa4d.com/question/654df8b03625c22cffcb1d04


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问答社区提供了回答,欢迎大家转至社区交流:
https://answer.uwa4d.com/question/654865203625c22cffcb1cdf


Platform

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

1.png

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

<key>ProjectName</key>
<string>IDEApplication</string>
<key>ProjectName</key>
<string>IDEFrameworks</string>

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

2.png

确认了下,2022.3.10f1确实有提及对Xcode15兼容的支持:
https://unity.com/releases/editor/whats-new/2022.3.10

https://issuetracker.unity3d.com/issues/building-projects-with-il2cpp-scripting-backend-for-apple-platforms-fails-with-xcode-15-dot-0b6-or-newer

感谢littlesome@UWA问答社区提供了回答,欢迎大家转至社区交流:
https://answer.uwa4d.com/question/6544ec5f3625c22cffcb1cd3

封面图来源于网络


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

UWA官网:www.uwa4d.com
UWA社区:community.uwa4d.com
UWA学堂:edu.uwa4d.com
官方技术QQ群:465082844


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK