NxrViewerEditor.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. // Copyright 2016 Nibiru Inc. All rights reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. using System.IO;
  15. using UnityEngine;
  16. using UnityEditor;
  17. namespace Nxr.Internal
  18. {
  19. /// A custom editor for properties on the NxrViewer script. This appears in the
  20. /// Inspector window of a NxrViewer object. Its purpose is to allow changing the
  21. /// `NxrViewer.Instance` object's properties from their default values.
  22. [CustomEditor(typeof(NxrViewer))]
  23. public class NxrViewerEditor : Editor
  24. {
  25. // GUIContent directRenderEnabledLabel = new GUIContent("DirectRender Enabled",
  26. //"Whether to draw directly to the output window (true), or " +
  27. // "to an offscreen buffer first and then blit (false). Image " +
  28. // " Effects and Deferred Lighting may only work if set to false.");
  29. // GUIContent distortionEnabledLabel = new GUIContent("Distortion Enabled",
  30. // "Sets whether Distortion is enabled in DFT Mode.");
  31. GUIContent splitModeLabel = new GUIContent("Split Mode Enabled",
  32. "Sets whether Split mode is enabled.");
  33. GUIContent arLockHeadTracker = new GUIContent("Lock HeadTracker",
  34. "Sets whether Lock HeadTracker In Android.");
  35. GUIContent editorSettingsLabel = new GUIContent("Unity Editor Emulation Settings",
  36. "Controls for the in-editor emulation of a Cardboard viewer.");
  37. GUIContent autoUntiltHeadLabel = new GUIContent("Auto Untilt Head",
  38. "When enabled, just release Ctrl to untilt the head.");
  39. GUIContent screenSizeLabel = new GUIContent("Screen Size",
  40. "The screen size to emulate.");
  41. GUIContent viewerTypeLabel = new GUIContent("Viewer Type",
  42. "The viewer type to emulate.");
  43. GUIContent qualityLabel = new GUIContent("Texture Quality",
  44. "The texture quality in android.");
  45. GUIContent trackerPositionLabel = new GUIContent("Tracker Position",
  46. "Update the Camera's position with the user's head offset.");
  47. GUIContent effectRenderLabel = new GUIContent("Effect Render",
  48. "If you wish to use Deferred Rendering or any Image Effects in stereo, turn this option on.");
  49. GUIContent recenterLabel = new GUIContent("Firstly Recenter",
  50. "Do Camera recenter after the sdk load succ ,but before screen render.");
  51. GUIContent debuggingLabel = new GUIContent("Device Remote Debug",
  52. "When XR device is usb connected, use XR device sensor data in editor run mode.");
  53. GUIContent headControl = new GUIContent("Head Control", "Sets Head Control is enabled.");
  54. GUIContent duration = new GUIContent("Duration", "Sets Duration");
  55. GUIContent use3rdPosTip = new GUIContent("Use Third Party Position Data", "Whether Use Third Party Position Data, true=Use 3rd Party, false= Use HMD Position Data");
  56. GUIContent displacementCoefficient = new GUIContent("DisplacementCoefficient", "6Dof Displacement Coefficient");
  57. GUIContent SleepContent= new GUIContent("Sleep Timeout Mode", "Prevent screen dimming or not");
  58. /// @cond HIDDEN
  59. public override void OnInspectorGUI()
  60. {
  61. GUI.changed = false;
  62. GUIStyle headingStyle = new GUIStyle(GUI.skin.label);
  63. headingStyle.fontStyle = FontStyle.Bold;
  64. NxrViewer nvrViewer = (NxrViewer)target;
  65. EditorGUILayout.LabelField("General Settings", headingStyle);
  66. // 读取Config
  67. SettingsAssetConfig asset = NxrSDKApi.Instance.GetSettingsAssetConfig();
  68. nvrViewer.SixDofMode = asset.mSixDofMode;
  69. nvrViewer.SleepMode = asset.mSleepTimeoutMode;
  70. nvrViewer.HeadControl = asset.mHeadControl;
  71. nvrViewer.TextureQuality = asset.mTextureQuality;
  72. nvrViewer.TextureMSAA= asset.mTextureMSAA;
  73. // 读取Config
  74. #if UNITY_ANDROID
  75. nvrViewer.TrackerPosition = EditorGUILayout.Toggle(trackerPositionLabel, nvrViewer.TrackerPosition);
  76. #endif
  77. if (nvrViewer.TrackerPosition)
  78. {
  79. nvrViewer.DisplacementCoefficient = EditorGUILayout.Slider(displacementCoefficient, nvrViewer.DisplacementCoefficient,0,1);
  80. }
  81. nvrViewer.SleepMode = (SleepTimeoutMode) EditorGUILayout.EnumPopup(SleepContent, nvrViewer.SleepMode);
  82. nvrViewer.SplitScreenModeEnabled = EditorGUILayout.Toggle(splitModeLabel, nvrViewer.SplitScreenModeEnabled);
  83. nvrViewer.TextureQuality = (TextureQuality)EditorGUILayout.EnumPopup(qualityLabel, nvrViewer.TextureQuality);
  84. nvrViewer.RemoteDebug = EditorGUILayout.Toggle(debuggingLabel, nvrViewer.RemoteDebug);
  85. nvrViewer.RemoteController = EditorGUILayout.Toggle(new GUIContent("Device Remote Controller",
  86. "When XR device is usb connected, use XR device controller data in editor run mode."), nvrViewer.RemoteController);
  87. nvrViewer.ShowFPS = EditorGUILayout.Toggle("Show FPS in Scene", nvrViewer.ShowFPS);
  88. EditorGUILayout.LabelField("Advanced Settings", headingStyle);
  89. nvrViewer.HeadControl = (HeadControl)EditorGUILayout.EnumPopup(headControl, nvrViewer.HeadControl);
  90. if (nvrViewer.HeadControl == HeadControl.Hover)
  91. {
  92. nvrViewer.Duration = EditorGUILayout.DelayedFloatField(duration, nvrViewer.Duration);
  93. }
  94. nvrViewer.TextureMSAA = (TextureMSAA)EditorGUILayout.EnumPopup(new GUIContent("Texture MSAA",
  95. "The texture Anti-aliasing"), nvrViewer.TextureMSAA);
  96. EditorGUILayout.LabelField("SixDof Controller Settings", headingStyle);
  97. nvrViewer.IsAppHandleTriggerEvent = EditorGUILayout.Toggle(new GUIContent("App Handle Controller Trigger Event", "Sets Handle Controller Trigger Event"),
  98. nvrViewer.IsAppHandleTriggerEvent);
  99. #if UNITY_STANDALONE_WIN || ANDROID_REMOTE_NRR
  100. nvrViewer.TextureQuality = TextureQuality.Best;
  101. nvrViewer.TargetFrameRate = (FrameRate)EditorGUILayout.EnumPopup(new GUIContent("TargetFrameRate",
  102. "The target Frame Rate in PC."), nvrViewer.TargetFrameRate);
  103. nvrViewer.UseThirdPartyPosition = EditorGUILayout.Toggle(use3rdPosTip, nvrViewer.UseThirdPartyPosition);
  104. #endif
  105. EditorGUILayout.Separator();
  106. if (GUI.changed)
  107. {
  108. asset.mSleepTimeoutMode = nvrViewer.SleepMode;
  109. asset.mHeadControl = nvrViewer.HeadControl;
  110. asset.mTextureQuality = nvrViewer.TextureQuality;
  111. asset.mTextureMSAA = nvrViewer.TextureMSAA;
  112. EditorUtility.SetDirty(asset);
  113. EditorUtility.SetDirty(nvrViewer);
  114. }
  115. // 保存序列化数据,否则会出现设置数据丢失情况
  116. serializedObject.ApplyModifiedProperties();
  117. }
  118. }
  119. }