本文整理汇总了C#中Keyframe类的典型用法代码示例。如果您正苦于以下问题:C# Keyframe类的具体用法?C# Keyframe怎么用?C# Keyframe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Keyframe类属于命名空间,在下文中一共展示了Keyframe类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateCurve
public static AnimationCurve CreateCurve( float[] values, float[] times, bool smooth = true)
{
D.Assert( values != null && times != null, "Param == null" );
D.Assert( values.Length == times.Length, "Size not same" );
if ( values.Length != times.Length ){
D.Log("values.Length: {0} times.Length: {1}", values.Length, times.Length);
}
AnimationCurve result;
Keyframe[] ks = new Keyframe[values.Length];
for( int i = 0; i < values.Length; i ++ ) {
ks[ i ] = new Keyframe( times[ i ], values[ i ] );
}
result = new AnimationCurve( ks );
if ( smooth){
for( int i = 0; i < result.length; i++ ) {
result.SmoothTangents( i, 0 );
}
}
return result;
}
开发者ID:fengqk,项目名称:Art,代码行数:21,代码来源:ChpAnimation.cs
示例2: Start
void Start()
{
GameObject.Find("GUI Text").guiText.text = "AnimationClip sample";
AnimationClip clipA = new AnimationClip();
AnimationCurve curveA = AnimationCurve.Linear(0f, 3f, 3f, 3f);
Keyframe keyA = new Keyframe(1.5f, 10f);
curveA.AddKey(keyA);
clipA.SetCurve("", typeof(Transform), "localPosition.z", curveA);
clipA.wrapMode = WrapMode.Loop;
animation.AddClip(clipA, "anim1");
AnimationClip clipB = new AnimationClip();
AnimationCurve curveB = AnimationCurve.Linear(0f, 3f, 3f, 3f);
Keyframe key1 = new Keyframe(0.75f, 7f);
curveB.AddKey(key1);
Keyframe key2 = new Keyframe(1.5f, 3f);
curveB.AddKey(key2);
Keyframe key3 = new Keyframe(2.25f,7f);
curveB.AddKey (key3);
clipB.SetCurve("", typeof(Transform), "localPosition.z", curveB);
clipB.wrapMode = WrapMode.Loop;
animation.AddClip(clipB, "anim2");
animation.Play ("anim1");
}
开发者ID:riki-y,项目名称:Rikis-WorkSpace,代码行数:26,代码来源:chengeAnimationClip.cs
示例3: Start
// Use this for initialization
void Start()
{
GameObject[] ob_cubes;
ob_cubes = GameObject.FindGameObjectsWithTag("ob_cube");
foreach (GameObject obj in ob_cubes)
{
Vector3 move = obj.transform.position;
AnimationClip clip = new AnimationClip();
clip.legacy = true;
Keyframe[] keysX = new Keyframe[2];
keysX[0] = new Keyframe(0f, move.x - 5);
keysX[1] = new Keyframe(1f, move.x + 3);
AnimationCurve curveX = new AnimationCurve(keysX);
clip.SetCurve("", typeof(Transform), "localPosition.x", curveX);
clip.wrapMode = WrapMode.PingPong;
Keyframe[] keysY = new Keyframe[2];
keysY[0] = new Keyframe(0f, move.y);
keysY[1] = new Keyframe(1f, move.y);
AnimationCurve curveY = new AnimationCurve(keysY);
clip.SetCurve("", typeof(Transform), "localPosition.y", curveY);
Keyframe[] keysZ = new Keyframe[2];
keysZ[0] = new Keyframe(0f, move.z);
keysZ[1] = new Keyframe(1f, move.z);
AnimationCurve curveZ = new AnimationCurve(keysZ);
clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);
Animation animation = obj.GetComponent<Animation>();
animation.AddClip(clip, "clip1");
animation.Play("clip1");
}
}
开发者ID:yamagamirenya,项目名称:yamagamirenya.github.io,代码行数:33,代码来源:Obstacle_animation.cs
示例4: Test_New2
public void Test_New2()
{
var frame = new Keyframe (1, new Vector3(1,2,3));
Assert.AreEqual (1, frame.Time);
Assert.AreEqual (new Vector3(1,2,3), frame.Value);
}
开发者ID:weimingtom,项目名称:erica,代码行数:7,代码来源:TestKeyframe.cs
示例5: Drift
/// <summary>
/// Create drift orbit
/// </summary>
public void Drift(Vector3 origin, float speed, out AnimationCurve[] ac)
{
Keyframe[][] kf = new Keyframe[2][];
kf[X] = new Keyframe[driftPoints + 2];
kf[Y] = new Keyframe[driftPoints + 2];
kf[X][0] = new Keyframe(0, origin.x, inTangent, outTangent);
kf[Y][0] = new Keyframe(0, origin.y, inTangent, outTangent);
for (int i = 1; i <= driftPoints; i++)
{
kf[X][i] = new Keyframe(i / speed, origin.x + (driftX * Random.value), inTangent, outTangent);
kf[Y][i] = new Keyframe(i / speed, origin.y + (driftY * Random.value), inTangent, outTangent);
}
kf[X][driftPoints + 1] = new Keyframe((driftPoints + 1) / speed, origin.x, inTangent, outTangent);
kf[Y][driftPoints + 1] = new Keyframe((driftPoints + 1) / speed, origin.y, inTangent, outTangent);
// Curves
ac = new AnimationCurve[2];
ac[X] = new AnimationCurve(kf[X]);
ac[Y] = new AnimationCurve(kf[Y]);
// Smooth curves
for (int i = 0; i < ac[X].keys.Length; ++i)
{
ac[X].SmoothTangents(i, 0);
ac[Y].SmoothTangents(i, 0);
}
}
开发者ID:syanenko,项目名称:graphics,代码行数:33,代码来源:Orbits.cs
示例6: ApplyPose
public void ApplyPose(Keyframe pose)
{
currentPose = pose;
SetLocalTranslation(pose.GetTranslation());
poseRot = pose.GetRotation();
UpdateTransform();
}
开发者ID:ajmd17,项目名称:apexengine-sharp,代码行数:7,代码来源:Bone.cs
示例7: CreateAnimationClip
void CreateAnimationClip()
{
CameraShakeTool tool = target as CameraShakeTool;
List<Keyframe> keyframeList = new List<Keyframe>();
foreach (Vector2 v in tool.value)
{
Keyframe k = new Keyframe(v.x, v.y);
keyframeList.Add(k);
}
AnimationClip clip = new AnimationClip();
#if UNITY_5
clip.legacy = true;
#endif
clip.wrapMode = WrapMode.Once;
clip.SetCurve("", typeof(Transform), "localPosition.x", new AnimationCurve(keyframeList.ToArray()));
string activePath = AssetDatabase.GetAssetPath(Selection.activeObject);
string directory = Path.GetDirectoryName(activePath);
string filename = Path.GetFileNameWithoutExtension(activePath);
string path = directory + "/" + filename + ".anim";
string clipPath = AssetDatabase.GenerateUniqueAssetPath(path);
AssetDatabase.CreateAsset(clip, clipPath);
}
开发者ID:kimsama,项目名称:Unity-CameraShakeTool,代码行数:28,代码来源:CameraShakeToolEditor.cs
示例8: Start
void Start()
{
moves[0] = new Vector3( 0f, 1f, 0f);
moves[1] = new Vector3(-3f, 1f, 5f);
moves[2] = new Vector3( 3f, 1f, 5f);
moves[3] = new Vector3(-3f, 1f, -3f);
moves[4] = new Vector3( 3f, 1f, -3f);
for(int i=0;i<5;i++){
cubes[i] = GameObject.Find ("BoardCube"+i);
Vector3 move = cubes[i].transform.position;
AnimationClip clip = new AnimationClip();
Keyframe[] keysX = new Keyframe[2];
keysX[0] = new Keyframe( 0f, move.x-3);
keysX[1] = new Keyframe(i+1f, move.x+3);
AnimationCurve curveX = new AnimationCurve(keysX);
clip.SetCurve("", typeof(Transform), "localPosition.x", curveX);
clip.wrapMode = WrapMode.PingPong;
Keyframe[] keysY = new Keyframe[2];
keysY[0] = new Keyframe( 0f, move.y);
keysY[1] = new Keyframe(i+1f, move.y);
AnimationCurve curveY = new AnimationCurve(keysY);
clip.SetCurve("", typeof(Transform), "localPosition.y", curveY);
Keyframe[] keysZ = new Keyframe[2];
keysZ[0] = new Keyframe( 0f, move.z);
keysZ[1] = new Keyframe(i+1f, move.z);
AnimationCurve curveZ = new AnimationCurve(keysZ);
clip.SetCurve("", typeof(Transform), "localPosition.z", curveZ);
cubes[i].animation.AddClip(clip, "clip1");
cubes[i].animation.Play("clip1");
}
}
开发者ID:riki-y,项目名称:Rikis-WorkSpace,代码行数:34,代码来源:smartballscript.cs
示例9: Test_New1
public void Test_New1()
{
var frame = new Keyframe (1, 2);
Assert.AreEqual (1, frame.Time);
Assert.AreEqual (2, frame.Value);
}
开发者ID:weimingtom,项目名称:erica,代码行数:7,代码来源:TestKeyframe.cs
示例10: CurveIsWrong
public static bool CurveIsWrong(Keyframe[] aCurve)
{
if (null == aCurve || 1 > aCurve.Length)
return true;
else
return false;
}
开发者ID:ratsil,项目名称:bethe.btl,代码行数:7,代码来源:Roll.cs
示例11: SetLoupiotteAproach
void SetLoupiotteAproach()
{
AnimationClip clip = new AnimationClip();
Keyframe[] xValues = new Keyframe[5];
Keyframe[] yValues = new Keyframe[5];
Keyframe[] zValues = new Keyframe[5];
Keyframe[] stateValues = new Keyframe[5];
for (int i = 0; i<5; i++)
{
xValues[i] = new Keyframe(i * 3.0f, i < 4 ? Random.Range(-20.0f / (2 * i + 1), 20.0f / (2 * i + 1)) : xReference);
zValues[i] = new Keyframe(i * 3.0f, i < 4 ? Random.Range(-20.0f / (2 * i + 1), 20.0f / (2 * i + 1)) : zReference);
stateValues[i] = new Keyframe(i * 3.0f, i < 4 ? 0.0f : 1.0f);
}
yValues[0] = new Keyframe(0.0f, 50.0f);
yValues[1] = new Keyframe(3.0f, 35.0f);
yValues[2] = new Keyframe(6.0f, 25.0f);
yValues[3] = new Keyframe(9.0f, 15.0f);
yValues[4] = new Keyframe(12.0f, yReference);
AnimationCurve xCurve = new AnimationCurve(xValues);
AnimationCurve yCurve = new AnimationCurve(yValues);
AnimationCurve zCurve = new AnimationCurve(zValues);
AnimationCurve stateCurve = new AnimationCurve(stateValues);
clip.legacy = true;
clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.x", xCurve);
clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.y", yCurve);
clip.SetCurve("", typeof(Loupiotte), "positionToPlayer.z", zCurve);
clip.SetCurve("", typeof(Loupiotte), "state", stateCurve);
anim.AddClip(clip, "Approche");
}
开发者ID:Juli3nnicolas,项目名称:TempOcean,代码行数:32,代码来源:Loupiotte.cs
示例12: CalculateCurvesPoint
public static float CalculateCurvesPoint(Keyframe[] aCurve, long nFrame)
{
if (null == aCurve || 1> aCurve.Length)
throw new Exception("curve is empty");
Keyframe[] aInterval=FindInterval(aCurve, nFrame);
if (1 == aInterval.Length)
{
if (aCurve[0] == aInterval[0])
; // в идеале расчитать экстрапол¤цию за границы диапазона (касательна¤ в ту же сторону)
if (aCurve[aCurve.Length - 1] == aInterval[0])
; // в идеале расчитать экстрапол¤цию за границы диапазона (касательна¤ в ту же сторону)
return aInterval[0].nPosition; // но пока просто остаЄмс¤ на этой точке
}
float nRetVal = 0;
switch (aInterval[0].eType)
{
case Keyframe.Type.hold:
// формула y=A при M<=x<N
nRetVal = aInterval[0].nPosition;
break;
case Keyframe.Type.linear:
// формула y=kx+h, где y-пиксели, x-фреймы. M, N - точки на х; A, B - точки на y, то люба¤ точка (PX, FR) <= PX=((B-A)/(N-M))*(FR-M)+A
nRetVal = ((aInterval[1].nPosition - aInterval[0].nPosition) / (aInterval[1].nFrame - aInterval[0].nFrame)) * (nFrame - aInterval[0].nFrame) + aInterval[0].nPosition;
break;
case Keyframe.Type.besier:
break;
default:
break;
}
return nRetVal;
}
开发者ID:ratsil,项目名称:bethe.btl,代码行数:32,代码来源:Roll.cs
示例13: AnimationInstance
//
public AnimationInstance(Animation anim)
{
animation_ = anim;
frameRate_ = anim.FrameRate;
// The time of the last frame is less than the duration of the animation,
// as the last frame has some duration itself.
lastFrameTime_ = (anim.NumFrames - 1) / frameRate_;
invFrameRate_ = 1.0f / frameRate_;
duration_ = anim.NumFrames * invFrameRate_;
int max = 0;
// calculate max bone index
// todo: do in content pipeline
foreach (KeyValuePair<int, AnimationTrack> kvp in anim.Tracks)
{
if (kvp.Key >= max)
max = kvp.Key + 1;
}
// Allocate animation keyframes (for lerping between times).
keyframes_ = new Keyframe[max];
// Load all the tracks (one track per bone).
tracks_ = new AnimationTrack[max];
foreach (int i in anim.Tracks.Keys)
{
keyframes_[i] = new Keyframe();
tracks_[i] = anim.Tracks[i];
}
}
开发者ID:remmy925,项目名称:openbattlechess,代码行数:28,代码来源:AnimationInstance.cs
示例14: CreateLineraCurve
public static AnimationCurve CreateLineraCurve( float[] values, float[] times )
{
D.Assert( values != null && times != null, "Param == null" );
D.Assert( values.Length == times.Length, "Size not same" );
AnimationCurve result;
Keyframe[] ks = new Keyframe[values.Length];
for( int i = 0; i < values.Length; i ++ ) {
float inTgt;
float outTgt;
if ( i == 0){
inTgt = 0;
}else{
inTgt = (values[ i ] - values[i-1])/(times[i] - times[i-1]);
}
if ( i == values.Length -1){
outTgt = 0;
}else{
outTgt = (values[ i+1 ] - values[i])/(times[i+1] - times[i]);
}
ks[ i ] = new Keyframe( times[ i ], values[ i ], inTgt, outTgt );
}
result = new AnimationCurve( ks );
return result;
}
开发者ID:fengqk,项目名称:Art,代码行数:26,代码来源:ChpAnimation.cs
示例15: GetKeyTangentMode
// UnityEditor.CurveUtility.cs (c) Unity Technologies
public static TangentMode GetKeyTangentMode(Keyframe keyframe, int leftRight)
{
Type t = typeof(UnityEngine.Keyframe);
FieldInfo field = t.GetField("m_TangentMode", BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
int tangentMode = (int)field.GetValue(keyframe);
if(leftRight == 0)
return (TangentMode)((tangentMode & 6) >> 1);
else
return (TangentMode)((tangentMode & 24) >> 3);
}
开发者ID:sgyli7,项目名称:GarageKit_for_Unity,代码行数:11,代码来源:AnimationCurveUtil.cs
示例16: Init
public override void Init()
{
SceneManager.RC = RC;
var stativ = new SceneEntity("stativ", new ActionCode());
var dir = new DirectionalLight(new float3(0, 10, -1), new float4(1, 1, 1, 1), new float4(1, 1, 1, 1),
new float4(1, 1, 1, 1), new float3(0, 0, 0), 0);
stativ.AddComponent(dir);
_camera = new Camera(stativ);
stativ.transform.GlobalPosition = new float3(0, 0, 100);
SceneManager.Manager.AddSceneEntity(stativ);
_camera.Resize(Width, Height);
Geometry wuerfelGeo = MeshReader.ReadWavefrontObj(new StreamReader(@"Assets/Sphere.obj.model"));
_wuerfel = new SceneEntity("wuerfel", new Material(MoreShaders.GetSpecularShader(RC)),
new Renderer(wuerfelGeo));
SceneManager.Manager.AddSceneEntity(_wuerfel);
_channel2 = new Channel<float3>(Lerp.Float3Lerp);
_channel1 = new Channel<float4>(Lerp.Float4Lerp, new float4(0.5f, 0.5f, 0.5f, 0.5f));
var key0 = new Keyframe<float4>(0, new float4(1, 0, 1, 1));
var key1 = new Keyframe<float4>(2, new float4(0.125f, 1, 0.125f, 1));
var key2 = new Keyframe<float4>(4, new float4(0.250f, 0.75f, 0.250f, 1));
var key3 = new Keyframe<float4>(6, new float4(0.5f, 0.5f, 0.5f, 1));
var key4 = new Keyframe<float4>(8, new float4(0.75f, 0.25f, 0.75f, 1));
var key5 = new Keyframe<float4>(10, new float4(1, 25, 0.125f, 1));
var key6 = new Keyframe<float4>(0, new float4(0, 1, 0, 1));
_channel1.AddKeyframe(key0);
_channel1.AddKeyframe(key1);
_channel1.AddKeyframe(key2);
_channel1.AddKeyframe(key3);
_channel1.AddKeyframe(key4);
_channel1.AddKeyframe(key5);
_channel1.AddKeyframe(key6);
var key40 = new Keyframe<float3>(8, new float3(8, 0, 80));
var key00 = new Keyframe<float3>(0, new float3(0, 0, 0));
var key10 = new Keyframe<float3>(2, new float3(1, 2, 20));
var key20 = new Keyframe<float3>(4, new float3(2, 4, 40));
var key30 = new Keyframe<float3>(6, new float3(4, 4, 60));
var key50 = new Keyframe<float3>(12, new float3(0, 4, 60));
var key60 = new Keyframe<float3>(0, new float3(8, 8, 8));
_channel2.AddKeyframe(key00);
_channel2.AddKeyframe(key10);
_channel2.AddKeyframe(key20);
_channel2.AddKeyframe(key30);
_channel2.AddKeyframe(key40);
_channel2.AddKeyframe(key50);
_channel2.AddKeyframe(key60);
_myAnim.AddAnimation(_channel1, RC, "ClearColor");
_myAnim.AddAnimation(_channel2, _wuerfel, "transform.GlobalPosition");
}
开发者ID:GameProduction,项目名称:ScharfschiessenGame,代码行数:54,代码来源:Main.cs
示例17: Start
void Start()
{
GameObject.Find ("GUI Text").guiText.text = "AnimationClip sample";
AnimationClip clip = new AnimationClip ();
AnimationCurve curve = AnimationCurve.Linear (0f, 3f, 3f, 3f);
Keyframe key = new Keyframe (1.5f, 7f);
curve.AddKey (key);
clip.SetCurve ("", typeof(Transform), "localPosition.z", curve);
clip.wrapMode = WrapMode.Loop;
animation.AddClip (clip, "clip1");
animation.Play ("clip1");
}
开发者ID:riki-y,项目名称:Rikis-WorkSpace,代码行数:12,代码来源:animation.cs
示例18: SetStartPosition
public void SetStartPosition()
{
if (XPositionCurve.keys.Length < 2)
XPositionCurve = AnimationCurve.Linear(0,0,1,0);
if (YPositionCurve.keys.Length < 2)
YPositionCurve = AnimationCurve.Linear(0,0,1,0);
StartPostion = transform.position;
Keyframe keyx = new Keyframe(0, StartPostion.x);
XPositionCurve.MoveKey(0, keyx);
Keyframe keyy = new Keyframe(0, StartPostion.y);
YPositionCurve.MoveKey(0, keyy);
}
开发者ID:Broxxar,项目名称:egj_first_time,代码行数:13,代码来源:Moveable.cs
示例19: TestTimelineData
public void TestTimelineData()
{
Keyframe<KeyframeParams>[] keyframes = new Keyframe<KeyframeParams>[] {
new Keyframe<KeyframeParams>() { time=0, value=new KeyframeParams() { a=0,b=10 } },
new Keyframe<KeyframeParams>() { time=0.5f, value=new KeyframeParams() { a=1,b=5 } },
new Keyframe<KeyframeParams>() { time=0.1f, value=new KeyframeParams() { a=3,b=1 } }
};
KeyframeObject keyframeObject = new KeyframeObject();
Func<int,float,string> formatMsg = (a,b)=>string.Format( "{0}-{1}", a, b );
Timeline<KeyframeParams,KeyframeObject> timeline = new Timeline<KeyframeParams, KeyframeObject>() {
timelineEntity=keyframeObject,
keyframes=keyframes,
tweenFunction=(p1,p2,t)=>{
return new KeyframeParams() {
a=(int)Lerp(p1.a,p2.a,t),
b=Lerp(p1.b,p2.b,t)
};
},
applyKeyframeParameters=(kfo,p)=>kfo.msg = formatMsg(p.a,p.b)
};
Assert.AreEqual( -1, timeline.CurrentKeyframeIndex );
timeline.Update(0);
Assert.AreEqual( 0, timeline.CurrentKeyframeIndex );
Assert.AreEqual( formatMsg(0,10), keyframeObject.msg );
timeline.Update(0.1f);
Assert.AreEqual( 0, timeline.CurrentKeyframeIndex );
Assert.AreEqual( formatMsg(0,9f), keyframeObject.msg );
timeline.Update(0.4f);
Assert.AreEqual( 0, timeline.CurrentKeyframeIndex );
Assert.AreEqual( formatMsg(1,5f), keyframeObject.msg );
timeline.Update(0.1f);
Assert.AreEqual( 1, timeline.CurrentKeyframeIndex );
Assert.AreEqual( formatMsg(3,0.999999f), keyframeObject.msg );
timeline.Update(0.1f);
Assert.AreEqual( 2, timeline.CurrentKeyframeIndex );
Assert.AreEqual( formatMsg(0,10f), keyframeObject.msg ); // this frame has no length
timeline.Update(0.1f);
Assert.AreEqual( 0, timeline.CurrentKeyframeIndex ); // loop around
Assert.AreEqual( formatMsg(0,8f), keyframeObject.msg );
}
开发者ID:johnsietsma,项目名称:csharp-kit,代码行数:50,代码来源:TestTimeline.cs
示例20: FindInterval
public static Keyframe[] FindInterval(Keyframe[] aCurve, long nFrame)
{
if (aCurve[0].nFrame >= nFrame)
return new Keyframe[1] { aCurve[0]};
if (aCurve[aCurve.Length - 1].nFrame <= nFrame)
return new Keyframe[1] { aCurve[aCurve.Length - 1] };
for (int ni = 0; ni < aCurve.Length - 1; ni++)
{
if (aCurve[ni].nFrame == nFrame)
return new Keyframe[1] { aCurve[ni] };
if (aCurve[ni].nFrame > nFrame || aCurve[ni].nFrame < nFrame && aCurve[ni + 1].nFrame > nFrame)
return new Keyframe[2] { aCurve[ni], aCurve[ni + 1] };
}
throw new Exception("impossible to find interval");
}
开发者ID:ratsil,项目名称:bethe.btl,代码行数:15,代码来源:Roll.cs
注:本文中的Keyframe类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论