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


C# Spine.Apply方法代码示例

本文整理汇总了C#中Spine.Apply方法的典型用法代码示例。如果您正苦于以下问题:C# Spine.Apply方法的具体用法?C# Spine.Apply怎么用?C# Spine.Apply使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Spine的用法示例。


在下文中一共展示了Spine.Apply方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BakeBone

	static void BakeBone (Bone bone, Spine.Animation animation, AnimationClip clip) {
		Skeleton skeleton = bone.Skeleton;
		bool inheritRotation = bone.Data.InheritRotation;

		skeleton.SetToSetupPose();
		animation.Apply(skeleton, 0, 0, true, null);
		skeleton.UpdateWorldTransform();
		float duration = animation.Duration;

		AnimationCurve curve = new AnimationCurve();

		List<Keyframe> keys = new List<Keyframe>();

		float rotation = bone.RotationIK;
		if (!inheritRotation)
			rotation = GetUninheritedRotation(bone);

		keys.Add(new Keyframe(0, rotation, 0, 0));

		int listIndex = 1;

		float r = rotation;

		int steps = Mathf.CeilToInt(duration / bakeIncrement);

		float currentTime = 0;
		float lastTime = 0;
		float angle = rotation;

		for (int i = 1; i <= steps; i++) {
			currentTime += bakeIncrement;
			if (i == steps)
				currentTime = duration;

			animation.Apply(skeleton, lastTime, currentTime, true, null);
			skeleton.UpdateWorldTransform();

			int pIndex = listIndex - 1;

			Keyframe pk = keys[pIndex];

			pk = keys[pIndex];

			if (inheritRotation)
				rotation = bone.RotationIK;
			else {
				rotation = GetUninheritedRotation(bone);
			}

			angle += Mathf.DeltaAngle(angle, rotation);

			r = angle;

			float rOut = (r - pk.value) / (currentTime - pk.time);

			pk.outTangent = rOut;

			keys.Add(new Keyframe(currentTime, r, rOut, 0));

			keys[pIndex] = pk;

			listIndex++;
			lastTime = currentTime;
		}

		curve = EnsureCurveKeyCount(new AnimationCurve(keys.ToArray()));

		string path = GetPath(bone.Data);
		string propertyName = "localEulerAnglesBaked";

		EditorCurveBinding xBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".x");
		AnimationUtility.SetEditorCurve(clip, xBind, new AnimationCurve());
		EditorCurveBinding yBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".y");
		AnimationUtility.SetEditorCurve(clip, yBind, new AnimationCurve());
		EditorCurveBinding zBind = EditorCurveBinding.FloatCurve(path, typeof(Transform), propertyName + ".z");
		AnimationUtility.SetEditorCurve(clip, zBind, curve);
	}
开发者ID:wenhaoisbad,项目名称:kxsm,代码行数:77,代码来源:SkeletonBaker.cs


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