public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { EditorGUI.BeginProperty(position, label, property); var _ease = property.FindPropertyRelative("ease"); { var easeRect = position; easeRect.height = EditorGUIUtility.singleLineHeight; var foldoutRect = easeRect; foldoutRect.width *= 0.25f; property.isExpanded = EditorGUI.Foldout(foldoutRect, property.isExpanded, label); easeRect.x += position.width * 0.3f; easeRect.width -= position.width * 0.3f; EditorGUI.PropertyField(easeRect, _ease, GUIContent.none); } if (property.isExpanded) { var dx = 15f; position.x += dx; position.width -= dx; var dy = EditorGUIUtility.standardVerticalSpacing + EditorGUIUtility.singleLineHeight; position.y += dy; position.height -= dy; var graphWidth = dy * 12 * _curveDrawer.ValueRange.width / _curveDrawer.ValueRange.height; var sliderWidth = position.width - graphWidth - dx; var sliderRect = position; sliderRect.width = sliderWidth; sliderRect.height = EditorGUIUtility.singleLineHeight; var _ex = property.FindPropertyRelative("ex"); EditorGUI.PropertyField(sliderRect, _ex); sliderRect.y += dy; var _ey = property.FindPropertyRelative("ey"); EditorGUI.PropertyField(sliderRect, _ey); sliderRect.y += dy; var _ez = property.FindPropertyRelative("ez"); EditorGUI.PropertyField(sliderRect, _ez); sliderRect.y += dy; var vp = position; vp.x += sliderWidth + dx; vp.width = graphWidth; _curveDrawer.ViewPort = vp; _curveDrawer.DrawRect(_curveDrawer.ValueRange, 0.1f, 0.4f); _curveDrawer.DrawLine(new Vector2(0, 0), new Vector2(1, 0), Color.blue * 0.5f); _curveDrawer.DrawLine(new Vector2(0, 1), new Vector2(1, 1), Color.red * 0.5f); var ep = new EaseProfile((Easing)_ease.intValue, _ex.floatValue, _ey.floatValue, _ez.floatValue); _curveDrawer.DrawCurve(x => ep.Ease(x), Color.white); } EditorGUI.EndProperty(); }
void PrepareClipsViewer(SerializedProperty clips, SerializedProperty property) { if (_clipsViewer == null) { _clipsViewer = new EditorTools.PrettyListViewer( clips.serializedObject, clips, onDrawHeader: (rect) => { var sliderRect = rect; sliderRect.height = EditorGUIUtility.singleLineHeight; sliderRect.width -= 25; DrawPreviewSlider(sliderRect, property); sliderRect.x += sliderRect.width + 5; sliderRect.width = 20; var ndc = GUI.Toggle(sliderRect, _drawCurve, "C", EditorStyles.miniButton); if (ndc != _drawCurve) { _drawCurve = ndc; _clipsViewer.headerHeight = HeaderHeight; } if (!_drawCurve) { return; } var previewRect = rect; previewRect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; previewRect.height -= EditorGUIUtility.singleLineHeight + 2 * EditorGUIUtility.standardVerticalSpacing; _curveDrawer.ViewPort = previewRect; _curveDrawer.DrawRect(_curveDrawer.ValueRange, 0.05f, 0.4f); _curveDrawer.DrawLine(new Vector2(0, 0), new Vector2(1, 0), Color.blue * 0.5f); _curveDrawer.DrawLine(new Vector2(0, 1), new Vector2(1, 1), Color.red * 0.5f); if (InPreview) { _curveDrawer.DrawLine(new Vector2(_previewCounter, -0.5f), new Vector2(_previewCounter, 1.5f), Color.yellow); } for (int i = 0; i < clips.arraySize; ++i) { var clip = clips.GetArrayElementAtIndex(i); var startTime = clip.FindPropertyRelative("startTime").floatValue; var endTime = clip.FindPropertyRelative("endTime").floatValue; var profile = clip.FindPropertyRelative("profile"); var ease = profile.FindPropertyRelative("ease").intValue; var ex = profile.FindPropertyRelative("ex").floatValue; var ey = profile.FindPropertyRelative("ey").floatValue; var ez = profile.FindPropertyRelative("ez").floatValue; var ep = new EaseProfile((Easing)ease, ex, ey, ez); var iF = (float)i / clips.arraySize; var color = new Color(iF, Mathf.Abs(iF - 0.5f), 1 - iF, 0.6f); if (i == _clipsViewer.index) { color = Color.white; } _curveDrawer.DrawCurve( x => { var x1 = (x - startTime) / (endTime - startTime); if (x1 < 0) { x1 = 0; } else if (x1 < 1) { } else { x1 = 1; } return(ep.Ease(x1)); }, color ); } }, onDrawElement: (rect, index, isActive, isFocused) => { var boxRect = rect; boxRect.width = 20; var oc = GUI.color; var iF = (float)index / _clipsViewer.count; GUI.color = new Color(iF, Mathf.Abs(iF - 0.5f), 1 - iF, 0.6f); GUI.Box(boxRect, ""); GUI.color = oc; rect.x += 20; rect.width -= 20; var child = clips.GetArrayElementAtIndex(index); if (Event.current.type == EventType.MouseDown && Event.current.button == 1 && rect.Contains(Event.current.mousePosition)) { _clipPopup.Show(child, rect); Event.current.Use(); } rect.width *= 0.5f; var childContext = child.FindPropertyRelative("context"); var childPath = child.FindPropertyRelative("propertyPath"); EditorTools.InspectorUtils.PinLabel(rect, childContext.objectReferenceValue); rect.x += rect.width; GUI.Label(rect, childPath.stringValue); }, elementHeightGetter: (index) => { return(EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing); }, onReorder: (list) => { list.serializedProperty.serializedObject.ApplyModifiedProperties(); }, onAdd: (list) => { list.serializedProperty.InsertArrayElementAtIndex(list.serializedProperty.arraySize); list.serializedProperty.serializedObject.ApplyModifiedProperties(); }, onRemove: (list) => { list.serializedProperty.DeleteArrayElementAtIndex(list.index); list.serializedProperty.serializedObject.ApplyModifiedProperties(); } ); _clipsViewer.headerHeight = HeaderHeight; } }
public GeneralTweener(EaseProfile profile, float duration) : base() { this.ease = profile; this.duration = duration; }