handzlikchris / handzlikchris/FastScriptReload
Improvement: FindFileOrThrow for dotnet tools caching result between project sessions
- Dominant language
- C#
- Stars
- 2.2k
- Forks
- 167
- PR merge metrics
- No merged PRs in 30d
Description
Hi, handzlikchris. Thank you for your excellent work.
I noticed that every time project opens, FSR always search deeply into Unity installation path for dotnet tools, which spends seconds to complete. Because of storing in `SessionState`, first-time project launch can't benefit from it.
In my opinion, utilize `EditorPrefs` with `unityVersion` could be better.
Here is my snippet for this:
```csharp
private static string FindFileOrThrow(string fileName)
{
var cacheKey = $"FSR:FilePath_{fileName}:{Application.unityVersion}";
var result = EditorPrefs.GetString(cacheKey, null);
if (result != null && !File.Exists(result))
{
EditorPrefs.DeleteKey(cacheKey);
result = null;
}
if (result == null)
{
result = Directory
.GetFiles(ApplicationContentsPath, fileName, SearchOption.AllDirectories)
.FirstOrDefault();
if (result == null)
{
throw new Exception($"Unable to find '{fileName}', make sure Editor version supports it. You can also add preprocessor directive 'FastScriptReload_CompileViaMCS' which will use Mono compiler instead");
}
}
EditorPrefs.SetString(cacheKey, result);
return result;
}
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.