static void DoMinMaxCurvesField(Rect position, int id, SerializedProperty propertyMax, SerializedProperty propertyMin, SerializedProperty scalar, Color color, Color backgroundColor) { var evt = Event.current; if (MinMaxCurveEditorWindow.visible && Event.current.type != EventType.Layout && GUIUtility.keyboardControl == id) { if (s_CurveId != id) { s_CurveId = id; if (MinMaxCurveEditorWindow.visible) { MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color); MinMaxCurveEditorWindow.ShowPopup(GUIView.current); } } else { if (MinMaxCurveEditorWindow.visible && Event.current.type == EventType.Repaint) { MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color); MinMaxCurveEditorWindow.instance.Repaint(); } } } switch (evt.GetTypeForControl(id)) { case EventType.MouseDown: if (position.Contains(evt.mousePosition)) { s_CurveId = id; GUIUtility.keyboardControl = id; MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color); MinMaxCurveEditorWindow.ShowPopup(GUIView.current); evt.Use(); GUIUtility.ExitGUI(); } break; case EventType.Repaint: if (propertyMin != null) { EditorGUIUtility.DrawRegionSwatch(position, propertyMax, propertyMin, color, backgroundColor); } else { EditorGUIUtility.DrawCurveSwatch(position, null, propertyMax, color, backgroundColor); } EditorStyles.colorPickerBox.Draw(position, GUIContent.none, id, false); break; case EventType.ExecuteCommand: if (s_CurveId == id && evt.commandName == "CurveChanged") { GUI.changed = true; AnimationCurvePreviewCache.ClearCache(); HandleUtility.Repaint(); if (propertyMax != null && MinMaxCurveEditorWindow.instance.maxCurve != null) { propertyMax.animationCurveValue = MinMaxCurveEditorWindow.instance.maxCurve; } if (propertyMin != null) { propertyMin.animationCurveValue = MinMaxCurveEditorWindow.instance.minCurve; } } break; case EventType.KeyDown: if (evt.MainActionKeyForControl(id)) { s_CurveId = id; MinMaxCurveEditorWindow.SetCurves(propertyMax, propertyMin, scalar, color); MinMaxCurveEditorWindow.ShowPopup(GUIView.current); evt.Use(); GUIUtility.ExitGUI(); } break; } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Init(property); Rect fieldRect; var mode = (MinMaxCurveState)m_Property.mode.intValue; // Only curves require manually drawing a label, the controls for scalar handle the label drawing themselves. if (!m_Property.mode.hasMultipleDifferentValues && (mode == MinMaxCurveState.k_Scalar || mode == MinMaxCurveState.k_TwoScalars)) { fieldRect = position; } else { fieldRect = EditorGUI.PrefixLabel(position, label); } // Mode fieldRect.width -= s_Styles.stateButtonWidth; var modeRect = new Rect(fieldRect.xMax, fieldRect.y, s_Styles.stateButtonWidth, fieldRect.height); EditorGUI.BeginProperty(modeRect, GUIContent.none, m_Property.mode); EditorGUI.BeginChangeCheck(); //GUI.Button(modeRect, "T"); // worrks int newSelection = EditorGUI.Popup(modeRect, null, m_Property.mode.intValue, s_Styles.modes, EditorStyles.minMaxStateDropdown); if (EditorGUI.EndChangeCheck()) { m_Property.mode.intValue = newSelection; InitCurves(); AnimationCurvePreviewCache.ClearCache(); } EditorGUI.EndProperty(); if (m_Property.mode.hasMultipleDifferentValues) { EditorGUI.LabelField(fieldRect, GUIContent.Temp("-")); return; } switch (mode) { case MinMaxCurveState.k_Scalar: EditorGUI.PropertyField(fieldRect, m_Property.constantMax, label); break; case MinMaxCurveState.k_Curve: DoMinMaxCurvesField(fieldRect, m_Property.curveMax.GetHashCode(), m_Property.curveMax, null, m_Property.curveMultiplier, s_Styles.curveColor, s_Styles.curveBackgroundColor); break; case MinMaxCurveState.k_TwoCurves: DoMinMaxCurvesField(fieldRect, m_Property.curveMin.GetHashCode(), m_Property.curveMax, m_Property.curveMin, m_Property.curveMultiplier, s_Styles.curveColor, s_Styles.curveBackgroundColor); break; case MinMaxCurveState.k_TwoScalars: float fieldWidth = (fieldRect.width - EditorGUIUtility.labelWidth) * 0.5f; var rectMin = new Rect(fieldRect.x, fieldRect.y, fieldRect.width - fieldWidth - (s_Styles.floatFieldDragWidth * 0.5f), fieldRect.height); EditorGUI.PropertyField(rectMin, m_Property.constantMin, label); var rectMax = new Rect(rectMin.xMax + s_Styles.floatFieldDragWidth, fieldRect.y, fieldWidth - (s_Styles.floatFieldDragWidth * 0.5f), fieldRect.height); var rectMaxDragArea = new Rect(rectMax.xMin - s_Styles.floatFieldDragWidth, fieldRect.y, s_Styles.floatFieldDragWidth, fieldRect.height); EditorGUI.BeginProperty(rectMax, GUIContent.none, m_Property.constantMax); EditorGUI.BeginChangeCheck(); float newConstantMax = EditorGUI.DoFloatField(EditorGUI.s_RecycledEditor, rectMax, rectMaxDragArea, m_Property.constantMax.GetHashCode(), m_Property.constantMax.floatValue, "g7", EditorStyles.numberField, true); if (EditorGUI.EndChangeCheck()) { m_Property.constantMax.floatValue = newConstantMax; } EditorGUI.EndProperty(); break; } }