当前位置: 首页>>代码示例>>C#>>正文


C# Keyframe类代码示例

本文整理汇总了C#中Keyframe的典型用法代码示例。如果您正苦于以下问题:C# Keyframe类的具体用法?C# Keyframe怎么用?C# Keyframe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Keyframe类属于命名空间,在下文中一共展示了Keyframe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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


注:本文中的Keyframe类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。