unity 代码设置要打包的AssetBundle
来源:互联网 发布:杭州哪里可以学美工 编辑:程序博客网 时间:2024/05/21 07:58
1、AssetBundle 在unity 5 中要先标志好,然后就可以打包时根据平台直接打包即可,手动设置不现实,根据文件路径来确定其归属是一个不错的选择
把需要打包的资源都存在 <span style="font-family: Arial, Helvetica, sans-serif;">AssetBundle 中,然后在Editor 目录加入下面代码</span>
using UnityEngine;using UnityEditor;using System.Collections;using System;using System.IO;public class AssetBundlePostProcessor : AssetPostprocessor{private const string assetBundleRootPath = "Assets/AssetBundle/";static void OnPostprocessAllAssets (string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {foreach (var str in importedAssets){bool isChanged = CheckModifyIsTarget (str);if (isChanged) {Debug.Log("isChanged Asset: " + str);SetAssetBundleName (str);}}}// 检测是否是我希望设置的文件static bool CheckModifyIsTarget(string path){if(Directory.Exists (path)){return false;}string fileName = Path.GetFileName (path);if (string.IsNullOrEmpty (fileName) || fileName.EndsWith (".meta")) {return false;} else {return path.Contains (assetBundleRootPath);}}static void SetAssetBundleName(string path){string asName = GetAssetNameByPath (path);AssetImporter importer = AssetImporter.GetAtPath (path);importer.SetAssetBundleNameAndVariant (asName, "");}static string GetAssetNameByPath(string path){int index = assetBundleRootPath.Length;string substr = path.Substring (index);int lastFlashIndex = substr.LastIndexOf ('/');return substr.Substring (0, lastFlashIndex);}}
2、在网络上看到别人的做法,感觉更好,那就是在打包的时候先设置好,然后再打包。
因为上面 1 的方法没有 reimport 就可能会有问题,而这个方法是在打包时全部设置一次,挺好的。。不过就是可能打包时间比较长。。。
每次打包都设置一次,似乎也会重复,如果要打包两次可能就会重复
0 0
- unity 代码设置要打包的AssetBundle
- Unity中AssetBundle的打包和加载
- Unity 资源打包Assetbundle
- Unity 资源打包Assetbundle
- Unity 资源打包Assetbundle
- Unity资源打包Assetbundle
- [Unity]AssetBundle打包策略
- Unity AssetBundle打包
- 【Unity】Unity5版本的AssetBundle打包方案之资源打包
- Unity资源打包之Assetbundle
- Unity之资源打包Assetbundle
- unity assetBundle更新 打包变化
- Unity资源打包之Assetbundle
- unity AssetBundle打包以及加载
- Unity AssetBundle 打包爬坑
- unity Editor 下Assetbundle 打包
- 【Unity开发】Unity5.x版本的AssetBundle打包
- 【Unity】资源打包AssetBundle的概念和流程
- 字符/字符串操作函数(C)
- the operation couldn't be completed.
- HDU 2059 龟兔赛跑
- jquery源码分析—data缓存
- 【QT学习】解决对话框的中文字符串乱码
- unity 代码设置要打包的AssetBundle
- Spring 中的SpEL
- 文本特征提取
- 创建型模式————工厂方法模式
- 4Sum 找出满足要求的4元组
- 'Invalid type in JSON write (NSConcreteMutableData)'
- linux中安装g++
- iframe中父与子页面访问权限问题
- Delphi 字符指针分配内存