diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2.meta b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2.meta deleted file mode 100644 index f658740..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: 58608cf35fb60a246963a164d31a628a -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs deleted file mode 100644 index 85ac077..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs +++ /dev/null @@ -1,144 +0,0 @@ -#if UNITY_EDITOR -#if UNITY_2021_2 -using System; -using System.Threading; -using System.Threading.Tasks; -using System.Collections.Concurrent; -using System.Collections.Generic; -using System.IO; -using UnityEngine; -using UnityEditor; -using UnityEditor.Compilation; - -namespace FinalFrame.EditorTool { - - // 监控修改的代码文件 - // 编译Runtime DLL - public class DirtyScriptsCompilationTool { - - const string SHORTCUT_KEY = "%_T"; - - static System.Diagnostics.Stopwatch sw; - - static List dirtyFiles; - - [InitializeOnLoadMethod] - static void Setup() { - - dirtyFiles = new List(); - - EditorCompilationFileWatcher watcher = new EditorCompilationFileWatcher(); - watcher.Init(Application.dataPath); - watcher.OnScriptDirtyHandle += OnScriptDirty; - - } - - static void OnScriptDirty(string dirtyScriptFilePath) { - if (!dirtyFiles.Contains(dirtyScriptFilePath)) { - dirtyFiles.Add(dirtyScriptFilePath); - } - } - - [MenuItem(MENU_ITEM_COLLECTION.EDITOR_TOOL_PATH + nameof(DirtyScriptsCompilationTool) + "/脏脚本编译 " + SHORTCUT_KEY)] - public static void Compile() { - - sw = new System.Diagnostics.Stopwatch(); - sw.Start(); - - // 1. 缓存所有修改且未编译的代码文件 - // this.dirtyFiles - - // 2. 获取所有Runtime程序集 - var asms = CompilationPipeline.GetAssemblies(); - var pathToAsmDic = new Dictionary(); - for (int i = 0; i < asms.Length; i += 1) { - var asm = asms[i]; - for (int j = 0; j < asm.sourceFiles.Length; j += 1) { - var file = asm.sourceFiles[j]; - string dirName = Path.GetDirectoryName(file); - string fileName = Path.GetFileName(file); - string path = Path.Combine(dirName, fileName); - pathToAsmDic.Add(path, asm); - } - } - - // 3. 查找所有有改动的程序集 - List dirtyAsms = new List(); - var arr = dirtyFiles.ToArray(); - for (int i = 0; i < arr.Length; i += 1) { - var file = arr[i]; - bool hasAsm = pathToAsmDic.TryGetValue(file, out Assembly tarAsm); - if (!hasAsm) { - Debug.LogWarning($"该文件 {file} 暂不存在于程序集内"); - } else { - if (!dirtyAsms.Contains(tarAsm)) { - dirtyAsms.Add(tarAsm); - } - } - } - - // 4. 编译 - int waitCompileCount = dirtyAsms.Count; - if (waitCompileCount == 0) { - Debug.Log("无程序集需要编译"); - return; - } - - RecurCompile(dirtyAsms, waitCompileCount); - - } - - static void RecurCompile(List dirtyAsms, int waitCompileCount, int index = 0) { - - if (index < dirtyAsms.Count) { - - var asm = dirtyAsms[index]; - - AssemblyBuilder builder = new AssemblyBuilder(asm.outputPath, asm.sourceFiles); - builder.additionalDefines = asm.defines; - builder.compilerOptions = asm.compilerOptions; - builder.excludeReferences = new string[] { asm.outputPath }; - builder.additionalReferences = asm.compiledAssemblyReferences; - - builder.buildFinished += (dllFilePath, arr) => { - - bool hasErr = false; - foreach (var msg in arr) { - if (msg.type == CompilerMessageType.Error) { - Debug.LogError(msg.message); - hasErr = true; - } else if (msg.type == CompilerMessageType.Warning) { - Debug.LogWarning(msg.message); - } else { - Debug.Log(msg.message); - } - } - if (hasErr) { - Debug.LogError($"程序集{dllFilePath}编译失败"); - return; - } - - waitCompileCount -= 1; - Debug.Log($"程序集{dllFilePath}编译成功"); - if (waitCompileCount == 0) { - dirtyFiles.Clear(); - sw.Stop(); - Debug.Log($"[DSC编译完成]总程序集数:{dirtyAsms.Count}, 耗时:{sw.ElapsedMilliseconds}ms"); - } else { - index += 1; - RecurCompile(dirtyAsms, waitCompileCount, index); - } - - }; - - builder.Build(); - - } - } - - } - -} - -#endif -#endif \ No newline at end of file diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs.meta b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs.meta deleted file mode 100644 index e6fb730..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/DirtyScriptsCompilationTool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8da130701538a954ea5f6854e97c09d1 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher.meta b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher.meta deleted file mode 100644 index 916df78..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher.meta +++ /dev/null @@ -1,8 +0,0 @@ -fileFormatVersion: 2 -guid: f0262cc1f7a807a44b77cd1fb20873c9 -folderAsset: yes -DefaultImporter: - externalObjects: {} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs deleted file mode 100644 index 28fa571..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs +++ /dev/null @@ -1,100 +0,0 @@ -#if UNITY_EDITOR -#if UNITY_2021_2 -using System; -using System.Collections.Generic; -using System.IO; -using UnityEngine; - -namespace FinalFrame.EditorTool { - - // ---- 用于监控文件变化 ---- - [Serializable] - public class EditorCompilationFileWatcher { - - FileSystemWatcher watcher; - - public delegate void OnScriptDirty(string scriptFilePath); - public event OnScriptDirty OnScriptDirtyHandle; - - public void Init(string watchDir) { - watcher = new FileSystemWatcher(); - watcher.Path = watchDir; - watcher.Filter = "*.cs"; - watcher.IncludeSubdirectories = true; - watcher.NotifyFilter = NotifyFilters.LastWrite; - watcher.EnableRaisingEvents = true; - watcher.Changed += FileChanged; - } - - public void TearDown() { - if (watcher != null) { - watcher.Changed -= FileChanged; - } - } - - void FileChanged(object sender, FileSystemEventArgs e) { - - try { - - /* 等待 Unity 修复后再使用 - string dirName = Path.GetDirectoryName(e.FullPath); - string fileName = Path.GetFileName(e.FullPath); - string path = Path.Combine(dirName, fileName); - int index = path.IndexOf("Assets"); - path = path.Substring(index); - */ - - // 替代实现方案 - string path = FindFileWithExt(watcher.Path, e.Name.Replace(".cs", ""), "*.cs"); - int index = path.IndexOf("Assets"); - path = path.Substring(index); - if (OnScriptDirtyHandle != null) { - OnScriptDirtyHandle.Invoke(path); - } else { - Debug.LogWarning("OnScriptDirtyHandle 未注册"); - } - - } catch(Exception err) { - - Debug.LogError(err.ToString()); - - } - - } - - // 找到某个文件 - static string FindFileWithExt(string rootPath, string fileName, string ext) { - List all = FindAllFileWithExt(rootPath, ext); - return all.Find(value => value.Contains(fileName + ext.TrimStart('*'))); - } - - // 递归 - /// - /// ext 参数格式举例:"*.cs" - /// - static List FindAllFileWithExt(string rootPath, string ext) { - - List fileList = new List(); - - DirectoryInfo directoryInfo = new DirectoryInfo(rootPath); - FileInfo[] allFiles = directoryInfo.GetFiles(ext); - for (int i = 0; i < allFiles.Length; i += 1) { - var file = allFiles[i]; - fileList.Add(file.FullName); - } - - DirectoryInfo[] childrenDirs = directoryInfo.GetDirectories(); - for (int i = 0; i < childrenDirs.Length; i += 1) { - var dir = childrenDirs[i]; - fileList.AddRange(FindAllFileWithExt(dir.FullName, ext)); - } - - return fileList; - - } - - } - -} -#endif -#endif \ No newline at end of file diff --git a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs.meta b/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs.meta deleted file mode 100644 index d001e0a..0000000 --- a/Assets/com.frame.unitydirtycompiler/Editor/V2021.2/FileWatcher/EditorCompilationFileWatcher.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 8442e514899028841b87e5647ddf49d5 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/com.frame.unitydirtycompiler/package.json b/Assets/com.frame.unitydirtycompiler/package.json index 9e41c71..0edb271 100644 --- a/Assets/com.frame.unitydirtycompiler/package.json +++ b/Assets/com.frame.unitydirtycompiler/package.json @@ -1,6 +1,6 @@ { "name": "com.frame.unitydirtycompiler", - "version": "0.0.1", + "version": "0.0.2", "description": "Unity 脏脚本编译工具", "displayName": "JackFrame.UnityDirtyCompiler", "unity": "2019.4",