Skip to content

Commit de1c776

Browse files
april-roszkowskiEvergreen
authored andcommitted
[UUM-137272] Change file access strategy in Shader Graph importer
1 parent 155676a commit de1c776

2 files changed

Lines changed: 12 additions & 3 deletions

File tree

Packages/com.unity.shadergraph/Editor/Importers/ShaderGraphImporter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ public override void OnImportAsset(AssetImportContext ctx)
235235
AssetCollection assetCollection = new AssetCollection();
236236
MinimalGraphData.GatherMinimalDependenciesFromFile(assetPath, assetCollection);
237237

238-
var textGraph = File.ReadAllText(path, Encoding.UTF8);
238+
var textGraph = FileUtilities.ReadAllTextUTF8(assetPath);
239239
var graph = new GraphData
240240
{
241241
messageManager = new MessageManager(),

Packages/com.unity.shadergraph/Editor/Util/FileUtilities.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@ namespace UnityEditor.ShaderGraph
99
{
1010
static class FileUtilities
1111
{
12+
public static string ReadAllTextUTF8(string path)
13+
{
14+
ReadOnlySpan<byte> contents = FileUtil.ReadAllBytes(path);
15+
ReadOnlySpan<byte> bom = Encoding.UTF8.Preamble;
16+
if (contents.StartsWith(bom))
17+
contents = contents[bom.Length..];
18+
return Encoding.UTF8.GetString(contents);
19+
}
20+
1221
// if successfully written to disk, returns the serialized file contents as a string
1322
// on failure, returns null
1423
public static string WriteShaderGraphToDisk(string path, GraphData data)
@@ -74,7 +83,7 @@ public static string SafeReadAllText(string assetPath)
7483
string result = null;
7584
try
7685
{
77-
result = File.ReadAllText(FileUtil.PathToAbsolutePath(assetPath), Encoding.UTF8);
86+
result = ReadAllTextUTF8(assetPath);
7887
}
7988
catch
8089
{
@@ -87,7 +96,7 @@ internal static bool TryReadGraphDataFromDisk(string path, out GraphData graph)
8796
{
8897
try
8998
{
90-
var textGraph = File.ReadAllText(FileUtil.PathToAbsolutePath(path), Encoding.UTF8);
99+
var textGraph = ReadAllTextUTF8(path);
91100
graph = new GraphData
92101
{
93102
messageManager = new Graphing.Util.MessageManager(),

0 commit comments

Comments
 (0)