| 1 | /************************************************************************************ |
| 2 | Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. |
| 3 | |
| 4 | Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use |
| 5 | the Utilities SDK except in compliance with the License, which is provided at the time of installation |
| 6 | or download, or which otherwise accompanies this software in either electronic or hard copy form. |
| 7 | |
| 8 | You may obtain a copy of the License at |
| 9 | https://developer.oculus.com/licenses/utilities-1.31 |
| 10 | |
| 11 | Unless required by applicable law or agreed to in writing, the Utilities SDK distributed |
| 12 | under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 13 | ANY KIND, either express or implied. See the License for the specific language governing |
| 14 | permissions and limitations under the License. |
| 15 | ************************************************************************************/ |
| 16 | |
| 17 | using UnityEngine; |
| 18 | using UnityEditor; |
| 19 | using System.Collections.Generic; |
| 20 | using System.Reflection; |
| 21 | |
| 22 | [CustomEditor(typeof(OVRManager))] |
| 23 | public class OVRManagerEditor : Editor |
| 24 | { |
| 25 | override public void OnInspectorGUI() |
| 26 | { |
| 27 | #if UNITY_ANDROID |
| 28 | EditorGUILayout.LabelField("Target Devices"); |
| 29 | EditorGUI.indentLevel++; |
| 30 | OVRProjectConfig projectConfig = OVRProjectConfig.GetProjectConfig(); |
| 31 | List<OVRProjectConfig.DeviceType> oldTargetDeviceTypes = projectConfig.targetDeviceTypes; |
| 32 | List<OVRProjectConfig.DeviceType> targetDeviceTypes = new List<OVRProjectConfig.DeviceType>(oldTargetDeviceTypes); |
| 33 | bool hasModified = false; |
| 34 | int newCount = Mathf.Max(0, EditorGUILayout.IntField("Size", targetDeviceTypes.Count)); |
| 35 | while (newCount < targetDeviceTypes.Count) |
| 36 | { |
| 37 | targetDeviceTypes.RemoveAt(targetDeviceTypes.Count - 1); |
| 38 | hasModified = true; |
| 39 | } |
| 40 | while (newCount > targetDeviceTypes.Count) |
| 41 | { |
| 42 | targetDeviceTypes.Add(OVRProjectConfig.DeviceType.GearVrOrGo); |
| 43 | hasModified = true; |
| 44 | } |
| 45 | for (int i = 0; i < targetDeviceTypes.Count; i++) |
| 46 | { |
| 47 | var deviceType = (OVRProjectConfig.DeviceType)EditorGUILayout.EnumPopup(string.Format("Element {0}", i), targetDeviceTypes[i]); |
| 48 | if (deviceType != targetDeviceTypes[i]) |
| 49 | { |
| 50 | targetDeviceTypes[i] = deviceType; |
| 51 | hasModified = true; |
| 52 | } |
| 53 | } |
| 54 | if (hasModified) |
| 55 | { |
| 56 | projectConfig.targetDeviceTypes = targetDeviceTypes; |
| 57 | OVRProjectConfig.CommitProjectConfig(projectConfig); |
| 58 | } |
| 59 | EditorGUI.indentLevel--; |
| 60 | EditorGUILayout.Space(); |
| 61 | #endif |
| 62 | |
| 63 | DrawDefaultInspector(); |
| 64 | |
| 65 | #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID |
| 66 | OVRManager manager = (OVRManager)target; |
| 67 | #endif |
| 68 | |
| 69 | #if UNITY_ANDROID |
| 70 | EditorGUILayout.Space(); |
| 71 | EditorGUILayout.LabelField("Mixed Reality Capture for Quest (experimental)", EditorStyles.boldLabel); |
| 72 | EditorGUI.indentLevel++; |
| 73 | SetupMrcActivationModeField("ActivationMode", ref manager.mrcActivationMode); |
| 74 | EditorGUI.indentLevel--; |
| 75 | #endif |
| 76 | |
| 77 | #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN |
| 78 | EditorGUILayout.Space(); |
| 79 | EditorGUILayout.LabelField("Mixed Reality Capture", EditorStyles.boldLabel); |
| 80 | SetupBoolField("Show Properties", ref manager.expandMixedRealityCapturePropertySheet); |
| 81 | if (manager.expandMixedRealityCapturePropertySheet) |
| 82 | { |
| 83 | string[] layerMaskOptions = new string[32]; |
| 84 | for (int i=0; i<32; ++i) |
| 85 | { |
| 86 | layerMaskOptions[i] = LayerMask.LayerToName(i); |
| 87 | if (layerMaskOptions[i].Length == 0) |
| 88 | { |
| 89 | layerMaskOptions[i] = "<Layer " + i.ToString() + ">"; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | EditorGUI.indentLevel++; |
| 94 | |
| 95 | EditorGUILayout.Space(); |
| 96 | SetupBoolField("enableMixedReality", ref manager.enableMixedReality); |
| 97 | SetupCompositoinMethodField("compositionMethod", ref manager.compositionMethod); |
| 98 | SetupLayerMaskField("extraHiddenLayers", ref manager.extraHiddenLayers, layerMaskOptions); |
| 99 | |
| 100 | if (manager.compositionMethod == OVRManager.CompositionMethod.External) |
| 101 | { |
| 102 | EditorGUILayout.Space(); |
| 103 | EditorGUILayout.LabelField("External Composition", EditorStyles.boldLabel); |
| 104 | EditorGUI.indentLevel++; |
| 105 | |
| 106 | SetupColorField("backdropColor", ref manager.externalCompositionBackdropColor); |
| 107 | } |
| 108 | |
| 109 | if (manager.compositionMethod == OVRManager.CompositionMethod.Direct || manager.compositionMethod == OVRManager.CompositionMethod.Sandwich) |
| 110 | { |
| 111 | EditorGUILayout.Space(); |
| 112 | if (manager.compositionMethod == OVRManager.CompositionMethod.Direct) |
| 113 | { |
| 114 | EditorGUILayout.LabelField("Direct Composition", EditorStyles.boldLabel); |
| 115 | } |
| 116 | else |
| 117 | { |
| 118 | EditorGUILayout.LabelField("Sandwich Composition", EditorStyles.boldLabel); |
| 119 | } |
| 120 | EditorGUI.indentLevel++; |
| 121 | |
| 122 | EditorGUILayout.Space(); |
| 123 | EditorGUILayout.LabelField("Camera", EditorStyles.boldLabel); |
| 124 | SetupCameraDeviceField("capturingCameraDevice", ref manager.capturingCameraDevice); |
| 125 | SetupBoolField("flipCameraFrameHorizontally", ref manager.flipCameraFrameHorizontally); |
| 126 | SetupBoolField("flipCameraFrameVertically", ref manager.flipCameraFrameVertically); |
| 127 | |
| 128 | EditorGUILayout.Space(); |
| 129 | EditorGUILayout.LabelField("Chroma Key", EditorStyles.boldLabel); |
| 130 | SetupColorField("chromaKeyColor", ref manager.chromaKeyColor); |
| 131 | SetupFloatField("chromaKeySimilarity", ref manager.chromaKeySimilarity); |
| 132 | SetupFloatField("chromaKeySmoothRange", ref manager.chromaKeySmoothRange); |
| 133 | SetupFloatField("chromaKeySpillRange", ref manager.chromaKeySpillRange); |
| 134 | |
| 135 | EditorGUILayout.Space(); |
| 136 | EditorGUILayout.LabelField("Dynamic Lighting", EditorStyles.boldLabel); |
| 137 | SetupBoolField("useDynamicLighting", ref manager.useDynamicLighting); |
| 138 | SetupDepthQualityField("depthQuality", ref manager.depthQuality); |
| 139 | SetupFloatField("dynamicLightingSmoothFactor", ref manager.dynamicLightingSmoothFactor); |
| 140 | SetupFloatField("dynamicLightingDepthVariationClampingValue", ref manager.dynamicLightingDepthVariationClampingValue); |
| 141 | |
| 142 | EditorGUILayout.Space(); |
| 143 | EditorGUILayout.LabelField("Virtual Green Screen", EditorStyles.boldLabel); |
| 144 | SetupVirtualGreenTypeField("virtualGreenScreenType", ref manager.virtualGreenScreenType); |
| 145 | SetupFloatField("virtualGreenScreenTopY", ref manager.virtualGreenScreenTopY); |
| 146 | SetupFloatField("virtualGreenScreenBottomY", ref manager.virtualGreenScreenBottomY); |
| 147 | SetupBoolField("virtualGreenScreenApplyDepthCulling", ref manager.virtualGreenScreenApplyDepthCulling); |
| 148 | SetupFloatField("virtualGreenScreenDepthTolerance", ref manager.virtualGreenScreenDepthTolerance); |
| 149 | |
| 150 | EditorGUILayout.Space(); |
| 151 | EditorGUILayout.LabelField("Latency Control", EditorStyles.boldLabel); |
| 152 | SetupFloatField("handPoseStateLatency", ref manager.handPoseStateLatency); |
| 153 | if (manager.compositionMethod == OVRManager.CompositionMethod.Sandwich) |
| 154 | { |
| 155 | SetupFloatField("sandwichCompositionRenderLatency", ref manager.sandwichCompositionRenderLatency); |
| 156 | SetupIntField("sandwichCompositionBufferedFrames", ref manager.sandwichCompositionBufferedFrames); |
| 157 | } |
| 158 | EditorGUI.indentLevel--; |
| 159 | } |
| 160 | |
| 161 | EditorGUI.indentLevel--; |
| 162 | } |
| 163 | #endif |
| 164 | } |
| 165 | |
| 166 | #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID |
| 167 | void SetupBoolField(string name, ref bool member) |
| 168 | { |
| 169 | EditorGUI.BeginChangeCheck(); |
| 170 | bool value = EditorGUILayout.Toggle(name, member); |
| 171 | if (EditorGUI.EndChangeCheck()) |
| 172 | { |
| 173 | Undo.RecordObject(target, "Changed " + name); |
| 174 | member = value; |
| 175 | } |
| 176 | } |
| 177 | |
| 178 | void SetupIntField(string name, ref int member) |
| 179 | { |
| 180 | EditorGUI.BeginChangeCheck(); |
| 181 | int value = EditorGUILayout.IntField(name, member); |
| 182 | if (EditorGUI.EndChangeCheck()) |
| 183 | { |
| 184 | Undo.RecordObject(target, "Changed " + name); |
| 185 | member = value; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | void SetupFloatField(string name, ref float member) |
| 190 | { |
| 191 | EditorGUI.BeginChangeCheck(); |
| 192 | float value = EditorGUILayout.FloatField(name, member); |
| 193 | if (EditorGUI.EndChangeCheck()) |
| 194 | { |
| 195 | Undo.RecordObject(target, "Changed " + name); |
| 196 | member = value; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | void SetupDoubleField(string name, ref double member) |
| 201 | { |
| 202 | EditorGUI.BeginChangeCheck(); |
| 203 | double value = EditorGUILayout.DoubleField(name, member); |
| 204 | if (EditorGUI.EndChangeCheck()) |
| 205 | { |
| 206 | Undo.RecordObject(target, "Changed " + name); |
| 207 | member = value; |
| 208 | } |
| 209 | } |
| 210 | void SetupColorField(string name, ref Color member) |
| 211 | { |
| 212 | EditorGUI.BeginChangeCheck(); |
| 213 | Color value = EditorGUILayout.ColorField(name, member); |
| 214 | if (EditorGUI.EndChangeCheck()) |
| 215 | { |
| 216 | Undo.RecordObject(target, "Changed " + name); |
| 217 | member = value; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void SetupLayerMaskField(string name, ref LayerMask layerMask, string[] layerMaskOptions) |
| 222 | { |
| 223 | EditorGUI.BeginChangeCheck(); |
| 224 | int value = EditorGUILayout.MaskField(name, layerMask, layerMaskOptions); |
| 225 | if (EditorGUI.EndChangeCheck()) |
| 226 | { |
| 227 | Undo.RecordObject(target, "Changed " + name); |
| 228 | layerMask = value; |
| 229 | } |
| 230 | } |
| 231 | |
| 232 | void SetupCompositoinMethodField(string name, ref OVRManager.CompositionMethod method) |
| 233 | { |
| 234 | EditorGUI.BeginChangeCheck(); |
| 235 | OVRManager.CompositionMethod value = (OVRManager.CompositionMethod)EditorGUILayout.EnumPopup(name, method); |
| 236 | if (EditorGUI.EndChangeCheck()) |
| 237 | { |
| 238 | Undo.RecordObject(target, "Changed " + name); |
| 239 | method = value; |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | void SetupCameraDeviceField(string name, ref OVRManager.CameraDevice device) |
| 244 | { |
| 245 | EditorGUI.BeginChangeCheck(); |
| 246 | OVRManager.CameraDevice value = (OVRManager.CameraDevice)EditorGUILayout.EnumPopup(name, device); |
| 247 | if (EditorGUI.EndChangeCheck()) |
| 248 | { |
| 249 | Undo.RecordObject(target, "Changed " + name); |
| 250 | device = value; |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | void SetupDepthQualityField(string name, ref OVRManager.DepthQuality depthQuality) |
| 255 | { |
| 256 | EditorGUI.BeginChangeCheck(); |
| 257 | OVRManager.DepthQuality value = (OVRManager.DepthQuality)EditorGUILayout.EnumPopup(name, depthQuality); |
| 258 | if (EditorGUI.EndChangeCheck()) |
| 259 | { |
| 260 | Undo.RecordObject(target, "Changed " + name); |
| 261 | depthQuality = value; |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void SetupVirtualGreenTypeField(string name, ref OVRManager.VirtualGreenScreenType virtualGreenScreenType) |
| 266 | { |
| 267 | EditorGUI.BeginChangeCheck(); |
| 268 | OVRManager.VirtualGreenScreenType value = (OVRManager.VirtualGreenScreenType)EditorGUILayout.EnumPopup(name, virtualGreenScreenType); |
| 269 | if (EditorGUI.EndChangeCheck()) |
| 270 | { |
| 271 | Undo.RecordObject(target, "Changed " + name); |
| 272 | virtualGreenScreenType = value; |
| 273 | } |
| 274 | } |
| 275 | |
| 276 | void SetupMrcActivationModeField(string name, ref OVRManager.MrcActivationMode mrcActivationMode) |
| 277 | { |
| 278 | EditorGUI.BeginChangeCheck(); |
| 279 | OVRManager.MrcActivationMode value = (OVRManager.MrcActivationMode)EditorGUILayout.EnumPopup(name, mrcActivationMode); |
| 280 | if (EditorGUI.EndChangeCheck()) |
| 281 | { |
| 282 | Undo.RecordObject(target, "Changed " + name); |
| 283 | mrcActivationMode = value; |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | #endif |
| 288 | } |