MainThreadDataCache.cs 715 B

123456789101112131415161718192021222324252627
  1. // Copyright (c) 2025 TerraByte Inc.
  2. //
  3. // A new utility class that uses [InitializeOnLoad] to safely cache data
  4. // from Unity's main thread that is needed by background threads.
  5. using System.IO;
  6. using UnityEngine;
  7. using UnityEditor;
  8. using UnityEngine.Scripting;
  9. namespace Terra.Arbitrator.Services
  10. {
  11. [Preserve]
  12. [InitializeOnLoad]
  13. public static class MainThreadDataCache
  14. {
  15. /// <summary>
  16. /// A thread-safe, cached path to the project's root directory.
  17. /// </summary>
  18. public static string ProjectRoot { get; private set; }
  19. static MainThreadDataCache()
  20. {
  21. ProjectRoot = Directory.GetParent(Application.dataPath)?.FullName;
  22. }
  23. }
  24. }