Version: 2023.1
public static AnimationCurve CurveField (AnimationCurve value, params GUILayoutOption[] options);
public static AnimationCurve CurveField (string label, AnimationCurve value, params GUILayoutOption[] options);
public static AnimationCurve CurveField (GUIContent label, AnimationCurve value, params GUILayoutOption[] options);
public static AnimationCurve CurveField (AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);
public static AnimationCurve CurveField (string label, AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);
public static AnimationCurve CurveField (GUIContent label, AnimationCurve value, Color color, Rect ranges, params GUILayoutOption[] options);

参数

label (可选)显示在字段前的标签。
value 要编辑的曲线。
color 显示曲线时使用的颜色。
ranges 约束曲线范围的可选矩形。
options 一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

返回

AnimationCurve 用户编辑的曲线。

描述

创建一个用于编辑 AnimationCurve 的字段。


在其他轴上创建动画并将其分配给游戏对象。

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"); } } }

以及与该示例结合使用的脚本:

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 void CurveField (SerializedProperty property, Color color, Rect ranges, params GUILayoutOption[] options);
public static void CurveField (SerializedProperty property, Color color, Rect ranges, GUIContent label, params GUILayoutOption[] options);

参数

property 要编辑的曲线。
color 显示曲线时使用的颜色。
ranges 约束曲线范围的可选矩形。
options 一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight
label (可选)显示在字段前的标签。传递 [[GUIContent.none] 以隐藏标签。

描述

创建一个用于编辑 AnimationCurve 的字段。