public override void OnGUI(Rect position, ReflectedProperty property, GUIContent label = null) { guiRect.SetRect(position); if (style == null) { style = new GUIStyle(GUI.skin.box); } if (graphTexture == null) { graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true); } curve = (ResponseCurve)property.Value ?? new ResponseCurve(); if (property.IsExpanded) { EditorGUIX.Foldout(guiRect, property); } if (!property.IsExpanded) { DrawGraph(64, 32); GUIContent content = EditorGUIX.TempLabel(curve.ShortDisplayString); content.image = graphTexture; style.alignment = TextAnchor.MiddleLeft; GUI.Box(guiRect.GetFieldRect(2), content, style); content.image = null; if (Event.current.type == EventType.MouseDown) { if (position.Contains(Event.current.mousePosition)) { property.IsExpanded = true; Event.current.Use(); } } return; } GUIRect[] splits = guiRect.SplitHorizontal(0.5f); GUIRect left = splits[0]; GUIRect right = splits[1]; DrawGraph(right.GetRect().width, right.GetRect().height); GUIContent graphContent = EditorGUIX.TempLabel(string.Empty); graphContent.image = graphTexture; GUI.Box(right.GetRect(), graphContent, style); graphContent.image = null; float oldWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("curveType")); EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("slope")); EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("exp")); EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("vShift")); EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("hShift")); EditorGUIX.PropertyField(left.GetFieldRect(), property.FindProperty("threshold")); Rect lineRect = left.GetFieldRect(); Rect toggleRect = new Rect(lineRect) { width = EditorGUIUtility.labelWidth + 16f }; Rect selectRect = new Rect(lineRect) { x = lineRect.x + toggleRect.width, width = lineRect.width - toggleRect.width }; EditorGUIX.PropertyField(toggleRect, property.FindProperty("invert")); int idx = EditorGUI.Popup(selectRect, 0, presetCurveNames); property.Value = GetPreset(presetCurveNames[idx], curve); EditorGUIUtility.labelWidth = oldWidth; property.ApplyChanges(); }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { if (graphTexture == null) { graphTexture = new Texture2D(1, 1, TextureFormat.RGBA32, true); } curve = SerializedPropertyUtil.GetTargetObjectOfProperty(property) as ResponseCurve ?? new ResponseCurve(); GUIRect rect = new GUIRect(position); isCurveShown = curve.__editorOnlyFoldout__ = EditorGUI.Foldout(rect.GetFieldRect(), curve.__editorOnlyFoldout__, label.text); GUIStyle style = new GUIStyle(GUI.skin.box); if (!isCurveShown) { DrawGraph(64, 32); GUIContent content = new GUIContent(); content.text = curve.DisplayString; content.image = graphTexture; style.alignment = TextAnchor.MiddleLeft; GUI.Box(rect.GetFieldRect(2), content, style); return; } GUIRect[] splits = rect.SplitHorizontal(0.5f); GUIRect left = splits[0]; GUIRect right = splits[1]; DrawGraph(right.GetRect().width, right.GetRect().height); GUIContent graphContent = new GUIContent(); graphContent.image = graphTexture; GUI.Box(right.GetRect(), graphContent, style); float oldWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 100; DrawerUtil.PushIndentLevel(1); EditorGUI.BeginChangeCheck(); { EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("curveType")); EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("slope")); EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("exp")); EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("vShift")); EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("hShift")); EditorGUI.PropertyField(left.GetFieldRect(), property.FindPropertyRelative("threshold")); GUIRect lineRect = new GUIRect(left.GetFieldRect()); GUIRect[] lineRectParts = lineRect.SplitHorizontal(0.5f); EditorGUI.PropertyField(lineRectParts[0].GetRect(), property.FindPropertyRelative("invert")); if (GUI.Button(lineRectParts[1].GetRect(), "Reset Curve")) { property.FindPropertyRelative("curveType").intValue = (int)ResponseCurveType.Polynomial; property.FindPropertyRelative("slope").floatValue = 1f; property.FindPropertyRelative("exp").floatValue = 1f; property.FindPropertyRelative("vShift").floatValue = 0f; property.FindPropertyRelative("hShift").floatValue = 0f; property.FindPropertyRelative("threshold").floatValue = 0f; property.FindPropertyRelative("invert").boolValue = false; } } DrawerUtil.PopIndentLevel(); EditorGUIUtility.labelWidth = oldWidth; if (EditorGUI.EndChangeCheck()) { property.serializedObject.ApplyModifiedProperties(); } }