Procházet zdrojové kódy

加入 Hotfix HotfixView Model ModelView 四项目的asmdef,启用Unity的自动项目生成,不再需要手动修改项目文件,方便引用Unity库以及第三方库,只需Unity编辑器界面设置即可

tanghai před 3 roky
rodič
revize
8feb87a56e

+ 93 - 3
Unity/Assets/Editor/AssetPostProcessor/OnGenerateCSProjectProcessor.cs

@@ -1,5 +1,9 @@
-using UnityEditor;
+using System;
+using UnityEditor;
 using UnityEngine;
+using System.Xml;
+using System.IO;
+using System.Text;
 
 namespace ET
 {
@@ -7,11 +11,97 @@ namespace ET
     {
         public static string OnGeneratedCSProject(string path, string content)
         {
-            if (path.EndsWith("Unity.Mono.csproj"))
+            
+            if (path.EndsWith("Unity.Hotfix.csproj"))
             {
-                return content.Replace("<OutputPath>Temp\\Bin\\Debug\\Unity.Mono\\</OutputPath>", "<OutputPath>Temp\\Bin\\Debug\\</OutputPath>");
+                content =  content.Replace("<Compile Include=\"Assets\\Hotfix\\Empty.cs\" />", string.Empty);
+                content =  content.Replace("<None Include=\"Assets\\Hotfix\\Unity.Hotfix.asmdef\" />", string.Empty);
             }
+            
+            if (path.EndsWith("Unity.HotfixView.csproj"))
+            {
+                content =  content.Replace("<Compile Include=\"Assets\\HotfixView\\Empty.cs\" />", string.Empty);
+                content =  content.Replace("<None Include=\"Assets\\HotfixView\\Unity.HotfixView.asmdef\" />", string.Empty);
+            }
+            
+            if (path.EndsWith("Unity.Model.csproj"))
+            {
+                content =  content.Replace("<Compile Include=\"Assets\\Model\\Empty.cs\" />", string.Empty);
+                content =  content.Replace("<None Include=\"Assets\\Model\\Unity.Model.asmdef\" />", string.Empty);
+            }
+            
+            if (path.EndsWith("Unity.ModelView.csproj"))
+            {
+                content =  content.Replace("<Compile Include=\"Assets\\ModelView\\Empty.cs\" />", string.Empty);
+                content =  content.Replace("<None Include=\"Assets\\ModelView\\Unity.ModelView.asmdef\" />", string.Empty);
+            }
+            
+            if (path.EndsWith("Unity.Hotfix.csproj"))
+            {
+                return GenerateCustomProject(path, content, @"Codes\Hotfix\**\*.cs");
+            }
+
+            if (path.EndsWith("Unity.HotfixView.csproj"))
+            {
+                return GenerateCustomProject(path, content, @"Codes\HotfixView\**\*.cs");
+            }
+
+            if (path.EndsWith("Unity.Model.csproj"))
+            {
+                return GenerateCustomProject(path, content, @"Codes\Model\**\*.cs");
+            }
+
+            if (path.EndsWith("Unity.ModelView.csproj"))
+            {
+                return GenerateCustomProject(path, content, @"Codes\ModelView\**\*.cs");
+            }
+            
             return content;
         }
+
+        private static string GenerateCustomProject(string path, string content, string codesPath)
+        {
+            XmlDocument doc = new XmlDocument();
+            doc.LoadXml(content);
+
+            var newDoc = doc.Clone() as XmlDocument;
+
+            var rootNode = newDoc.GetElementsByTagName("Project")[0];
+
+            var itemGroup = newDoc.CreateElement("ItemGroup", newDoc.DocumentElement.NamespaceURI);
+            var compile = newDoc.CreateElement("Compile", newDoc.DocumentElement.NamespaceURI);
+
+            compile.SetAttribute("Include", codesPath);
+            itemGroup.AppendChild(compile);
+
+            var projectReference = newDoc.CreateElement("ProjectReference", newDoc.DocumentElement.NamespaceURI);
+            projectReference.SetAttribute("Include", @"..\Share\Analyzer\Share.Analyzer.csproj");
+            projectReference.SetAttribute("OutputItemType", @"Analyzer");
+            projectReference.SetAttribute("ReferenceOutputAssembly", @"false");
+
+            var project = newDoc.CreateElement("Project", newDoc.DocumentElement.NamespaceURI);
+            project.InnerText = @"{d1f2986b-b296-4a2d-8f12-be9f470014c3}";
+            projectReference.AppendChild(project);
+
+            var name = newDoc.CreateElement("Name", newDoc.DocumentElement.NamespaceURI);
+            name.InnerText = "Analyzer";
+            projectReference.AppendChild(project);
+
+            itemGroup.AppendChild(projectReference);
+
+            rootNode.AppendChild(itemGroup);
+
+            using (StringWriter sw = new StringWriter())
+            {
+
+                using (XmlTextWriter tx = new XmlTextWriter(sw))
+                {
+                    tx.Formatting = Formatting.Indented;
+                    newDoc.WriteTo(tx);
+                    tx.Flush();
+                    return sw.GetStringBuilder().ToString();
+                }
+            }
+        }
     }
 }

+ 8 - 0
Unity/Assets/Hotfix.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 516985cfbade0c4458173ec83193b0cb
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/Hotfix/Empty.cs

@@ -0,0 +1 @@
+//用于自动生成工程项目的占位脚本,请勿移除或修改

+ 11 - 0
Unity/Assets/Hotfix/Empty.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8c7b59b119e946e8bcbc3783c8c355c6
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 20 - 0
Unity/Assets/Hotfix/Unity.Hotfix.asmdef

@@ -0,0 +1,20 @@
+{
+    "name": "Unity.Hotfix",
+    "rootNamespace": "ET",
+    "references": [
+        "Unity.Model",
+        "Unity.ThirdParty",
+        "Unity.Mono"
+    ],
+    "includePlatforms": [
+        "Editor"
+    ],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Unity/Assets/Hotfix/Unity.Hotfix.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: dd49a6aee98625147b438c1f3cc12621
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Unity/Assets/HotfixView.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: efde22fdd5457074db1d9c790adc391e
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/HotfixView/Empty.cs

@@ -0,0 +1 @@
+//用于自动生成工程项目的占位脚本,请勿移除或修改

+ 11 - 0
Unity/Assets/HotfixView/Empty.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 4d37f62f6e5d48d28d7e4a8364391ca5
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 22 - 0
Unity/Assets/HotfixView/Unity.HotfixView.asmdef

@@ -0,0 +1,22 @@
+{
+    "name": "Unity.HotfixView",
+    "rootNamespace": "ET",
+    "references": [
+        "Unity.Mono",
+        "Unity.ThirdParty",
+        "Unity.Model",
+        "Unity.Hotfix",
+        "Unity.ModelView"
+    ],
+    "includePlatforms": [
+        "Editor"
+    ],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Unity/Assets/HotfixView/Unity.HotfixView.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 98144a3fda0534746a737325b7935c1d
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Unity/Assets/Model.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 362839cefe2ae724d8bc02709d095eb8
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/Model/Empty.cs

@@ -0,0 +1 @@
+//用于自动生成工程项目的占位脚本,请勿移除或修改

+ 11 - 0
Unity/Assets/Model/Empty.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ec3187e786484b65b55340bb73f34d68
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 19 - 0
Unity/Assets/Model/Unity.Model.asmdef

@@ -0,0 +1,19 @@
+{
+    "name": "Unity.Model",
+    "rootNamespace": "ET",
+    "references": [
+        "Unity.ThirdParty",
+        "Unity.Mono"
+    ],
+    "includePlatforms": [
+        "Editor"
+    ],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Unity/Assets/Model/Unity.Model.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 61be00357cd206e42a4338fff3f5d273
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 8 - 0
Unity/Assets/ModelView.meta

@@ -0,0 +1,8 @@
+fileFormatVersion: 2
+guid: 6a7bb529db4d3394d88e71b685cf7d4f
+folderAsset: yes
+DefaultImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 1 - 0
Unity/Assets/ModelView/Empty.cs

@@ -0,0 +1 @@
+//用于自动生成工程项目的占位脚本,请勿移除或修改

+ 11 - 0
Unity/Assets/ModelView/Empty.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 08c022786ae2400099625ccd862e310e
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

+ 20 - 0
Unity/Assets/ModelView/Unity.ModelView.asmdef

@@ -0,0 +1,20 @@
+{
+    "name": "Unity.ModelView",
+    "rootNamespace": "ET",
+    "references": [
+        "Unity.Model",
+        "Unity.Mono",
+        "Unity.ThirdParty"
+    ],
+    "includePlatforms": [
+        "Editor"
+    ],
+    "excludePlatforms": [],
+    "allowUnsafeCode": true,
+    "overrideReferences": false,
+    "precompiledReferences": [],
+    "autoReferenced": true,
+    "defineConstraints": [],
+    "versionDefines": [],
+    "noEngineReferences": false
+}

+ 7 - 0
Unity/Assets/ModelView/Unity.ModelView.asmdef.meta

@@ -0,0 +1,7 @@
+fileFormatVersion: 2
+guid: 1c9695a401c816a4f8fa3550926b6cfc
+AssemblyDefinitionImporter:
+  externalObjects: {}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: 

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 2 - 12
Unity/Unity.Hotfix.csproj


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 3 - 4
Unity/Unity.HotfixView.csproj


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 3 - 13
Unity/Unity.Model.csproj


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 3 - 4
Unity/Unity.ModelView.csproj


Některé soubory nejsou zobrazeny, neboť je v těchto rozdílových datech změněno mnoho souborů