From d910af589d7d1a1622cb3acb5b799774113f29d7 Mon Sep 17 00:00:00 2001
From: Y-way <young_way2007@126.com>
Date: Mon, 10 Mar 2025 15:22:44 +0800
Subject: [PATCH 1/2] Update MacrosProcessor.cs
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

修正YooAsset相关宏在引用库不能生效的问题.
---
 .../Editor/Assembly/MacrosProcessor.cs        | 113 +++++++++++++++++-
 1 file changed, 109 insertions(+), 4 deletions(-)

diff --git a/Assets/YooAsset/Editor/Assembly/MacrosProcessor.cs b/Assets/YooAsset/Editor/Assembly/MacrosProcessor.cs
index 3ad49de6..17e24a28 100644
--- a/Assets/YooAsset/Editor/Assembly/MacrosProcessor.cs
+++ b/Assets/YooAsset/Editor/Assembly/MacrosProcessor.cs
@@ -1,18 +1,20 @@
 using System.Collections.Generic;
 using System.IO;
 using System.Linq;
+using System.Text;
 using System.Xml;
 using UnityEditor;
+using UnityEditor.PackageManager;
+using UnityEngine;
+using static UnityEditor.PlayerSettings;
 
 namespace YooAsset.Editor
 {
     [InitializeOnLoad]
     public class MacrosProcessor : AssetPostprocessor
     {
-        static MacrosProcessor()
-        {
-        }
-
+        // csc.rsp 文件路径
+        private static string RspFilePath => Path.Combine(Application.dataPath, "csc.rsp");
         /// <summary>
         /// YooAsset版本宏定义
         /// </summary>
@@ -23,6 +25,12 @@ namespace YooAsset.Editor
             "YOO_ASSET_2_3_OR_NEWER",
         };
 
+        static MacrosProcessor()
+        {
+            //添加到全局宏定义
+            UpdateRspFile(YooAssetMacros);
+        }
+
         static string OnGeneratedCSProject(string path, string content)
         {
             XmlDocument xmlDoc = new XmlDocument();
@@ -105,5 +113,102 @@ namespace YooAsset.Editor
 
             return false;
         }
+        /// <summary>
+        /// 更新csc.rsp文件
+        /// </summary>
+        /// <param name="macrosToAdd"></param>
+        /// <param name="macrosToRemove"></param>
+        private static void UpdateRspFile(List<string> macrosToAdd = null, List<string> macrosToRemove = null)
+        {
+            HashSet<string> existingDefines = new HashSet<string>();
+            List<string> otherLines = new List<string>();
+            // 1. 读取现有内容
+            ReadRspFile(ref existingDefines, ref otherLines);
+            // 2. 添加新宏
+            if (macrosToAdd != null && macrosToAdd.Count > 0)
+            {
+                macrosToAdd.ForEach(x =>
+                {
+                    if (existingDefines.Contains(x) == false)
+                        existingDefines.Add(x);
+                });
+            }
+            // 3. 移除指定宏
+            if (macrosToRemove != null && macrosToRemove.Count > 0)
+            {
+                macrosToRemove.ForEach(x =>
+                {
+                    existingDefines.Remove(x);
+                });
+            }
+            // 4. 重新生成内容
+            WriteRspFile(existingDefines, otherLines);
+            // 5. 刷新AssetDatabase
+            AssetDatabase.Refresh();
+            EditorUtility.RequestScriptReload();
+        }
+        /// <summary>
+        /// 读取csc.rsp文件,返回宏定义和其他行
+        /// </summary>
+        /// <param name="defines"></param>
+        /// <param name="others"></param>
+        private static void ReadRspFile(ref HashSet<string> defines, ref List<string> others)
+        {
+            if (defines == null)
+            {
+                defines = new HashSet<string>();
+            }
+
+            if (others == null)
+            {
+                others = new List<string>();
+            }
+
+            if (File.Exists(RspFilePath) == false)
+            {
+                return;
+            }
+
+            foreach (string line in File.ReadAllLines(RspFilePath))
+            {
+                if (line.StartsWith("-define:"))
+                {
+                    string[] parts = line.Split(new[] { ':' }, 2);
+                    if (parts.Length == 2)
+                    {
+                        defines.Add(parts[1].Trim());
+                    }
+                }
+                else
+                {
+                    others.Add(line);
+                }
+            }
+        }
+        /// <summary>
+        /// 重写入出csc.rsp文件
+        /// </summary>
+        /// <param name="defines"></param>
+        /// <param name="others"></param>
+        private static void WriteRspFile(HashSet<string> defines, List<string> others)
+        {
+
+            StringBuilder sb = new StringBuilder();
+            if (others != null && others.Count > 0)
+            {
+                others.ForEach(o => sb.AppendLine(o));
+            }
+
+            if (defines != null && defines.Count > 0)
+            {
+                foreach (string define in defines)
+                {
+                    sb.AppendLine($"-define:{define}");
+                }
+            }
+
+            File.WriteAllText(RspFilePath, sb.ToString());
+        }
+
     }
 }

From bdcf95384f55dcd8dd36804adfd35c1b99b2f7f6 Mon Sep 17 00:00:00 2001
From: Y-way <young_way2007@126.com>
Date: Mon, 10 Mar 2025 16:13:18 +0800
Subject: [PATCH 2/2] Update .gitignore

---
 .gitignore | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index b38cfe63..9764a0ca 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,4 +72,6 @@ sysinfo.txt
 # Crashlytics generated file
 crashlytics-build.properties
 
-*.vsconfig
\ No newline at end of file
+*.vsconfig
+Assets/csc.rsp
+Assets/csc.rsp.meta