public override void OnInspectorGUI() { serializedObject.Update(); EditorGUILayout.DelayedTextField(trackerIpProperty); EditorGUILayout.LabelField("Matrix directory"); matrixDirectoryProperty.stringValue = EditorGUILayout.TextArea(matrixDirectoryProperty.stringValue); cstFromFileProperty.boolValue = EditorGUILayout.Toggle("Auto-load CST from file", cstFromFileProperty.boolValue); if (cstFromFileProperty.boolValue) { // If we're loading from a file, we need to define the file. var newBase = (RelativePathBase)EditorGUILayout.EnumPopup((RelativePathBase)cstPathBaseProperty.enumValueIndex); cstPathBaseProperty.enumValueIndex = (int)newBase; cstPathProperty.stringValue = EditorGUILayout.TextField("CST matrix path", cstPathProperty.stringValue); if (GUILayout.Button("Load")) // Button allows the user to load from the specified file in the editor. { var basePath = ""; // For relative paths, we look at the users selection. switch ((RelativePathBase)cstPathBaseProperty.enumValueIndex) { case RelativePathBase.ProjectAssets: { basePath = Application.dataPath; break; } case RelativePathBase.TrackerBoss: { basePath = matrixDirectoryProperty.stringValue; break; } } LoadCstMatrix(System.IO.Path.Combine(basePath, cstPathProperty.stringValue)); // Load matrix from file. } } else { if (GUILayout.Button("Load...")) { // Load matrix using a file chooser. Matrix loading is not performed in build. var path = EditorUtility.OpenFilePanelWithFilters("Open File", Application.dataPath, new string[] { "Data files", "dat", "All files", "*" }); LoadCstMatrix(path); } } EditorGUI.BeginDisabledGroup(true); SAREditorGUI.Matrix4x4Field(cstMatrixProperty); EditorGUILayout.DelayedFloatField(cstScaleFactorProperty); SAREditorGUI.Matrix4x4Field(cstTransformMatrixProperty); EditorGUI.EndDisabledGroup(); serializedObject.ApplyModifiedProperties(); }
public override void OnInspectorGUI() { serializedObject.Update(); // Update the serialized representation of the target. var trackerTransform = target as TrackerTransform; var sceneBoss = FindObjectOfType <TrackerBoss>(); // First TrackerBoss in the scene. Used if some values inherit from the boss, but no boss object explicitly defined. updateInEditor.boolValue = EditorGUILayout.Toggle("Update in editor", updateInEditor.boolValue); trackerTransform.runInEditMode = updateInEditor.boolValue; // If VRPN is driving the transform in edit mode, disable the transform editor. if (updateInEditor.boolValue) { trackerTransform.transform.hideFlags |= HideFlags.NotEditable; } else { trackerTransform.transform.hideFlags &= ~HideFlags.NotEditable; } EditorGUILayout.DelayedTextField(trackerId); var shouldUseBoss = EditorGUILayout.Toggle("Inherit values from Tracker Boss", useBoss.boolValue); useBoss.boolValue = shouldUseBoss; if (useBoss.boolValue) { // If using boss, optionally use boss value for ip. EditorGUILayout.ObjectField(trackerBoss, typeof(TrackerBoss)); var shouldUseBossIp = EditorGUILayout.Toggle("IP from Tracker Boss", ipFromBoss.boolValue); ipFromBoss.boolValue = shouldUseBossIp; } else { ipFromBoss.boolValue = false; } if (!ipFromBoss.boolValue) { // Hide if driven by boss. EditorGUILayout.DelayedTextField(trackerIp); } /* Setup CST Matrix */ if (useBoss.boolValue) { // If using boss, optionally use boss value for cst. cstFromBossProp.boolValue = EditorGUILayout.Toggle("Inherit CST matrix from TrackerBoss", cstFromBossProp.boolValue); } else { cstFromBossProp.boolValue = false; } if (!cstFromBossProp.boolValue) { cstFromFileProp.boolValue = EditorGUILayout.Toggle("Auto-load CST from file", cstFromFileProp.boolValue); if (cstFromFileProp.boolValue) { // If we're loading from a file, we need to define the file. var newBase = (RelativePathBase)EditorGUILayout.EnumPopup((RelativePathBase)cstPathBaseProp.enumValueIndex); cstPathBaseProp.enumValueIndex = (int)newBase; cstPath.stringValue = EditorGUILayout.TextField("CST matrix path", cstPath.stringValue); if (GUILayout.Button("Load")) // Button allows the user to load from the specified file in the editor. { var basePath = ""; // For relative paths, we look at the users selection. switch ((RelativePathBase)cstPathBaseProp.enumValueIndex) { case RelativePathBase.ProjectAssets: { basePath = Application.dataPath; break; } case RelativePathBase.TrackerBoss: { // First check if the user specified a boss. If not, find one in the scene. if (trackerBoss.objectReferenceValue == null) { if (sceneBoss == null) { EditorUtility.DisplayDialog("Load Error", "No TrackerBoss in scene.", "OK"); } else { basePath = sceneBoss.MatrixDirectory; } } else { basePath = (trackerBoss.objectReferenceValue as TrackerBoss).MatrixDirectory; } break; } } LoadCstMatrix(System.IO.Path.Combine(basePath, cstPath.stringValue)); // Load matrix from file. } } else { if (GUILayout.Button("Load...")) { // Load matrix using a file chooser. Matrix loading is not performed in build. var path = EditorUtility.OpenFilePanelWithFilters("Open File", Application.dataPath, new string[] { "Data files", "dat", "All files", "*" }); LoadCstMatrix(path); } } // Draw matrix and derived parameters, these shouldn't be editred directly, but should be loaded from a file. EditorGUI.BeginDisabledGroup(true); SAREditorGUI.Matrix4x4Field(cstMatrix); EditorGUILayout.DelayedFloatField(cstScaleFactor); SAREditorGUI.Matrix4x4Field(cstTransformMatrix); EditorGUI.EndDisabledGroup(); } /* Setup offset Matrix */ offsetFromFileProp.boolValue = EditorGUILayout.Toggle("Auto-load offset from file", offsetFromFileProp.boolValue); if (offsetFromFileProp.boolValue) { var newBase = (RelativePathBase)EditorGUILayout.EnumPopup((RelativePathBase)offsetPathBaseProp.enumValueIndex); offsetPathBaseProp.enumValueIndex = (int)newBase; offsetPath.stringValue = EditorGUILayout.TextField("Offset matrix path", offsetPath.stringValue); if (GUILayout.Button("Load")) { var basePath = ""; switch ((RelativePathBase)offsetPathBaseProp.enumValueIndex) { case RelativePathBase.ProjectAssets: { basePath = Application.dataPath; break; } case RelativePathBase.TrackerBoss: { if (trackerBoss.objectReferenceValue == null) { if (sceneBoss == null) { EditorUtility.DisplayDialog("Load Error", "No TrackerBoss in scene.", "OK"); } else { basePath = sceneBoss.MatrixDirectory; } } else { basePath = (trackerBoss.objectReferenceValue as TrackerBoss).MatrixDirectory; } break; } } LoadOffsetMatrix(System.IO.Path.Combine(basePath, offsetPath.stringValue)); } } else { if (GUILayout.Button("Load...")) { var path = EditorUtility.OpenFilePanelWithFilters("Open File", Application.dataPath, new string[] { "Data files", "dat", "All files", "*" }); LoadOffsetMatrix(path); } } EditorGUI.BeginDisabledGroup(true); SAREditorGUI.Matrix4x4Field(offsetMatrix); EditorGUILayout.Vector3Field(offsetTranslate.displayName, offsetTranslate.vector3Value); EditorGUILayout.Vector3Field(offsetRotation.displayName, offsetRotation.quaternionValue.eulerAngles); EditorGUI.EndDisabledGroup(); var newAxis = (Axis)EditorGUILayout.EnumPopup("Flip Handedness", (Axis)axis.enumValueIndex); axis.enumValueIndex = (int)newAxis; // Apply the new properties and create an Undo record. serializedObject.ApplyModifiedProperties(); }