void PasteCurve() { AnimationCurve animationCurve = VegetationStudioManager.GetAnimationCurveFromClippboard(); if (animationCurve != null) { foreach (var curve in _mCurves) { Keyframe[] keyframes = animationCurve.keys; curve.Key.keys = new Keyframe[0]; for (var i = 0; i <= keyframes.Length - 1; i++) { curve.Key.AddKey(keyframes[i].time, keyframes[i].value); } break; } } }
private void OnGeneralUI() { var e = Event.current; // Selection if (e.type == EventType.MouseDown) { GUI.FocusControl(null); _SelectedCurve = null; _SelectedKeyframeIndex = -1; bool used = false; var hit = CanvasToCurve(e.mousePosition); float curvePickValue = CurveToCanvas(hit).y; // Try and select a curve foreach (var curve in _mCurves) { if (!curve.Value.Editable || !curve.Value.Visible) { continue; } var prop = curve.Key; var state = curve.Value; var animCurve = prop;//.animationCurveValue; float hitY = animCurve.length == 0 ? state.ZeroKeyConstantValue : animCurve.Evaluate(hit.x); var curvePos = CurveToCanvas(new Vector3(hit.x, hitY)); if (Mathf.Abs(curvePos.y - curvePickValue) < settings.CurvePickingDistance) { _SelectedCurve = prop; if (e.clickCount == 2 && e.button == 0) { // Create a keyframe on double-click on this curve EditCreateKeyframe(animCurve, hit, true, state.ZeroKeyConstantValue); SaveCurve(); } else if (e.button == 1) { // Curve context menu var menu = new GenericMenu(); menu.AddItem(new GUIContent("Add Key"), false, (x) => { var action = (MenuAction)x; var curveValue = action.Curve;//.animationCurveValue; //TUDO event to update object //action.curve.serializedObject.Update(); EditCreateKeyframe(curveValue, hit, true, 0f); SaveCurve(); //TUDO event to update object //action.curve.serializedObject.ApplyModifiedProperties(); }, new MenuAction(prop, hit)); menu.ShowAsContext(); e.Use(); used = true; } } } if (e.clickCount == 2 && e.button == 0 && _SelectedCurve == null) { // Create a keyframe on every curve on double-click foreach (var curve in _mCurves) { if (!curve.Value.Editable || !curve.Value.Visible) { continue; } var prop = curve.Key; var state = curve.Value; var animCurve = prop;//.animationCurveValue; EditCreateKeyframe(animCurve, hit, e.alt, state.ZeroKeyConstantValue); SaveCurve(); } } else if (!used && e.button == 1) { // Global context menu var menu = new GenericMenu(); menu.AddItem(new GUIContent("Add Key At Position"), false, () => ContextMenuAddKey(hit, false)); menu.AddItem(new GUIContent("Add Key On Curves"), false, () => ContextMenuAddKey(hit, true)); menu.AddItem(new GUIContent("Copy Curve"), false, () => CopyCurve()); if (VegetationStudioManager.GetAnimationCurveFromClippboard() != null) { menu.AddItem(new GUIContent("Paste Curve"), false, () => PasteCurve()); } menu.ShowAsContext(); } e.Use(); } // Delete selected key(s) if (e.type == EventType.KeyDown && (e.keyCode == KeyCode.Delete || e.keyCode == KeyCode.Backspace)) { if (_SelectedKeyframeIndex != -1 && _SelectedCurve != null) { var animCurve = _SelectedCurve;//.animationCurveValue; var length = animCurve.length; if (_mCurves[_SelectedCurve].MinPointCount < length && length >= 0) { EditDeleteKeyframe(animCurve, _SelectedKeyframeIndex); _SelectedKeyframeIndex = -1; SaveCurve(); } e.Use(); } } }