【Unity】unity打包下载(参考)
2016-01-07 14:03
453 查看
using UnityEngine; using System.Collections; using UnityEditor; using System.IO; /// <summary> /// 编辑器 打包 /// </summary> public class BuildAssetBundle { [MenuItem("build/1.create All Scene AssetBundleName")] static void clearAssetBundleName() { string[] files = Directory.GetFiles(Application.dataPath, "*.unity", SearchOption.AllDirectories); for (int i = 0; i < files.Length; i++) { string currentFile = files[i].Replace("\\", "/"); int startIndex = currentFile.IndexOf("Assets"); string assetFile = currentFile.Substring(startIndex, currentFile.Length - startIndex); string sceneName = Path.GetFileNameWithoutExtension(assetFile); AssetImporter ai = AssetImporter.GetAtPath(assetFile); ai.assetBundleName = sceneName; ai.assetBundleVariant = Main.AB_END; } } [MenuItem("build/2.Build All AssetBundle")] static void buildAssetBundle() { string outPath = Application.streamingAssetsPath + "/AssetBundle"; if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } BuildPipeline.BuildAssetBundles(outPath); } [MenuItem("build/3.clear All AssetBundle")] static void clearAssetBundle() { string outPath = Application.streamingAssetsPath + "/AssetBundle"; if (!Directory.Exists(outPath)) { return; } deleteFileOrFolder(outPath); AssetDatabase.Refresh(); } static void deleteFileOrFolder(string fileOrFolder) { if (Directory.Exists(fileOrFolder)) { string[] allFiles = Directory.GetFiles(fileOrFolder); if (allFiles != null) { for (int i = 0; i < allFiles.Length; i++) { deleteFileOrFolder(allFiles[i]); } } string[] allFolders = Directory.GetDirectories(fileOrFolder); if (allFolders != null) { for (int i = 0; i < allFolders.Length; i++) { deleteFileOrFolder(allFolders[i]); } } Directory.Delete(fileOrFolder); } else { if (File.Exists(fileOrFolder)) { File.Delete(fileOrFolder); } } } } using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; /// <summary> /// 下载 /// </summary> public class Main : MonoBehaviour { public const string AB_END = "assetbundle"; // Use this for initialization void Start() { } // Update is called once per frame void Update() { } void OnGUI() { if (GUILayout.Button("加载a场景")) { StartCoroutine(loadScene("a")); } } IEnumerator loadScene(string sceneName) { string fileFullPath = "file://" + Application.streamingAssetsPath + "/AssetBundle/" + sceneName + "." + AB_END; WWW www = new WWW(fileFullPath); yield return www; if (www.error == null) { AssetBundle abScene = www.assetBundle; SceneManager.LoadScene(sceneName); } else { Debug.LogError("fileFullPath:" + fileFullPath + " error:" + www.error); } www.Dispose(); www = null; } }
相关文章推荐
- 【Unity3D游戏开发】UnityEditor.UI.dll timestamps but is not known in guidmapper...
- Unity3D Editor 扩展
- Unity 数据存储
- unity中解析excel导出的txt文件
- Unity 存储目录
- 在unity通过组件名称(string)添加脚本
- 简单的Animation实现角色行走(学习笔记)
- Unity3d在安卓android的更新(APK覆盖)
- Unity中一键创建常用文件夹
- Unity中一键创建常用文件夹
- unity终极抗锯齿抗白边黑边投影阴影不正常问题解决
- Unity 高版本项目 移植到 低版本
- Unity项目开发准则
- Unity CCTween UGUI 动画插件
- Unity中消息事件的封装与运用
- Unity中的Path对应各平台中的Path
- Unity_Shader开发_Shaderlab(三)---------2016.1.6
- Unity3D 的物理渲染和光照模型
- 游戏动作师使用Unity3D遇到过的所有问题
- Unity_Shader开发_数学(四)---------2016.1.6