EditorGUI.CurveField 曲线字段
static function CurveField (position : Rect, value : AnimationCurve) : AnimationCurve
static function CurveField (position : Rect, label : string, value : AnimationCurve) : AnimationCurve
static function CurveField (position : Rect, label : GUIContent, value : AnimationCurve) : AnimationCurve
static function CurveField (position : Rect, value : AnimationCurve, color : Color, ranges : Rect) : AnimationCurve
static function CurveField (position : Rect, label : string, value : AnimationCurve, color : Color, ranges : Rect) : AnimationCurve
static function CurveField (position : Rect, label : GUIContent, value : AnimationCurve, color : Color, ranges : Rect) : AnimationCurve
Parameters参数
- positionRectangle on the screen to use for the field.
屏幕上的矩形区域 - labelOptional label to display above the field.
该字段上面显示的可选标签 - valueThe value to edit. // 编辑的值
- colorThe color to show the curve with.
显示曲线的颜色 - rangesOptional rectangle that the curve is restrained within.
限制曲线的可选矩形区域
Returns
AnimationCurve - The curve edited by the user.
返回AnimationCurve - 用户编辑的曲线。
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//用法:为所需的游戏物体,生成X、Y、Z曲线// 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));}