Hi, I have a racing game I am working on, I have setup an acceleration curve to control a non player car and would like to apply that curve to my other cars. Is there a way to copy and paste a curve? as it is mind numbing trying to do it manually. Thanks!
Try this Code (csharp): using UnityEngine; using UnityEditor; [CustomPropertyDrawer(typeof(AnimationCurve))] public class CurvePropertyDrawer: PropertyDrawer { private const int _buttonWidth = 12; private static Keyframe[] _buffer; private static WrapMode _preWrapMode; private static WrapMode _postWrapMode; public override void OnGUI(Rect pos, SerializedProperty prop, GUIContent label) { prop.animationCurveValue = EditorGUI.CurveField( new Rect(pos.x, pos.y, pos.width - _buttonWidth * 2, pos.height), label, prop.animationCurveValue ); // Copy if ( GUI.Button( new Rect(pos.x + pos.width - _buttonWidth * 2, pos.y, _buttonWidth, pos.height), "" ) ) { _buffer = prop.animationCurveValue.keys; _preWrapMode = prop.animationCurveValue.preWrapMode; _postWrapMode = prop.animationCurveValue.postWrapMode; } GUI.Label( new Rect(pos.x + pos.width - _buttonWidth * 2, pos.y, _buttonWidth, pos.height), "C" ); // Paste if (_buffer == null) return; if ( GUI.Button( new Rect(pos.x + pos.width - _buttonWidth, pos.y, _buttonWidth, pos.height), "" ) ) { AnimationCurve newAnimationCurve = new AnimationCurve(_buffer); newAnimationCurve.preWrapMode = _preWrapMode; newAnimationCurve.postWrapMode = _postWrapMode; prop.animationCurveValue = newAnimationCurve; } GUI.Label( new Rect(pos.x + pos.width - _buttonWidth, pos.y, _buttonWidth, pos.height), "P" ); } // OnGUI() } // class CurvePropertyDrawer Put this script in Editor folder.
Hey there, just tried out that script; works like a charm! I think this should be a standard feature. I can't thank you enough for saving me soooo much time. I'm using Animation Curves to control object velocity for special maneuvers. Time to make some magic
Hello, I put this script in Editor folder but I can't see any copy/paste functionality in Animation window. Could you please explain me how to use it? Thanks in advance, Alejandro.
I've added this code to the Editor folder but I don't know how to use it or what to do. Any help will be appreciated. Thanks in advance.
Hi - this seems awesome for animationCurves defined in your own scripts - but doesn't work for animationCurves that you've added to animations... (in the Curve section...) any c
Awesome!!! For those not knowing how to use: 1. Create Editor folder in your project (I did it within my Scripts folder, ending with Scrips\Editor) 2. Create C# script, I named it CurveCopier (Obviously, move this script into the editor folder if it is not there yet) 3. Edit this script, kill all its contents and place the above script within it. 4.SAVE 5. Now look next to your curve property on the script where you defined your curve... a small "C" button appeared 6. Click that button and a "P" button will appear 7. Now go to your target script with the curve you want to paste to, click the "P" and Voila!!! (In my case, the curve picture suddenly matched my source curve, proving it worked. Thanks again, I was just about to start typing values manually.
The script is useful. It adds Copy and Paste button next to the animation curve indeed. But it causes the Tooltip() on the animation curve field to disappear. How do you fix that?
Thank you! This also solves the Tooltip not appearing issue. I had to remove the EditorGUI.PrefixLabel inside AnimationCurveGUI.OnGUI to avoid duplicating the label (I'm using Unity 2019.1)