public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { SerializedProperty enabled = prop.FindPropertyRelative("enabled"); SerializedProperty outputFolder = prop.FindPropertyRelative("outputFolder"); SerializedProperty rate = prop.FindPropertyRelative("rate"); SerializedProperty captureProcessedImage = prop.FindPropertyRelative("captureProcessedImage"); SerializedProperty stopTime = prop.FindPropertyRelative("stopTime"); float lineHeight = MyRoutines.GetEditorGUIStandardLineHeight(); EditorGUI.PropertyField(new Rect(pos.x, pos.y, pos.width, lineHeight), enabled, new GUIContent("Eye Test", enabled.tooltip)); if (enabled.boolValue) { EditorGUI.indentLevel++; string tooltip = MyRoutines.GetTooltip(typeof(EyeTest), "outputFolder"); float ypos = MyRoutines.GetEditorGUINextControlYPos(pos.y); EditorGUI.PropertyField(new Rect(pos.x, ypos, pos.width, lineHeight), captureProcessedImage); ypos = MyRoutines.GetEditorGUINextControlYPos(ypos); Rect controlRect = new Rect(pos.x, ypos, pos.width, lineHeight); //lineheight //MyRoutines.CreateScreenRecordingControl (outputFolder.displayName, tooltip, controlRect, outputFolder, rate, "EyeTestData"); MyRoutines.CreateOutputPathControl(outputFolder.displayName, tooltip, controlRect, outputFolder, false, string.Empty, string.Empty); if (string.IsNullOrEmpty(outputFolder.stringValue) == false) { ypos = MyRoutines.GetEditorGUINextControlYPos(ypos); controlRect = new Rect(pos.x, ypos, pos.width, lineHeight * 2); EditorGUI.HelpBox(controlRect, "The contents of the selected folder will be overwritten.", MessageType.Warning); ypos = MyRoutines.GetEditorGUINextControlYPos(ypos) + lineHeight; } else { ypos = MyRoutines.GetEditorGUINextControlYPos(ypos); } EditorGUI.PropertyField(new Rect(pos.x, ypos, pos.width, lineHeight), rate); ypos = MyRoutines.GetEditorGUINextControlYPos(ypos); EditorGUI.PropertyField(new Rect(pos.x, ypos, pos.width, lineHeight), stopTime); if (stopTime.floatValue <= 0) { stopTime.floatValue = Mathf.Infinity; } EditorGUI.indentLevel--; } }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { SerializedProperty outputPath = prop.FindPropertyRelative("outputPath"); SerializedProperty dataCaptureRate = prop.FindPropertyRelative("dataCaptureRate"); SerializedProperty stopTime = prop.FindPropertyRelative("stopTime"); float lineHeight = MyRoutines.GetEditorGUIStandardLineHeight(); DataOutputDetails outputDetails = fieldInfo.GetValue(prop.serializedObject.targetObject) as DataOutputDetails; bool isFile = outputDetails.isFile; string fileExtension = outputDetails.fileExtension; string defaultFileName = outputDetails.defaultFileName; string tooltip = MyRoutines.GetTooltip(typeof(DataOutputDetails), "outputPath"); //create the output path control MyRoutines.CreateOutputPathControl(outputPath.displayName, tooltip, pos, outputPath, isFile, fileExtension, defaultFileName); float ypos; if (string.IsNullOrEmpty(outputPath.stringValue) == false) { ypos = MyRoutines.GetEditorGUINextControlYPos(pos.y); Rect controlRect = new Rect(pos.x, ypos, pos.width, lineHeight * 2); EditorGUI.HelpBox(controlRect, "The contents of the selected folder will be overwritten.", MessageType.Warning); ypos = MyRoutines.GetEditorGUINextControlYPos(ypos) + lineHeight; } else { ypos = MyRoutines.GetEditorGUINextControlYPos(pos.y); } //create the datacapture rate field tooltip = MyRoutines.GetTooltip(typeof(DataOutputDetails), "dataCaptureRate"); string rateDisplayName = outputDetails.rateFieldLabel; EditorGUI.PropertyField(new Rect(pos.x, ypos, pos.width, lineHeight), dataCaptureRate, new GUIContent(rateDisplayName, tooltip)); //create the stopTime field ypos = MyRoutines.GetEditorGUINextControlYPos(ypos); EditorGUI.PropertyField(new Rect(pos.x, ypos, pos.width, lineHeight), stopTime); if (stopTime.floatValue <= 0) { stopTime.floatValue = Mathf.Infinity; } }
public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { SerializedProperty showScale = prop.FindPropertyRelative("showScale"); SerializedProperty curveColor = prop.FindPropertyRelative("curveColor"); SerializedProperty yScale = prop.FindPropertyRelative("yScale"); SerializedProperty xScale = prop.FindPropertyRelative("xScale"); SerializedProperty yMaxScale = prop.FindPropertyRelative("yMaxScale"); SerializedProperty xMaxScale = prop.FindPropertyRelative("xMaxScale"); SerializedProperty curve = prop.FindPropertyRelative("curve"); SerializedProperty curveType = prop.FindPropertyRelative("curveType"); float padding = MyRoutines.GetEditorGUIControlSpacing(); float lineHeight = MyRoutines.GetEditorGUIStandardLineHeight(); float yPos = pos.y; float curveWidth = pos.width; string tooltip = MyRoutines.GetTooltip(prop.serializedObject.targetObject.GetType(), prop.name); GUIContent gContent = new GUIContent(label.text, tooltip); //prop.tooltip doesn't work //draw the slider if required if (showScale.boolValue) { curveWidth = 75; EditorGUI.IntSlider(new Rect(pos.x, yPos, pos.width - curveWidth, lineHeight), yScale, 0, yMaxScale.intValue, gContent); } //draw curve if (showScale.boolValue) { int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; EditorGUI.CurveField(new Rect(pos.x + (pos.width - curveWidth) + padding, yPos, curveWidth - padding, lineHeight), curve, curveColor.colorValue, new Rect(0, 0, xScale.intValue, yScale.intValue), GUIContent.none); EditorGUI.indentLevel = indent; } else { EditorGUI.CurveField(new Rect(pos.x, yPos, curveWidth - padding, lineHeight), curve, curveColor.colorValue, new Rect(0, 0, xMaxScale.intValue, yScale.intValue), gContent); } //buttons yPos = MyRoutines.GetEditorGUINextControlYPos(yPos); float buttonWidth = (pos.width / 3) - padding; GUIContent buttonGUIContent = new GUIContent("Reset", "Reset the curve to its default setting."); if (GUI.Button(new Rect(pos.x, yPos, buttonWidth, lineHeight), buttonGUIContent)) { //reset the animation curve //get a reference to the curve ScaledCurve c = (ScaledCurve)fieldInfo.GetValue(prop.serializedObject.targetObject); //reset the curve curve.animationCurveValue = c.ResetCurve(); } buttonGUIContent = new GUIContent("Save", "Saves curve data to an asset file."); if (GUI.Button(new Rect(pos.x + buttonWidth + padding, yPos, buttonWidth, lineHeight), buttonGUIContent)) { string path = EditorUtility.SaveFilePanelInProject("Save Curve", "CurveData", "asset", "Please enter a file name to save the curve data to."); if (string.IsNullOrEmpty(path) == false) { //save curve data as scriptable object instance SerializedCurve asset = ScriptableObject.CreateInstance <SerializedCurve> (); asset.curve = new SerializableCurve(curve.animationCurveValue); asset.curveType = curveType.stringValue; AssetDatabase.CreateAsset(asset, path); AssetDatabase.SaveAssets(); AssetDatabase.Refresh(); } } buttonGUIContent = new GUIContent("Load", "Loads curve data from an asset file."); if (GUI.Button(new Rect(pos.x + ((buttonWidth + padding) * 2), yPos, buttonWidth, lineHeight), buttonGUIContent)) { string path = EditorUtility.OpenFilePanel("Load Curve", Application.dataPath, "asset"); if (string.IsNullOrEmpty(path) == false) { //load curve data from scriptable object path = path.Replace(Application.dataPath, "Assets"); SerializedCurve asset = AssetDatabase.LoadAssetAtPath <SerializedCurve>(path); if (asset.curveType == curveType.stringValue) { //correct type - replace curve with serialized curve data curve.animationCurveValue = asset.curve.ToAnimationCurve(); } else { EditorUtility.DisplayDialog("Error", "Saved curve data is of the wrong type.", "OK"); } } } }