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参数

Returns

AnimationCurve - The curve edited by the user.

返回AnimationCurve - 用户编辑的曲线。

Description描述

Make a field for editing an AnimationCurve.

制作一个曲线字段,用来编辑动画曲线。

EditorGUI.CurveField 曲线字段

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));
}
最后修改:2011年6月23日 Thursday 18:11

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。