本文整理汇总了C#中UnityEngine.AnimationClip.ValidateIfRetargetable方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationClip.ValidateIfRetargetable方法的具体用法?C# AnimationClip.ValidateIfRetargetable怎么用?C# AnimationClip.ValidateIfRetargetable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AnimationClip
的用法示例。
在下文中一共展示了AnimationClip.ValidateIfRetargetable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateSpriteAnimationClip
/// <summary>
/// Creates an <see cref="AnimationClip"/> of a sprite animation using the given <see cref="Sprite"/> frames and frames per second.
/// </summary>
/// <param name="name">The name of the animation to create.</param>
/// <param name="sprites">The list of <see cref="Sprite"/> objects making up the frames of the animation.</param>
/// <param name="fps">The frames per second for the animation.</param>
/// <returns>The newly constructed <see cref="AnimationClip"/></returns>
private static AnimationClip CreateSpriteAnimationClip(string name, IList<Sprite> sprites, float fps)
{
float frameLength = 1f / fps;
AnimationClip clip = new AnimationClip();
clip.name = name;
clip.frameRate = fps;
clip.wrapMode = WrapMode.Loop;
// The AnimationClipSettings cannot be set in Unity (as of 4.6) and must be editted via SerializedProperty
// from: http://forum.unity3d.com/threads/can-mecanim-animation-clip-properties-be-edited-in-script.251772/
SerializedObject serializedClip = new SerializedObject(clip);
SerializedProperty serializedSettings = serializedClip.FindProperty("m_AnimationClipSettings");
serializedSettings.FindPropertyRelative("m_LoopTime").boolValue = true;
serializedClip.ApplyModifiedProperties();
EditorCurveBinding curveBinding = new EditorCurveBinding();
curveBinding.type = typeof(SpriteRenderer);
curveBinding.propertyName = "m_Sprite";
ObjectReferenceKeyframe[] keyFrames = new ObjectReferenceKeyframe[sprites.Count];
for (int i = 0; i < sprites.Count; i++)
{
ObjectReferenceKeyframe kf = new ObjectReferenceKeyframe();
kf.time = i * frameLength;
kf.value = sprites[i];
keyFrames[i] = kf;
}
#if UNITY_5
AnimationUtility.SetObjectReferenceCurve(clip, curveBinding, keyFrames);
#else // Unity 4
AnimationUtility.SetAnimationType(clip, ModelImporterAnimationType.Generic);
AnimationUtility.SetObjectReferenceCurve(clip, curveBinding, keyFrames);
clip.ValidateIfRetargetable(true);
#endif
AssetDatabase.CreateAsset(clip, GetRelativePath(currentPath) + "/" + name + ".anim");
return clip;
}