dijital
December 14, 2012, 5:25pm
1
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!
dijital
December 18, 2012, 1:51am
2
Iāll take that as a ānoā then.
Try this
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.
26 Likes
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
Thank you!! Thatās a very neat piece of code there!
Cheers
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.
Itās for AnimationCurve property.
Not Animation window!
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.
Ross_S
March 27, 2014, 11:41am
10
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
I also think this could be incredibly useful, but am unclear on how to install/use it.
dijital
October 23, 2014, 1:43pm
12
Havenāt logged in in a long time, Thanks!
imlabel
November 24, 2014, 10:07am
13
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.
define a variable of type AnimationCurve, and in the āinspectorā property panel, youāll see it,
Thanks a lot for that script :)))
Is it possible to do the same thing for the Particle system curves?
For those just add it as a preset. Then select it when want to āpasteā it.
1 Like
wuhuan
June 30, 2016, 12:54am
17
2 Likes
Awesome!!!
For those not knowing how to use:
Create Editor folder in your project (I did it within my Scripts folder, ending with Scrips\Editor)
Create C# script, I named it CurveCopier (Obviously, move this script into the editor folder if it is not there yet)
Edit this script, kill all its contents and place the above script within it.
4.SAVE
Now look next to your curve property on the script where you defined your curve⦠a small āCā button appeared
Click that button and a āPā button will appear
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.
2 Likes
AShim-3D:
Try this
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.
I know this is really old, but thank you
1 Like