|
| 1 | +// Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | +// Licensed under the MIT License. See LICENSE in the project root for license information. |
| 3 | + |
| 4 | +using Microsoft.MixedReality.Toolkit.Core.Definitions.Utilities; |
| 5 | +using Microsoft.MixedReality.Toolkit.SDK.Utilities.Solvers; |
| 6 | +using UnityEditor; |
| 7 | +using UnityEngine; |
| 8 | + |
| 9 | +namespace Microsoft.MixedReality.Toolkit.SDK.Inspectors.Utilities.Solvers |
| 10 | +{ |
| 11 | + [CustomEditor(typeof(SolverHandler))] |
| 12 | + [CanEditMultipleObjects] |
| 13 | + public class SolverHandlerInspector : ControllerFinderInspector |
| 14 | + { |
| 15 | + private SerializedProperty trackedObjectProperty; |
| 16 | + private SerializedProperty transformTargetProperty; |
| 17 | + private SerializedProperty additionalOffsetProperty; |
| 18 | + private SerializedProperty additionalRotationProperty; |
| 19 | + private SerializedProperty updateSolversProperty; |
| 20 | + private SolverHandler solverHandler; |
| 21 | + private readonly GUIContent trackedTransformGUIContent = new GUIContent("Tracked Transform"); |
| 22 | + |
| 23 | + protected override void OnEnable() |
| 24 | + { |
| 25 | + base.OnEnable(); |
| 26 | + |
| 27 | + trackedObjectProperty = serializedObject.FindProperty("trackedObjectToReference"); |
| 28 | + transformTargetProperty = serializedObject.FindProperty("transformTarget"); |
| 29 | + additionalOffsetProperty = serializedObject.FindProperty("additionalOffset"); |
| 30 | + additionalRotationProperty = serializedObject.FindProperty("additionalRotation"); |
| 31 | + updateSolversProperty = serializedObject.FindProperty("updateSolvers"); |
| 32 | + |
| 33 | + solverHandler = target as SolverHandler; |
| 34 | + } |
| 35 | + |
| 36 | + public override void OnInspectorGUI() |
| 37 | + { |
| 38 | + serializedObject.Update(); |
| 39 | + EditorGUILayout.Space(); |
| 40 | + |
| 41 | + bool trackedObjectChanged = false; |
| 42 | + |
| 43 | + if (transformTargetProperty.objectReferenceValue == null || Application.isPlaying) |
| 44 | + { |
| 45 | + EditorGUI.BeginChangeCheck(); |
| 46 | + EditorGUILayout.PropertyField(trackedObjectProperty); |
| 47 | + trackedObjectChanged = EditorGUI.EndChangeCheck(); |
| 48 | + } |
| 49 | + |
| 50 | + EditorGUILayout.PropertyField(transformTargetProperty, trackedTransformGUIContent); |
| 51 | + |
| 52 | + EditorGUI.BeginChangeCheck(); |
| 53 | + EditorGUILayout.PropertyField(additionalOffsetProperty); |
| 54 | + EditorGUILayout.PropertyField(additionalRotationProperty); |
| 55 | + bool additionalOffsetChanged = EditorGUI.EndChangeCheck(); |
| 56 | + |
| 57 | + EditorGUILayout.PropertyField(updateSolversProperty); |
| 58 | + |
| 59 | + serializedObject.ApplyModifiedProperties(); |
| 60 | + |
| 61 | + if (Application.isPlaying && trackedObjectChanged) |
| 62 | + { |
| 63 | + solverHandler.RefreshTrackedObject(); |
| 64 | + } |
| 65 | + |
| 66 | + if (Application.isPlaying && additionalOffsetChanged) |
| 67 | + { |
| 68 | + solverHandler.AdditionalOffset = additionalOffsetProperty.vector3Value; |
| 69 | + solverHandler.AdditionalRotation = additionalRotationProperty.vector3Value; |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | +} |
0 commit comments