示例#1
0
        static void BuildAssetBundles()
        {
            if (EditorApplication.isPlayingOrWillChangePlaymode)
            {
                Debug.LogError("Exit play mode before build AssetBundle!");
                return;
            }
            AssetBundleManager.Log("building... cur Time " + Time.realtimeSinceStartup);
            AssetBundleBuildConfig config = LoadAssetAtPath <AssetBundleBuildConfig>(savePath);

            if (config == null)
            {
                return;
            }

            ABBuilder builder = new AssetBundleBuilder5x(new AssetBundlePathResolver());

            builder.SetDataWriter(config.depInfoFileFormat == AssetBundleBuildConfig.Format.Text ? new AssetBundleDataWriter() : new AssetBundleDataBinaryWriter());

            builder.Begin();

            for (int i = 0; i < config.filters.Count; i++)
            {
                AssetBundleFilter f = config.filters[i];
                if (f.valid)
                {
                    builder.AddRootTargets(new DirectoryInfo(f.path), f.packMode, f.filter);
                }
            }
            AssetBundleManager.Log("building... cur Time " + Time.realtimeSinceStartup);
            builder.Export();
            AssetBundleManager.Log("building... cur Time " + Time.realtimeSinceStartup);
            builder.End();
            AssetBundleManager.Log("building... cur Time " + Time.realtimeSinceStartup);
        }