Configuration.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.IO;
  4. using UnityEngine;
  5. namespace Assets.StreetLight
  6. {
  7. public sealed class Configuration
  8. {
  9. private string homographyFilePath;
  10. /// <summary>
  11. /// The file path to the csv file containing the homography for mapping world coodrinates to Unity coordinates.
  12. /// </summary>
  13. [JsonRequired]
  14. public string HomographyFilePath
  15. {
  16. get => homographyFilePath;
  17. set
  18. {
  19. if (!File.Exists(value))
  20. {
  21. throw new InvalidOperationException($"File \"{value}\" does not exist.");
  22. }
  23. homographyFilePath = value;
  24. }
  25. }
  26. private static readonly Lazy<Configuration> lazy = new(() =>
  27. {
  28. var dataPath = new DirectoryInfo(Application.streamingAssetsPath).FullName;
  29. var configFilePath = Path.Combine(dataPath, "StreetLight", "Configuration.json");
  30. return JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(configFilePath));
  31. });
  32. public static Configuration Instance => lazy.Value;
  33. private Configuration() { }
  34. }
  35. }