关于U打包代码必须放到Editor目录下的问题
今天在写一个简单的打APK的工具功能时,刚开始打包脚本没有放到Editor目录下,产生了各种奇怪的问题,包括Assembly不可写,磁盘究竟是否满等。
以及AssetBundleBuild及各种其它类不存在等,放入Editor下后一切OK,脚本如下 :
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; using System.IO; public class NewBehaviourScripts { public static void buildab() { } static List<AssetBundleBuild> buildsMap = new List<AssetBundleBuild>(10); [MenuItem("xabc/bd")] public static void TestAb() { buildsMap.Clear(); //shaders var allshadersBuild = new AssetBundleBuild(); allshadersBuild.assetBundleName = "allShaders"; allshadersBuild.assetBundleVariant = "ab"; allshadersBuild.assetNames = new string[2] { "assets/res/shaders/DW_Particle Add_Mask.shader", "assets/res/shaders/allsvc.shadervariants", }; buildsMap.Add(allshadersBuild); //res var allResBuild = new AssetBundleBuild(); allResBuild.assetBundleName = "allRes"; allResBuild.assetNames = new string[3] { "assets/res/icon.png", "assets/res/xmat.mat", "assets/res/Cube.prefab", }; buildsMap.Add(allResBuild); var dir = "d:/testab"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } BuildPipeline.BuildAssetBundles("d:/testab", buildsMap.ToArray(), BuildAssetBundleOptions.DeterministicAssetBundle, BuildTarget.Android); Debug.Log("okkkkk"); } }