当前位置: 首页 > news >正文

daaoling / daaoling.github.io

daaoling / daaoling.github.io

https://github.com/daaoling/daaoling.github.io/wiki/Unity-AssetBundle-%E8%B8%A9%E5%9D%91%E8%AE%B0%E5%BD%95

 

Unity AssetBundle 踩坑记录

daaoling edited this page Jul 14, 2016 · 1 revision

 

Unity AssetBundle 踩坑记录

 

Unity 版本 4.6.9

 

editor 下选择什么平台的 ab 加载

Material doesn't have a color property '_Color' UnityEditor.DockArea:OnGUI()

Material doesn't have a float or range property 'PixelSnap' UnityEditor.DockArea:OnGUI()

因为editor模式下所有的 platform ab 都是可以用的 并且打 android ab 包必须要把platform转换为android 但是自己写的cg shader 如果打成 android ab 在editor 模式下没有OpenGL 2.0 环境会报错 只有打成windows包

但是好像其他 surface shader 是可以的ASœ

参考

关于打包shader丢失参数的问题


 

The asset bundle '' can't be loaded because another asset bundle with the same files are already loaded

 

create scene assetbundle Scenes/battle/MapEditor/53.unityin _LoadImmediate failed

 

可能的原因

  • 相同名字 bundle load 加载后

    http://forum.unity3d.com/threads/asset-bundle-cant-be-the-same-name.190275

    这里经过测试过 发现相同名字不同后缀的单个资源 bundle 是可以的

    但是相同名字相同后缀即使路径不同也是不可以的

  • ab重复加载

 

解决方法

后期使用asset guid 来给ab命名 ab的asset name path 随意 guid 也行 相对于 asset path 也行

 

不同机子打包的ab md5 值不同 无语了


 

打 ab 最好把脚本打进去 有概率会出现看不见的情况


 

如果在同一个场景对ab做清理对话 会对当时的场景造成当时就材质丢失的情况 就是出现闪一下红色

最好就是弄个东西挡一下 比如ui 或者 弄一个单独加载场景的场景 在挡着的时候进行卸载

 

load sprite from ab

[MenuItem("Build/Tools/Test")]
public static void TestSceneAssets() {
    UnityEngine.Object[] assets =
        new UnityEngine.Object[] {
             AssetDatabase.LoadAssetAtPath("Assets/Resources/Icon/ectype_chapter/1.png",
                 typeof(UnityEngine.Object)) };
    UnityEngine.Object mainAsset = assets[0];

    string savePath =
        "f:/assetbundles/windows/"
            + "d4fe2a6e186849f4086398d2ceeb0510"
                + ResourceCommon.assetbundleFileSuffix;
    BuildPipeline.BuildAssetBundle(
        mainAsset, assets, savePath,
            BuildAssetBundleOptions.CollectDependencies
                | BuildAssetBundleOptions.CompleteAssets
                    | BuildAssetBundleOptions.DeterministicAssetBundle,
                        BuildTarget.StandaloneWindows);
}


mTest6.cs

void OnGUI()
{
    if (GUI.Button(new Rect(10, 10, 150, 100), "I am a button")) Test();
}


void Test()
{
    TextAsset bundleFile = Resources.Load("d4fe2a6e186849f4086398d2ceeb0510") as TextAsset;
    AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(bundleFile.bytes);
    Object[] assets = assetBundle.LoadAll();
    foreach (Object asset in assets)
    {
        Debug.Log("loaded asset " + asset.name + " of type " + asset.GetType());
    }
}

//loaded asset 1 of type UnityEngine.Texture2D
//loaded asset 1 of type UnityEngine.Sprite


string path = "Assets/NGUI/Examples/Models/Orc/FBX.FBX";
UnityEngine.Object[] assets = new UnityEngine.Object[] {
    AssetDatabase.LoadAssetAtPath(path, typeof(UnityEngine.Object)) };
string[] depends = AssetDatabase.GetDependencies(new string[] { path });
foreach (string str in depends)
{
    Debug.Log("depency: " + str);
}
//depency: Assets/NGUI/Examples/Models/Orc/FBX@idle.FBX
//depency: Assets/NGUI/Examples/Models/Orc/FBX@idleBreaks.FBX
//depency: Assets/NGUI/Examples/Models/Orc/FBX.FBX


List<string> tmp = new List<string>();
int index = 0;
foreach (Object asset in assets){
    Debug.Log("loaded asset " + asset.name + " of type " + asset.GetType());
    index++;
    tmp.Add(index+"");
}
UnityEngine.Object mainAsset = assets[0];

string savePath =
    "f:/assetbundles/windows/"
        + "d4fe2a6e186849f4086398d2ceeb0510"
            + ResourceCommon.assetbundleFileSuffix;
-----1
BuildPipeline.BuildAssetBundle(
    mainAsset, assets, savePath,
        BuildAssetBundleOptions.CollectDependencies
            | BuildAssetBundleOptions.CompleteAssets
                | BuildAssetBundleOptions.DeterministicAssetBundle,
                    BuildTarget.StandaloneWindows); 会收集依赖  比如 fbx@idle 等等

-----2
BuildPipeline.BuildAssetBundleExplicitAssetNames(
        assets, tmp.ToArray(), savePath,
        BuildAssetBundleOptions.CollectDependencies
            | BuildAssetBundleOptions.CompleteAssets
                | BuildAssetBundleOptions.DeterministicAssetBundle,
                    BuildTarget.StandaloneWindows); ///不会收集依赖  比如 fbx@idle 等等



void Test()
{
    TextAsset bundleFile = Resources.Load("d4fe2a6e186849f4086398d2ceeb0510") as TextAsset;
    AssetBundle assetBundle = AssetBundle.CreateFromMemoryImmediate(bundleFile.bytes);
    Object[] assets = assetBundle.LoadAll();
    foreach (Object asset in assets)
    {
        Debug.Log("loaded asset " + asset.name + " of type " + asset.GetType());
    }
}
-----1
//loaded asset FBX of type UnityEngine.GameObject
//loaded asset FBX of type UnityEngine.Transform
//loaded asset Orc of type UnityEngine.Mesh
//loaded asset FBX@idle of type UnityEngine.GameObject
//loaded asset FBX@idle of type UnityEngine.Transform
//loaded asset Orc of type UnityEngine.Mesh
//loaded asset idle of type UnityEngine.AnimationClip  .etc

------2
//loaded asset FBX of type UnityEngine.GameObject
//loaded asset FBX of type UnityEngine.Transform

从上述实验看 BuildPipeline.BuildAssetBundle 和 BuildPipeline.BuildAssetBundleExplicitAssetNames 不同之处 就在于后者只打包你当前指定的资源,比如 fix 或者 texture2d 下面的 mesh 和 sprite 不会打包进去 , 并且依赖比如 fbx@idle 也不会打包进去 , 不过这个还好,正好是我们当前的打包策略,依赖由我们自己掌握

这样我们考虑 texture2d 的打包策略和 prefab 的打包策略不一样了 或者 内存中动态生成sprite

参考

load-unity-43-sprites-with-assetbundles

 

 

 

相关文章:

  • 一个灵活的AssetBundle打包工具
  • BuildPipeline.BuildAssetBundleExplicitAssetNames
  • Unity5.x shader打包AssetBundle总结
  • Unity 加载AssetBundle
  • Unity开发(三) AssetBundle同步异步引用计数资源加载管理器
  • Unity脚本运行时更新带来了什么?
  • UE4 补丁更新(基于Http)
  • UE4 Pak加载
  • Unity3D Shader加载时机和预编译
  • ShaderVariantCollection解决shader_feature丢失
  • 一次UNITY闪退问题的定位心得
  • Unity AssetBundle打包 , BuildAssetBundleOptions
  • protobuf-net 的应用
  • Using Unity’s ShaderVariantCollection
  • Unity技术分享连载(64)|Shader Variant Collection|Material.SetPassFast
  • Android 初级面试者拾遗(前台界面篇)之 Activity 和 Fragment
  • JavaScript DOM 10 - 滚动
  • npx命令介绍
  • PermissionScope Swift4 兼容问题
  • Python十分钟制作属于你自己的个性logo
  • Redis的resp协议
  • Sass Day-01
  • Spring声明式事务管理之一:五大属性分析
  • uni-app项目数字滚动
  • 从tcpdump抓包看TCP/IP协议
  • 计算机在识别图像时“看到”了什么?
  • 离散点最小(凸)包围边界查找
  • 力扣(LeetCode)22
  • 区块链分支循环
  • 区块链技术特点之去中心化特性
  • 首页查询功能的一次实现过程
  • 数据科学 第 3 章 11 字符串处理
  • 通过npm或yarn自动生成vue组件
  • 网络应用优化——时延与带宽
  • 我有几个粽子,和一个故事
  • 用Node EJS写一个爬虫脚本每天定时给心爱的她发一封暖心邮件
  • Android开发者必备:推荐一款助力开发的开源APP
  • 继 XDL 之后,阿里妈妈开源大规模分布式图表征学习框架 Euler ...
  • 新年再起“裁员潮”,“钢铁侠”马斯克要一举裁掉SpaceX 600余名员工 ...
  • 支付宝花15年解决的这个问题,顶得上做出十个支付宝 ...
  • ​草莓熊python turtle绘图代码(玫瑰花版)附源代码
  • #使用清华镜像源 安装/更新 指定版本tensorflow
  • ${factoryList }后面有空格不影响
  • (6)添加vue-cookie
  • (arch)linux 转换文件编码格式
  • (webRTC、RecordRTC):navigator.mediaDevices undefined
  • (zz)子曾经曰过:先有司,赦小过,举贤才
  • (八)Docker网络跨主机通讯vxlan和vlan
  • (搬运以学习)flask 上下文的实现
  • (二)linux使用docker容器运行mysql
  • (欧拉)openEuler系统添加网卡文件配置流程、(欧拉)openEuler系统手动配置ipv6地址流程、(欧拉)openEuler系统网络管理说明
  • (七)理解angular中的module和injector,即依赖注入
  • (十一)c52学习之旅-动态数码管
  • (学习日记)2024.01.19
  • ****** 二 ******、软设笔记【数据结构】-KMP算法、树、二叉树