1+ using UnityEditor ;
2+ using System ;
3+ using System . Reflection ;
4+ using System . IO ;
5+ /*
6+ public class WXAssetPostprocessor : AssetPostprocessor
7+ {
8+ private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths)
9+ {
10+ foreach (string asset in importedAssets)
11+ {
12+ ProcessWxPerfPluginAsset(asset);
13+ }
14+ }
15+
16+ public static bool EnableWXPostProcess = false;
17+
18+ static void ProcessWxPerfPluginAsset(string wxPerfPluginAsset)
19+ {
20+ PluginImporter importer = AssetImporter.GetAtPath(wxPerfPluginAsset) as PluginImporter;
21+ if (importer == null) return;
22+
23+ // 判断是否是wx_perf_2022.a/o文件
24+ if (wxPerfPluginAsset.Contains("wx_perf_2022.a"))
25+ {
26+ if (IsCompatibleWithUnity202203OrNewer() && EnableWXPostProcess)
27+ {
28+ #if PLATFORM_WEIXINMINIGAME
29+ if (importer.GetCompatibleWithPlatform(BuildTarget.WeixinMiniGame))
30+ #else
31+ if (importer.GetCompatibleWithPlatform(BuildTarget.WebGL))
32+ #endif
33+ {
34+ return;
35+ }
36+ EnablePluginAsset(wxPerfPluginAsset);
37+ AssetDatabase.Refresh();
38+ }
39+ else
40+ {
41+ RemovePluginAssetAllCompatibility(wxPerfPluginAsset);
42+ }
43+
44+ return;
45+ }
46+
47+
48+ // 判断是否是wx_perf_2021.a/o文件
49+ if (wxPerfPluginAsset.Contains("wx_perf_2021.a"))
50+ {
51+ if (IsCompatibleWithUnity202103To202203() && EnableWXPostProcess)
52+ {
53+ // UnityEngine.Debug.Log($"Before --- WebGL: {importer.GetCompatibleWithPlatform(BuildTarget.WebGL)}, Editor: {importer.GetCompatibleWithEditor()}");
54+ #if PLATFORM_WEIXINMINIGAME
55+ if (importer.GetCompatibleWithPlatform(BuildTarget.WeixinMiniGame))
56+ #else
57+ if (importer.GetCompatibleWithPlatform(BuildTarget.WebGL))
58+ #endif
59+ {
60+ return;
61+ }
62+
63+ EnablePluginAsset(wxPerfPluginAsset);
64+ // UnityEngine.Debug.Log($"After --- WebGL: {importer.GetCompatibleWithPlatform(BuildTarget.WebGL)}, Editor: {importer.GetCompatibleWithEditor()}");
65+
66+ AssetDatabase.Refresh();
67+ }
68+ else
69+ {
70+ RemovePluginAssetAllCompatibility(wxPerfPluginAsset);
71+ }
72+
73+ return;
74+ }
75+
76+ if (wxPerfPluginAsset.Contains("WxPerfJsBridge.jslib"))
77+ {
78+ if (EnableWXPostProcess)
79+ {
80+ // UnityEngine.Debug.Log($"Before --- WebGL: {importer.GetCompatibleWithPlatform(BuildTarget.WebGL)}, Editor: {importer.GetCompatibleWithEditor()}");
81+ #if PLATFORM_WEIXINMINIGAME
82+ if (importer.GetCompatibleWithPlatform(BuildTarget.WeixinMiniGame))
83+ #else
84+ if (importer.GetCompatibleWithPlatform(BuildTarget.WebGL))
85+ #endif
86+ {
87+ return;
88+ }
89+
90+ EnablePluginAsset(wxPerfPluginAsset);
91+ // UnityEngine.Debug.Log($"After --- WebGL: {importer.GetCompatibleWithPlatform(BuildTarget.WebGL)}, Editor: {importer.GetCompatibleWithEditor()}");
92+
93+ AssetDatabase.Refresh();
94+ }
95+ else
96+ {
97+ RemovePluginAssetAllCompatibility(wxPerfPluginAsset);
98+ }
99+
100+ return;
101+ }
102+
103+
104+
105+ }
106+
107+ static bool IsCompatibleWithUnity202203OrNewer()
108+ {
109+ #if UNITY_2022_3_OR_NEWER
110+ return true;
111+ #endif
112+ return false;
113+ }
114+
115+ static bool IsCompatibleWithUnity202103To202203()
116+ {
117+ #if UNITY_2022_3_OR_NEWER
118+ return false;
119+ #endif
120+
121+ #if !UNITY_2021_3_OR_NEWER
122+ return false;
123+ #endif
124+
125+ return true;
126+ }
127+
128+
129+ private static void RemovePluginAssetAllCompatibility(string inAssetPath)
130+ {
131+ PluginImporter importer = AssetImporter.GetAtPath(inAssetPath) as PluginImporter;
132+
133+ #if PLATFORM_WEIXINMINIGAME
134+ importer.SetCompatibleWithPlatform(BuildTarget.WeixinMiniGame, false);
135+ #else
136+ importer.SetCompatibleWithPlatform(BuildTarget.WebGL, false);
137+ #endif
138+
139+ AssetDatabase.WriteImportSettingsIfDirty(inAssetPath);
140+ }
141+
142+ private static bool IsPluginAssetValid(PluginImporter inPluginImporter)
143+ {
144+ if (inPluginImporter == null) return false;
145+
146+ if (inPluginImporter.GetCompatibleWithEditor()) return true;
147+
148+ foreach (BuildTarget target in Enum.GetValues(typeof(BuildTarget)))
149+ {
150+ if (inPluginImporter.GetCompatibleWithPlatform(target))
151+ {
152+ return true;
153+ }
154+ }
155+
156+ return false;
157+ }
158+
159+ private static void EnablePluginAsset(string inAssetPath)
160+ {
161+ PluginImporter importer = AssetImporter.GetAtPath(inAssetPath) as PluginImporter;
162+ #if PLATFORM_WEIXINMINIGAME
163+ importer.SetCompatibleWithPlatform(BuildTarget.WeixinMiniGame, EnableWXPostProcess);
164+ #else
165+ importer.SetCompatibleWithPlatform(BuildTarget.WebGL, EnableWXPostProcess);
166+ #endif
167+ AssetDatabase.WriteImportSettingsIfDirty(inAssetPath);
168+ }
169+
170+ private static int GetEnabledFlagStringIndex(string inAllText, string inTagStr)
171+ {
172+ int tagStrIdx = inAllText.IndexOf(inTagStr);
173+
174+ int enabledStrIdx = inAllText.IndexOf("enabled: ", tagStrIdx);
175+
176+ // inAllText[enabledStrIdx] == 'e'
177+ // And that is to say, inAllText[enabledStrIdx + 9] should be 0 or 1
178+ return enabledStrIdx + 9;
179+ }
180+ }
181+ */
0 commit comments