NRSessionConfig.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  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 UnityEngine;
  12. using UnityEngine.Serialization;
  13. using System.Collections.Generic;
  14. /// <summary> A configuration used to track the world. </summary>
  15. [CreateAssetMenu(fileName = "NRKernalSessionConfig", menuName = "NRSDK/SessionConfig", order = 1)]
  16. public class NRSessionConfig : ScriptableObject
  17. {
  18. /// <summary> Chooses which plane finding mode will be used. </summary>
  19. [Tooltip("Chooses which plane finding mode will be used.")]
  20. [FormerlySerializedAs("EnablePlaneFinding")]
  21. public TrackablePlaneFindingMode PlaneFindingMode = TrackablePlaneFindingMode.DISABLE;
  22. /// <summary> Chooses which marker finding mode will be used. </summary>
  23. [Tooltip("Chooses which marker finding mode will be used.")]
  24. [FormerlySerializedAs("EnableImageTracking")]
  25. public TrackableImageFindingMode ImageTrackingMode = TrackableImageFindingMode.DISABLE;
  26. /// <summary>
  27. /// A scriptable object specifying the NRSDK TrackingImageDatabase configuration. </summary>
  28. [Tooltip("A scriptable object specifying the NRSDK TrackingImageDatabase configuration.")]
  29. public NRTrackingImageDatabase TrackingImageDatabase;
  30. /// <summary> Chooses whether notification will be used. </summary>
  31. [Tooltip("Chooses whether notification will be used.")]
  32. public bool EnableNotification = false;
  33. /// <summary> Chooses whether to kill process while receive OnGlassesDisconnectEvent for NOTIFY_TO_QUIT_APP reason. </summary>
  34. [Tooltip("Chooses whether to force kill while receive OnGlassesDisconnectEvent for NOTIFY_TO_QUIT_APP reason.")]
  35. public bool ForceKillWhileGlassSwitchMode = true;
  36. /// <summary> An error prompt will pop up when the device fails to connect. </summary>
  37. [Tooltip("An error prompt will pop up when the device fails to connect.")]
  38. public NRGlassesInitErrorTip GlassesErrorTipPrefab;
  39. /// <summary> An warnning prompt will pop up when the lost tracking. </summary>
  40. [Tooltip("An warnning prompt will pop up when the lost tracking.")]
  41. public NRTrackingModeChangedTip TrackingModeChangeTipPrefab;
  42. /// <summary> It will be read automatically from PlayerdSetting. </summary>
  43. [HideInInspector]
  44. public bool UseMultiThread
  45. {
  46. get;
  47. private set;
  48. }
  49. /// <summary> The NRProjectConfig whick is global unique. All NRSessionConfig in project should refer to the same NRProjectConfig. </summary>
  50. [SerializeField]
  51. [Tooltip("Donot change this manually, it always refer to the NRProjectConfig whick is global unique.")]
  52. NRProjectConfig ProjectConfig;
  53. public NRProjectConfig GlobalProjectConfig
  54. {
  55. get
  56. {
  57. return ProjectConfig;
  58. }
  59. }
  60. /// <summary> ValueType check if two NRSessionConfig objects are equal. </summary>
  61. /// <param name="other"> .</param>
  62. /// <returns>
  63. /// True if the two NRSessionConfig objects are value-type equal, otherwise false. </returns>
  64. public override bool Equals(object other)
  65. {
  66. NRSessionConfig otherConfig = other as NRSessionConfig;
  67. if (other == null)
  68. {
  69. return false;
  70. }
  71. if (PlaneFindingMode != otherConfig.PlaneFindingMode ||
  72. ImageTrackingMode != otherConfig.ImageTrackingMode ||
  73. TrackingImageDatabase != otherConfig.TrackingImageDatabase)
  74. {
  75. return false;
  76. }
  77. if (ProjectConfig != otherConfig.ProjectConfig)
  78. return false;
  79. return true;
  80. }
  81. /// <summary> Return a hash code for this object. </summary>
  82. /// <returns> A hash code for this object. </returns>
  83. public override int GetHashCode()
  84. {
  85. return base.GetHashCode();
  86. }
  87. /// <summary> ValueType copy from another SessionConfig object into this one. </summary>
  88. /// <param name="other"> .</param>
  89. public void CopyFrom(NRSessionConfig other)
  90. {
  91. PlaneFindingMode = other.PlaneFindingMode;
  92. ImageTrackingMode = other.ImageTrackingMode;
  93. TrackingImageDatabase = other.TrackingImageDatabase;
  94. GlassesErrorTipPrefab = other.GlassesErrorTipPrefab;
  95. TrackingModeChangeTipPrefab = other.TrackingModeChangeTipPrefab;
  96. UseMultiThread = other.UseMultiThread;
  97. EnableNotification = other.EnableNotification;
  98. ForceKillWhileGlassSwitchMode = other.ForceKillWhileGlassSwitchMode;
  99. ProjectConfig = other.ProjectConfig;
  100. }
  101. public bool IsTargetDevice(NRDeviceType device)
  102. {
  103. return ProjectConfig ? ProjectConfig.targetDeviceTypes.Contains(device) : false;
  104. }
  105. public string GetTargetDeviceTypesDesc()
  106. {
  107. return ProjectConfig ? ProjectConfig.GetTargetDeviceTypesDesc() : string.Empty;
  108. }
  109. #if UNITY_EDITOR
  110. public void SetProjectConfig(NRProjectConfig projectConfig)
  111. {
  112. ProjectConfig = projectConfig;
  113. }
  114. public void SetUseMultiThread(bool useMultiThread)
  115. {
  116. UseMultiThread = useMultiThread;
  117. }
  118. #endif
  119. }
  120. }