Legacy Documentation: Version 4.6.2
Language: English
  • C#
  • JS
  • Boo

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUI.CurveField

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

public static function CurveField(position: Rect, value: AnimationCurve): AnimationCurve;
public static AnimationCurve CurveField(Rect position, AnimationCurve value);
public static def CurveField(position as Rect, value as AnimationCurve) as AnimationCurve
public static function CurveField(position: Rect, label: string, value: AnimationCurve): AnimationCurve;
public static AnimationCurve CurveField(Rect position, string label, AnimationCurve value);
public static def CurveField(position as Rect, label as string, value as AnimationCurve) as AnimationCurve
public static function CurveField(position: Rect, label: GUIContent, value: AnimationCurve): AnimationCurve;
public static AnimationCurve CurveField(Rect position, GUIContent label, AnimationCurve value);
public static def CurveField(position as Rect, label as GUIContent, value as AnimationCurve) as AnimationCurve
public static function CurveField(position: Rect, value: AnimationCurve, color: Color, ranges: Rect): AnimationCurve;
public static AnimationCurve CurveField(Rect position, AnimationCurve value, Color color, Rect ranges);
public static def CurveField(position as Rect, value as AnimationCurve, color as Color, ranges as Rect) as AnimationCurve
public static function CurveField(position: Rect, label: string, value: AnimationCurve, color: Color, ranges: Rect): AnimationCurve;
public static AnimationCurve CurveField(Rect position, string label, AnimationCurve value, Color color, Rect ranges);
public static def CurveField(position as Rect, label as string, value as AnimationCurve, color as Color, ranges as Rect) as AnimationCurve
public static function CurveField(position: Rect, label: GUIContent, value: AnimationCurve, color: Color, ranges: Rect): AnimationCurve;
public static AnimationCurve CurveField(Rect position, GUIContent label, AnimationCurve value, Color color, Rect ranges);
public static def CurveField(position as Rect, label as GUIContent, value as AnimationCurve, color as Color, ranges as Rect) as AnimationCurve

Parameters

position Rectangle on the screen to use for the field.
label Optional label to display in front of the field.
value The curve to edit.
color The color to show the curve with.
ranges Optional rectangle that the curve is restrained within.

Returns

AnimationCurve The curve edited by the user.

Description

Make a field for editing an AnimationCurve.


Curve field in an Editor Window.

	// Makes the selected GameObject follow the animation curve.
	//
	// Usage: Generate the curves for X,Y and Z axis of your desired GameObject
	// Select an Object and click Generate Curve.
	// Press Play and see your object moving.
	
	
	class EditorGUICurveField extends EditorWindow {
	
		var curveX : AnimationCurve = AnimationCurve.Linear(0,0,10,10);
		var curveY : AnimationCurve = AnimationCurve.Linear(0,0,10,10);
		var curveZ : AnimationCurve = AnimationCurve.Linear(0,0,10,10);
	
		@MenuItem("Examples/Create Curve For Object")
		static function Init() {
			var window = GetWindow(EditorGUICurveField);
			window.position = Rect(0,0,200,100);
			window.Show();
		}
		
		function OnGUI() {
			curveX = EditorGUI.CurveField(
				Rect(3,3,position.width-6,15),
				"Animation on X", curveX);
			curveY = EditorGUI.CurveField(
				Rect(3,20,position.width-6,15),
				"Animation on Y", curveY);
			curveZ = EditorGUI.CurveField(
				Rect(3,45,position.width-6,15),
				"Animation on Z", curveZ);
			
			if(GUI.Button(Rect(3,60,position.width-6,30),"Generate Curve"))
				AddCurveToSelectedGameObject();
		}
		
		function AddCurveToSelectedGameObject() {
			if(Selection.activeGameObject) {
				var comp : FollowAnimationCurve = 
					Selection.activeGameObject.AddComponent(FollowAnimationCurve);
					comp.SetCurves(curveX, curveY, curveZ);
			} else {
				Debug.LogError("No Game Object selected for adding an animation curve");
			}
		}
	}

And the script attached to this editor script:

	// FollowAnimationCurve.js
	// This script has to go outside of the Editor Folder.
	
	var curveX : AnimationCurve;
	var curveY : AnimationCurve;
	var curveZ : AnimationCurve;
	
	function SetCurves(xC : AnimationCurve, yC : AnimationCurve, zC : AnimationCurve) {
		curveX = xC;
		curveY = yC;
		curveZ = zC;
	}
	function Update() {
		transform.position = Vector3(curveX.Evaluate(Time.time),
									curveY.Evaluate(Time.time),
									curveZ.Evaluate(Time.time));
	}
public static function CurveField(position: Rect, value: SerializedProperty, color: Color, ranges: Rect): void;
public static void CurveField(Rect position, SerializedProperty value, Color color, Rect ranges);
public static def CurveField(position as Rect, value as SerializedProperty, color as Color, ranges as Rect) as void

Parameters

position Rectangle on the screen to use for the field.
property The curve to edit.
color The color to show the curve with.
ranges Optional rectangle that the curve is restrained within.

Description

Make a field for editing an AnimationCurve.