1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- //这是原码
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using UnityEditor;
- using UnityEngine;
- public class ABPacket : Editor
- {
- //Ab包目标文件目录
- public static string path = Application.dataPath + "/Rec/ui/panel/";
- //public static string path = Application.dataPath + "/Rec/ui/texture/";
- //public static string path = Application.dataPath + "/Rec/ui/Material/";
- //Ab包出包文件目录
- public static string pathExit = Application.streamingAssetsPath;
- public static string pathPxit = Application.persistentDataPath;
- //Ab包目标文件集合
- private static List<AssetBundleBuild> abs = new List<AssetBundleBuild>();
- [MenuItem("ABmanager/打包Windows64")]
- static void BuildABs()
- {
- BuildTarget target = BuildTarget.StandaloneWindows64;
- PackAB(target);
- }
- [MenuItem("ABmanager/打包安卓")]
- static void BuildABAnzhuo()
- {
- BuildTarget target = BuildTarget.Android;
- PackAB(target);
- }
- [MenuItem("ABmanager/打包ios")]
- static void BuildABIos()
- {
- BuildTarget target = BuildTarget.iOS;
- PackAB(target);
- }
- //打包具体实现
- private static void PackAB(BuildTarget buildTarget)
- {
- FABPacket();
- BuildPipeline.BuildAssetBundles(pathExit, abs.ToArray(), BuildAssetBundleOptions.None, buildTarget);
- AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
- }
- static void FABPacket()
- {
- DirectoryInfo directoryInfo = new DirectoryInfo(path);
- DirectoryInfo[] directoryInfos = directoryInfo.GetDirectories();
- //每个目录打一个AB包
- for (int i = 0; i < directoryInfos.Length; i++)
- {
- List<string> prefabs = new List<string>();
- FileInfo[] fileInfos = directoryInfos[i].GetFiles("*", SearchOption.AllDirectories);
- for (int j = 0; j < fileInfos.Length; j++)
- {
- if (fileInfos[j].Name.EndsWith(".meta"))
- {
- continue;
- }
- prefabs.Add(fileInfos[j].FullName.Replace("\\", "/"));
- AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
- }
- AssetBundleBuild prefabAB = new AssetBundleBuild
- {
- assetBundleName = directoryInfos[i].Name,
- assetNames = prefabs.Select(s => ToSelectAssetPath(s)).ToArray(),
- };
- abs.Add(prefabAB);
- }
- }
- private static string ToSelectAssetPath(string s)
- {
- string path = s.Substring(s.IndexOf("Assets/"));
- Debug.Log(path);
- return path;
- }
- }
|