Legacy Documentation: Version 2017.1 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

EditorGUILayout.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

Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> 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(value: AnimationCurve, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(AnimationCurve value, params GUILayoutOption[] options);
public static function CurveField(label: string, value: AnimationCurve, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(string label, AnimationCurve value, params GUILayoutOption[] options);
public static function CurveField(label: GUIContent, value: AnimationCurve, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(GUIContent label, AnimationCurve value, params GUILayoutOption[] options);
public static function CurveField(value: AnimationCurve, color: Color, ranges: Rect, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);
public static function CurveField(label: string, value: AnimationCurve, color: Color, ranges: Rect, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(string label, AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);
public static function CurveField(label: GUIContent, value: AnimationCurve, color: Color, ranges: Rect, params options: GUILayoutOption[]): AnimationCurve;
public static AnimationCurve CurveField(GUIContent label, AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);

Parameters

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.
options An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.

Returns

AnimationCurve The curve edited by the user.

Description

Make a field for editing an AnimationCurve.


Create an animation on the different axis and assign it to a GameObject.

// 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 FollowCurve 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(FollowCurve); window.Show(); }

function OnGUI() { curveX = EditorGUILayout.CurveField("Animation on X", curveX); curveY = EditorGUILayout.CurveField("Animation on Y", curveY); curveZ = EditorGUILayout.CurveField("Animation on Z", curveZ);

if(GUILayout.Button("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"); } } }
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class FollowCurve : EditorWindow { AnimationCurve curveX = AnimationCurve.Linear(0, 0, 10, 10); AnimationCurve curveY = AnimationCurve.Linear(0, 0, 10, 10); AnimationCurve curveZ = AnimationCurve.Linear(0, 0, 10, 10);

[MenuItem("Examples/Create Curve For Object")] static void Init() { FollowCurve window = (FollowCurve)EditorWindow.GetWindow(typeof(FollowCurve)); window.Show(); }

void OnGUI() { curveX = EditorGUILayout.CurveField("Animation on X", curveX); curveY = EditorGUILayout.CurveField("Animation on Y", curveY); curveZ = EditorGUILayout.CurveField("Animation on Z", curveZ);

if (GUILayout.Button("Generate Curve")) AddCurveToSelectedGameObject(); }

void AddCurveToSelectedGameObject() { if (Selection.activeGameObject) { FollowAnimationCurve comp = Selection.activeGameObject.AddComponent<FollowAnimationCurve>();

comp.SetCurves(curveX, curveY, curveZ); } else { Debug.LogError("No Game Object selected for adding an animation curve"); } } }

And the script that works with the example:

// 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)); }
using UnityEngine;
using System.Collections;

public class FollowAnimationCurve : MonoBehaviour { public AnimationCurve curveX; public AnimationCurve curveY; public AnimationCurve curveZ;

public void SetCurves(AnimationCurve xC, AnimationCurve yC, AnimationCurve zC) { curveX = xC; curveY = yC; curveZ = zC; }

void Update() { transform.position = new Vector3(curveX.Evaluate(Time.time), curveY.Evaluate(Time.time), curveZ.Evaluate(Time.time)); } }

public static function CurveField(property: SerializedProperty, color: Color, ranges: Rect, params options: GUILayoutOption[]): void;
public static void CurveField(SerializedProperty property, Color color, Rect ranges, params GUILayoutOption[] options);
public static function CurveField(property: SerializedProperty, color: Color, ranges: Rect, label: GUIContent, params options: GUILayoutOption[]): void;
public static void CurveField(SerializedProperty property, Color color, Rect ranges, GUIContent label, params GUILayoutOption[] options);

Parameters

property The curve to edit.
color The color to show the curve with.
ranges Optional rectangle that the curve is restrained within.
options An optional list of layout options that specify extra layouting properties. Any values passed in here will override settings defined by the style.
See Also: GUILayout.Width, GUILayout.Height, GUILayout.MinWidth, GUILayout.MaxWidth, GUILayout.MinHeight, GUILayout.MaxHeight, GUILayout.ExpandWidth, GUILayout.ExpandHeight.
label Optional label to display in front of the field. Pass [[GUIContent.none] to hide the label.

Description

Make a field for editing an AnimationCurve.

Did you find this page useful? Please give it a rating: