|
|
@@ -1,166 +1,187 @@
|
|
|
-using System.IO;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.IO;
|
|
|
using Model;
|
|
|
using UnityEditor;
|
|
|
+using UnityEngine;
|
|
|
|
|
|
namespace MyEditor
|
|
|
{
|
|
|
- public class BuildEditor : EditorWindow
|
|
|
+ public class BundleInfo
|
|
|
{
|
|
|
- private static BuildOptions option = BuildOptions.Development | BuildOptions.AllowDebugging;
|
|
|
- private const string relativeDirPrefix = "../Release";
|
|
|
-
|
|
|
- public static string abFolderAndroid = "../Release/Android/StreamingAssets/";
|
|
|
-
|
|
|
- public static string abFolderPC = "../Release/PC/StreamingAssets/";
|
|
|
+ public List<string> ParentPaths = new List<string>();
|
|
|
+ }
|
|
|
|
|
|
- public static string abFolderIOS = "../Release/IOS/StreamingAssets/";
|
|
|
+ public enum PlatformType
|
|
|
+ {
|
|
|
+ PC,
|
|
|
+ Android,
|
|
|
+ IOS,
|
|
|
+ }
|
|
|
|
|
|
- [MenuItem("Tools/编译")]
|
|
|
- public static void BuildHotfix()
|
|
|
- {
|
|
|
- System.Diagnostics.Process process = new System.Diagnostics.Process();
|
|
|
- string unityDir = System.Environment.GetEnvironmentVariable("Unity");
|
|
|
- if (string.IsNullOrEmpty(unityDir))
|
|
|
- {
|
|
|
- Log.Error("没有设置Unity环境变量!");
|
|
|
- return;
|
|
|
- }
|
|
|
- process.StartInfo.FileName = $@"{unityDir}\Editor\Data\MonoBleedingEdge\bin\mono.exe";
|
|
|
- process.StartInfo.Arguments = $@"{unityDir}\Editor\Data\MonoBleedingEdge\lib\mono\xbuild\14.0\bin\xbuild.exe .\Hotfix\Unity.Hotfix.csproj";
|
|
|
- process.StartInfo.UseShellExecute = false;
|
|
|
- process.StartInfo.WorkingDirectory = @".\";
|
|
|
- process.StartInfo.RedirectStandardOutput = true;
|
|
|
- process.StartInfo.RedirectStandardError = true;
|
|
|
- process.Start();
|
|
|
- string info = process.StandardOutput.ReadToEnd();
|
|
|
- process.WaitForExit();
|
|
|
- process.Close();
|
|
|
- Log.Info(info);
|
|
|
- }
|
|
|
+ public class BuildEditor : EditorWindow
|
|
|
+ {
|
|
|
+ private readonly Dictionary<string, BundleInfo> dictionary = new Dictionary<string, BundleInfo>();
|
|
|
|
|
|
- [MenuItem("Tools/打开文件服务器")]
|
|
|
- public static void OpenFileServer()
|
|
|
- {
|
|
|
- string currentDir = System.Environment.CurrentDirectory;
|
|
|
- string path = Path.Combine(currentDir, @"..\FileServer\");
|
|
|
- System.Diagnostics.Process process = new System.Diagnostics.Process();
|
|
|
- process.StartInfo.FileName = "FileServer.exe";
|
|
|
- process.StartInfo.WorkingDirectory = path;
|
|
|
- process.StartInfo.CreateNoWindow = true;
|
|
|
- process.Start();
|
|
|
- }
|
|
|
+ private PlatformType platformType;
|
|
|
+ private bool isBuildExe;
|
|
|
+ private BuildOptions buildOptions;
|
|
|
|
|
|
- [MenuItem("Tools/打包/PC打包")]
|
|
|
- public static void BuildPC()
|
|
|
+ [MenuItem("Tools/打包工具")]
|
|
|
+ public static void ShowWindow()
|
|
|
{
|
|
|
- BuildAssetBundlesPC();
|
|
|
-
|
|
|
- string[] levels2 = {
|
|
|
- "Assets/Scenes/Init.unity",
|
|
|
- };
|
|
|
- BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.exe", BuildTarget.StandaloneWindows, option);
|
|
|
- Log.Info("打包完成");
|
|
|
+ GetWindow(typeof(BuildEditor));
|
|
|
}
|
|
|
|
|
|
- [MenuItem("Tools/打包/Android打包")]
|
|
|
- public static void BuildAndroid()
|
|
|
+ private void OnGUI()
|
|
|
{
|
|
|
- BuildAssetBundlesAndroid();
|
|
|
+ if (GUILayout.Button("标记"))
|
|
|
+ {
|
|
|
+ SetPackingTagAndAssetBundle();
|
|
|
+ }
|
|
|
|
|
|
- string[] levels2 = {
|
|
|
- "Assets/Scenes/Init.unity",
|
|
|
- };
|
|
|
- BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.apk", BuildTarget.Android, option);
|
|
|
- Log.Info("打包完成");
|
|
|
- }
|
|
|
+ EditorGUILayout.BeginHorizontal();
|
|
|
+ this.platformType = (PlatformType)EditorGUILayout.EnumPopup(platformType);
|
|
|
+ this.isBuildExe = EditorGUILayout.Toggle("是否打包EXE: ", this.isBuildExe);
|
|
|
+ EditorGUILayout.EndHorizontal();
|
|
|
|
|
|
- [MenuItem("Tools/打包/Android打包APK")]
|
|
|
- public static void BuildAPK()
|
|
|
- {
|
|
|
- string[] levels2 = {
|
|
|
- "Assets/Scenes/Init.unity",
|
|
|
- };
|
|
|
- BuildPipeline.BuildPlayer(levels2, $"{relativeDirPrefix}/et.apk", BuildTarget.Android, option);
|
|
|
- Log.Info("打包APK完成");
|
|
|
- }
|
|
|
+ this.buildOptions = (BuildOptions)EditorGUILayout.EnumMaskField("BuildOptions(可多选): ", this.buildOptions);
|
|
|
|
|
|
- [MenuItem("Tools/打包/PC生成资源包")]
|
|
|
- public static void BuildAssetBundlesPC()
|
|
|
- {
|
|
|
- if (!Directory.Exists(abFolderPC))
|
|
|
+ if (GUILayout.Button("开始打包"))
|
|
|
{
|
|
|
- Directory.CreateDirectory(abFolderPC);
|
|
|
+ BuildHelper.Build(this.platformType, BuildOptions.None, this.isBuildExe);
|
|
|
}
|
|
|
- BuildPipeline.BuildAssetBundles(abFolderPC, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows);
|
|
|
-
|
|
|
- GenerateVersionInfo(abFolderPC);
|
|
|
- Log.Info("生成资源包完成");
|
|
|
}
|
|
|
|
|
|
- [MenuItem("Tools/打包/Android生成资源包")]
|
|
|
- public static void BuildAssetBundlesAndroid()
|
|
|
+ private void SetPackingTagAndAssetBundle()
|
|
|
{
|
|
|
- if (!Directory.Exists(abFolderAndroid))
|
|
|
- {
|
|
|
- Directory.CreateDirectory(abFolderAndroid);
|
|
|
- }
|
|
|
- BuildPipeline.BuildAssetBundles(abFolderAndroid, BuildAssetBundleOptions.None, BuildTarget.Android);
|
|
|
-
|
|
|
- GenerateVersionInfo(abFolderAndroid);
|
|
|
- Log.Info("生成资源包完成");
|
|
|
+ ClearPackingTagAndAssetBundle();
|
|
|
+
|
|
|
+ SetOneDirPackingTagAndAssetBundle("Assets/Bundles/");
|
|
|
}
|
|
|
|
|
|
- [MenuItem("Tools/打包/IOS生成资源包")]
|
|
|
- public static void BuildAssetBundlesIOS()
|
|
|
+ private void SetOneDirPackingTagAndAssetBundle(string dir)
|
|
|
{
|
|
|
- if (!Directory.Exists(abFolderIOS))
|
|
|
+ this.dictionary.Clear();
|
|
|
+ List<string> paths = EditorResHelper.GetPrefabsAndScenes(dir);
|
|
|
+
|
|
|
+ foreach (string path in paths)
|
|
|
{
|
|
|
- Directory.CreateDirectory(abFolderIOS);
|
|
|
- }
|
|
|
- BuildPipeline.BuildAssetBundles(abFolderIOS, BuildAssetBundleOptions.None, BuildTarget.iOS);
|
|
|
+ string path1 = path.Replace('\\', '/');
|
|
|
+ UnityEngine.Object go = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(path1);
|
|
|
+ AssetImporter importer = AssetImporter.GetAtPath(path1);
|
|
|
+ if (importer == null || go == null)
|
|
|
+ {
|
|
|
+ Log.Error("error: " + path1);
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ importer.assetBundleName = $"{go.name}.unity3d";
|
|
|
|
|
|
- GenerateVersionInfo(abFolderIOS);
|
|
|
- Log.Info("生成资源包完成");
|
|
|
+ UnityEngine.Object[] objects = EditorUtility.CollectDependencies(new[] { go });
|
|
|
+ foreach (UnityEngine.Object o in objects)
|
|
|
+ {
|
|
|
+ string pt = AssetDatabase.GetAssetPath(o);
|
|
|
+ string extension = Path.GetExtension(pt);
|
|
|
+ if (extension == ".cs" || extension == ".dll")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (pt.Contains("Resources"))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (pt == path1)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 不存在则记录下来
|
|
|
+ if (!this.dictionary.ContainsKey(pt))
|
|
|
+ {
|
|
|
+ Log.Info($"{path1}----{pt}");
|
|
|
+ BundleInfo bundleInfo = new BundleInfo();
|
|
|
+ bundleInfo.ParentPaths.Add(path1);
|
|
|
+ this.dictionary.Add(pt, bundleInfo);
|
|
|
+
|
|
|
+ AssetImporter importer3 = AssetImporter.GetAtPath(pt);
|
|
|
+ TextureImporter textureImporter3 = importer3 as TextureImporter;
|
|
|
+ if (textureImporter3 != null)
|
|
|
+ {
|
|
|
+ textureImporter3.spritePackingTag = go.name;
|
|
|
+ }
|
|
|
+
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 依赖的父亲不一样
|
|
|
+ BundleInfo info = this.dictionary[pt];
|
|
|
+ if (info.ParentPaths.Contains(path1))
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ info.ParentPaths.Add(path1);
|
|
|
+
|
|
|
+ AssetImporter importer2 = AssetImporter.GetAtPath(pt);
|
|
|
+ if (importer2 == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (importer2.assetBundleName != "")
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ importer2.assetBundleName = $"share.unity3d";
|
|
|
+ Log.Warning($"{importer2.assetBundleName}: {pt} {info.ParentPaths.ListToString()}");
|
|
|
+
|
|
|
+ TextureImporter textureImporter = importer2 as TextureImporter;
|
|
|
+ if (textureImporter != null)
|
|
|
+ {
|
|
|
+ textureImporter.spritePackingTag = $"share";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private static void GenerateVersionInfo(string dir)
|
|
|
+ private static void ClearPackingTagAndAssetBundle()
|
|
|
{
|
|
|
- VersionConfig versionProto = new VersionConfig();
|
|
|
- GenerateVersionInfo3(dir, versionProto, "");
|
|
|
-
|
|
|
- using (FileStream fileStream = new FileStream($"{dir}/Version.txt", FileMode.Create))
|
|
|
+ List<string> bundlePaths = EditorResHelper.GetAllResourcePath("Assets/Bundles", true);
|
|
|
+ foreach (string bundlePath in bundlePaths)
|
|
|
{
|
|
|
- byte[] bytes = MongoHelper.ToJson(versionProto).ToByteArray();
|
|
|
- fileStream.Write(bytes, 0, bytes.Length);
|
|
|
+ AssetImporter importer = AssetImporter.GetAtPath(bundlePath);
|
|
|
+ if (importer == null)
|
|
|
+ {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ //Log.Info(bundlePath);
|
|
|
+ importer.assetBundleName = "";
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- private static void GenerateVersionInfo3(string dir, VersionConfig versionProto, string relativePath)
|
|
|
- {
|
|
|
- foreach (string file in Directory.GetFiles(dir))
|
|
|
+ List<string> paths = EditorResHelper.GetAllResourcePath("Assets/Res", true);
|
|
|
+ foreach (string path in paths)
|
|
|
{
|
|
|
- if (file.EndsWith(".manifest"))
|
|
|
+ string extendName = Path.GetExtension(path);
|
|
|
+ if (extendName == ".cs")
|
|
|
{
|
|
|
continue;
|
|
|
}
|
|
|
- string md5 = MD5Helper.FileMD5(file);
|
|
|
- FileInfo fi = new FileInfo(file);
|
|
|
- long size = fi.Length;
|
|
|
- string filePath = relativePath == "" ? fi.Name : $"{relativePath}/{fi.Name}";
|
|
|
|
|
|
- versionProto.FileVersionInfos.Add(new FileVersionInfo
|
|
|
+ AssetImporter importer = AssetImporter.GetAtPath(path);
|
|
|
+ if (importer == null)
|
|
|
{
|
|
|
- File = filePath,
|
|
|
- MD5 = md5,
|
|
|
- Size = size,
|
|
|
- });
|
|
|
- }
|
|
|
+ continue;
|
|
|
+ }
|
|
|
|
|
|
- foreach (string directory in Directory.GetDirectories(dir))
|
|
|
- {
|
|
|
- DirectoryInfo dinfo = new DirectoryInfo(directory);
|
|
|
- string rel = relativePath == "" ? dinfo.Name : $"{relativePath}/{dinfo.Name}";
|
|
|
- GenerateVersionInfo3($"{dir}/{dinfo.Name}", versionProto, rel);
|
|
|
+ //Log.Info(path);
|
|
|
+
|
|
|
+ importer.assetBundleName = "";
|
|
|
+
|
|
|
+ TextureImporter textureImporter = importer as TextureImporter;
|
|
|
+ if (textureImporter != null)
|
|
|
+ {
|
|
|
+ textureImporter.spritePackingTag = "";
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|