[unity3d]Assetbundle使用示例2(支持多平台)
来源:互联网 发布:linux的date命令 编辑:程序博客网 时间:2024/06/05 20:29
支持多平台的Assetbundle的应用示例,贴代码,供学习!
这里不同平台的StreamingAssets是不同的,所以我们要写预处理!
using UnityEngine;using System.Collections;public class RunScript : MonoBehaviour{ //不同平台下StreamingAssets的路径是不同的,这里需要注意一下。 public static readonly string PathURL =#if UNITY_ANDROID"jar:file://" + Application.dataPath + "!/assets/";#elif UNITY_IPHONEApplication.dataPath + "/Raw/";#elif UNITY_STANDALONE_WIN || UNITY_EDITOR"file://" + Application.dataPath + "/StreamingAssets/";#else string.Empty;#endifvoid OnGUI(){if(GUILayout.Button("Main Assetbundle")){//StartCoroutine(LoadMainGameObject(PathURL + "Prefab0.assetbundle"));//StartCoroutine(LoadMainGameObject(PathURL + "Prefab1.assetbundle"));StartCoroutine(LoadMainCacheGameObject(PathURL + "Prefab0.assetbundle"));StartCoroutine(LoadMainCacheGameObject(PathURL + "Prefab1.assetbundle"));}if(GUILayout.Button("ALL Assetbundle")){StartCoroutine(LoadALLGameObject(PathURL + "ALL.assetbundle"));}if(GUILayout.Button("Open Scene")){StartCoroutine(LoadScene());}}//读取一个资源private IEnumerator LoadMainGameObject(string path){ WWW bundle = new WWW(path); yield return bundle; //加载到游戏中 yield return Instantiate(bundle.assetBundle.mainAsset); bundle.assetBundle.Unload(false);}//读取全部资源private IEnumerator LoadALLGameObject(string path){ WWW bundle = new WWW(path); yield return bundle; //通过Prefab的名称把他们都读取出来 Object obj0 = bundle.assetBundle.Load("Prefab0"); Object obj1 = bundle.assetBundle.Load("Prefab1"); //加载到游戏中 yield return Instantiate(obj0); yield return Instantiate(obj1); bundle.assetBundle.Unload(false);}private IEnumerator LoadMainCacheGameObject(string path){ WWW bundle = WWW.LoadFromCacheOrDownload(path,5); yield return bundle; //加载到游戏中 yield return Instantiate(bundle.assetBundle.mainAsset); bundle.assetBundle.Unload(false);}private IEnumerator LoadScene(){ WWW download = WWW.LoadFromCacheOrDownload ("file://"+Application.dataPath + "/MyScene.unity3d", 1); yield return download; var bundle = download.assetBundle; Application.LoadLevel ("Level");}}
截图:
关于Unity3D,我们有个专门技术讨论的大群,可以进行技术交流和咨询,群号:858550 欢迎进行技术讨论,里面有不少大牛
- [unity3d]Assetbundle使用示例2(支持多平台)
- Unity3d Assetbundle代码示例
- Unity3d Load AssetBundle(不同平台)
- Unity3D之AssetBundle【2】AssetBundle流程分析
- unity3d开发2d游戏关于Assetbundle的使用
- unity3d开发2d游戏时注意使用Assetbundle
- 2、Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D研究院之Assetbundle的使用
- 【Unity3D自学记录】使用assetbundle时可能遇到的坑
- Unity3d 开发(六) 5.x AssetBundle使用
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D -- 5.X 新版AssetBundle使用方案及策略
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D 5.3 新版AssetBundle使用方案及策略
- Unity3D 5.X 新版AssetBundle使用方案及策略
- 输入圆的半径,求出该半径的圆的周长和面积并输出
- 泛型算法
- Vmware10下安装Mac OS X Mountain Lion10.8.5
- 解决fatal: No remote repository specified. Please, specify either a URL...
- 输入矩形的长和宽,求出该矩形的周长和面积
- [unity3d]Assetbundle使用示例2(支持多平台)
- [转载]图像处理与计算机视觉:基础,经典以及最近发展
- 工作效率低下?业内人士建议你切勿追求完美
- 在linux终端下打开pdf文件
- Android导入一个工程时提示 Invalid project description的解决方法
- locale::facet::_S_create_c_locale name not valid
- 任意输入两个整数,输出最大值
- switch语言的应用
- Visual Studio 项目生成器,方便在Windows下查看uboot、linux源码