Skip to content

Commit 0a8a7fb

Browse files
committed
fix: In Unity 2020.2 or later, some fields will be not deserialized on first compilation (analyzer)
1 parent dc97d57 commit 0a8a7fb

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Plugins/CSharpCompilerSettings/CscSettingsAsset.cs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEditor;
77
using UnityEngine;
88
using LVersion = Coffee.CSharpCompilerSettings.CSharpLanguageVersion;
9+
using System.Collections.Generic;
910

1011
namespace Coffee.CSharpCompilerSettings
1112
{
@@ -247,6 +248,30 @@ public static CscSettingsAsset CreateFromJson(string json = "")
247248
}
248249
}
249250

251+
if (!serializedJson.Contains("\"m_AnalyzerPackages\":"))
252+
{
253+
var m = Regex.Match(json, "\"m_AnalyzerPackages\":\\s*(\\[[^\\]]+\\])");
254+
if (m.Success)
255+
{
256+
var packages = new List<NugetPackage>();
257+
foreach (Match match in Regex.Matches(m.Groups[1].Value, "{[^}]+}"))
258+
{
259+
packages.Add(JsonUtility.FromJson<NugetPackage>(match.Value));
260+
}
261+
262+
setting.m_AnalyzerPackages = packages.ToArray();
263+
}
264+
}
265+
266+
if (!serializedJson.Contains("\"m_AnalyzerFilter\":"))
267+
{
268+
var m = Regex.Match(json, "\"m_AnalyzerFilter\":\\s*({[^}]+})");
269+
if (m.Success)
270+
{
271+
setting.m_AnalyzerFilter = JsonUtility.FromJson<AssemblyFilter>(m.Groups[1].Value);
272+
}
273+
}
274+
250275
return setting;
251276
}
252277

0 commit comments

Comments
 (0)