NRTrackingImageDatabaseEntry.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /****************************************************************************
  2. * Copyright 2019 Nreal Techonology Limited. All rights reserved.
  3. *
  4. * This file is part of NRSDK.
  5. *
  6. * https://www.nreal.ai/
  7. *
  8. *****************************************************************************/
  9. namespace NRKernal
  10. {
  11. using System;
  12. using UnityEngine;
  13. #if UNITY_EDITOR
  14. using UnityEditor;
  15. using System.IO;
  16. #endif
  17. /// <summary> Hold the total infomation of a image data base item. </summary>
  18. [Serializable]
  19. public struct NRTrackingImageDatabaseEntry
  20. {
  21. /// <summary> The name assigned to the tracked image. </summary>
  22. public string Name;
  23. /// <summary> The width of the image in meters. </summary>
  24. public float Width;
  25. /// <summary> The height of the image in meters. </summary>
  26. public float Height;
  27. /// <summary> The quality of the image. </summary>
  28. public string Quality;
  29. /// <summary> The Unity GUID for this entry. </summary>
  30. public string TextureGUID;
  31. /// <summary> Contructs a new Augmented Image database entry. </summary>
  32. /// <param name="name"> The image name.</param>
  33. /// <param name="width"> The image width in meters or 0 if the width is unknown.</param>
  34. /// <param name="height"> The height of the image in meters.</param>
  35. public NRTrackingImageDatabaseEntry(string name, float width, float height)
  36. {
  37. Name = name;
  38. TextureGUID = string.Empty;
  39. Width = width;
  40. Height = height;
  41. Quality = string.Empty;
  42. TextureGUID = string.Empty;
  43. }
  44. #if UNITY_EDITOR
  45. /// <summary> Contructs a new Augmented Image database entry. </summary>
  46. /// <param name="name"> The image name.</param>
  47. /// <param name="texture"> The texture.</param>
  48. /// <param name="width"> The image width in meters or 0 if the width is unknown.</param>
  49. /// <param name="height"> The height of the image in meters.</param>
  50. public NRTrackingImageDatabaseEntry(string name, Texture2D texture, float width, float height)
  51. {
  52. Name = name;
  53. TextureGUID = string.Empty;
  54. Width = width;
  55. Quality = string.Empty;
  56. Height = height;
  57. Texture = texture;
  58. }
  59. /// <summary> Contructs a new Augmented Image database entry. </summary>
  60. /// <param name="name"> The image name.</param>
  61. /// <param name="texture"> The texture.</param>
  62. public NRTrackingImageDatabaseEntry(string name, Texture2D texture)
  63. {
  64. Name = name;
  65. TextureGUID = string.Empty;
  66. Width = 0;
  67. Quality = string.Empty;
  68. Height = 0;
  69. Texture = texture;
  70. }
  71. /// <summary> Contructs a new Augmented Image database entry. </summary>
  72. /// <param name="texture"> The texture.</param>
  73. public NRTrackingImageDatabaseEntry(Texture2D texture)
  74. {
  75. Name = "Unnamed";
  76. TextureGUID = string.Empty;
  77. Width = 0;
  78. Quality = string.Empty;
  79. Height = 0;
  80. Texture = texture;
  81. }
  82. /// <summary> Gets or sets the texture. </summary>
  83. /// <value> The texture. </value>
  84. public Texture2D Texture
  85. {
  86. get
  87. {
  88. return AssetDatabase.LoadAssetAtPath<Texture2D>(AssetDatabase.GUIDToAssetPath(TextureGUID));
  89. }
  90. set
  91. {
  92. string path = AssetDatabase.GetAssetPath(value);
  93. TextureGUID = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(value));
  94. var fileName = Path.GetFileName(path);
  95. Name = fileName.Replace(Path.GetExtension(fileName), string.Empty);
  96. }
  97. }
  98. /// <summary> Convert this object into a string representation. </summary>
  99. /// <returns> A string that represents this object. </returns>
  100. public override string ToString()
  101. {
  102. return string.Format("Name:{0} Quality:{1}", Name, Quality);
  103. }
  104. #endif
  105. }
  106. }