Configuration.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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 outputCalibrationFilesDirectory;
  10. ///// <summary>
  11. ///// The directory path where new calibration files are saved when the calibration is run.
  12. ///// </summary>
  13. //[JsonRequired]
  14. //public string OutputCalibrationFilesDirectory
  15. //{
  16. // get => outputCalibrationFilesDirectory;
  17. // set
  18. // {
  19. // if (!Directory.Exists(value))
  20. // {
  21. // throw new InvalidOperationException($"Directory \"{value}\" does not exist.");
  22. // }
  23. // outputCalibrationFilesDirectory = value;
  24. // }
  25. //}
  26. //private string inputCalibrationFilePath;
  27. ///// <summary>
  28. ///// The file path to the calibration file that is used as input for the actual calibration.
  29. ///// </summary>
  30. //[JsonRequired]
  31. //public string InputCalibrationFilePath
  32. //{
  33. // get => inputCalibrationFilePath;
  34. // set
  35. // {
  36. // if (!File.Exists(value))
  37. // {
  38. // throw new InvalidOperationException($"File \"{value}\" does not exist.");
  39. // }
  40. // inputCalibrationFilePath = value;
  41. // }
  42. //}
  43. private string homographyFilePath;
  44. /// <summary>
  45. /// The file path to the csv file containing the homography for mapping world coodrinates to Unity coordinates.
  46. /// </summary>
  47. [JsonRequired]
  48. public string HomographyFilePath
  49. {
  50. get => homographyFilePath;
  51. set
  52. {
  53. if (!File.Exists(value))
  54. {
  55. throw new InvalidOperationException($"File \"{value}\" does not exist.");
  56. }
  57. homographyFilePath = value;
  58. }
  59. }
  60. private static readonly Lazy<Configuration> lazy = new(() => JsonConvert.DeserializeObject<Configuration>(File.ReadAllText(Path.Combine(Application.streamingAssetsPath, "Configuration.json"))));
  61. public static Configuration Instance => lazy.Value;
  62. private Configuration() { }
  63. }
  64. }