【Unity】unity打包下载(参考)
来源:互联网 发布:linux localdns查看 编辑:程序博客网 时间:2024/05/17 03:07
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; }}
0 0
- 【Unity】unity打包下载(参考)
- Unity打包
- unity下载
- unity下载
- Unity easyTouch移动代码(参考)
- Unity Linghting参考
- Unity 技巧参考
- unity开发之一:打包(使用细节)
- unity提取打包资源
- Unity自动打包思路
- Unity自动打包工具
- Unity 资源打包Assetbundle
- Unity自动打包工具
- unity命令行打包
- 【unity资源管理】 打包
- Unity安卓打包
- Unity 资源打包Assetbundle
- unity图片打包
- IOS UIAlertControl与UIAlertAction
- [IMX6Q]u-boot启动kernel流程
- 关于脏数据比如说,有两个用户A,B同时操作数据库,A开始了一个事务,修改了某行,但还未提交,这个时
- 快速掌握EDIUS的几个常用技巧
- iOS 大头针 MKAnnotationView 自定义
- 【Unity】unity打包下载(参考)
- How to change your USB Serial Port COM number?
- MFC工程的Dui+Win32改造案例遇到的问题总结
- Handler
- SVM 支持向量机
- springmvc+spring+mybatis项目部署中遇到的问题
- 02.类、类指针和别名、类与结构体区别
- 【c/c++】关键字typedef
- 前端程序员应该知道的 15 个 jQuery 小技巧