本文整理汇总了C#中UnityEngine.AnimationCurve.UpdateAllLinearTangents方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationCurve.UpdateAllLinearTangents方法的具体用法?C# AnimationCurve.UpdateAllLinearTangents怎么用?C# AnimationCurve.UpdateAllLinearTangents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AnimationCurve
的用法示例。
在下文中一共展示了AnimationCurve.UpdateAllLinearTangents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: createAnimation
public static void createAnimation()
{
GameObject go = GameObject.Find(GAME_OBJECT_NAME);
if (go != null)
removeGameObjectAndComponents(go);
Animator animator;
go = createGameObjects(out animator);
AnimationClip animationClip = new AnimationClip();
AnimationUtility.SetAnimationType(animationClip, ModelImporterAnimationType.Generic);
AnimationCurve activeCurve = new AnimationCurve();
AnimationCurve positionLineCurve = new AnimationCurve();
AnimationCurve positionSmoothCurve = new AnimationCurve();
for (int i = 0; i < stepValues.Length; i++) {
float time = stepTime * i;
activeCurve .AddKey(KeyframeUtil.GetNew(time, stepValues[i] , TangentMode.Stepped));
positionLineCurve .AddKey(KeyframeUtil.GetNew(time, stepValues[i] + 2, TangentMode.Linear));
positionSmoothCurve.AddKey(KeyframeUtil.GetNew(time, stepValues[i] - 2, TangentMode.Smooth));
}
//this will be linear curve, so need to update tangents (should be after keyframes assignments)
positionLineCurve.UpdateAllLinearTangents();
animationClip.SetCurve(CUBE1_NAME, typeof(GameObject),"m_IsActive", activeCurve);
animationClip.SetCurve(CUBE2_NAME, typeof(Transform),"localPosition.x", positionLineCurve);
animationClip.SetCurve(CUBE2_NAME, typeof(Transform),"localPosition.y", positionSmoothCurve);
AssetDatabase.CreateAsset(animationClip, ANIMATION_CLIP_PATH);
AssetDatabase.SaveAssets();
AddClipToAnimatorComponent(go, animator, animationClip);
}
示例2: SetFloatCurve
void SetFloatCurve(AnimationCurve curve, SpriteStudioAnimePackAnimePartAnimeAttribute attribute, float fps, int frameCount, float unit = 1.0f, float baseValue = 0)
{
List<float> keyList = new List<float> (frameCount);
SpriteStudioAnimePackAnimePartAnimeAttributeKey prevKey = null;
SpriteStudioAnimePackAnimePartAnimeAttributeKey nextKey = null;
for (int i = 0; i < frameCount; i++) {
float value = 0;
SpriteStudioAnimePackAnimePartAnimeAttributeKey key = attribute.key.FirstOrDefault (v => v.time == i);
if (key != null) {
value = GetValue (key);
prevKey = key;
} else {
IEnumerable<SpriteStudioAnimePackAnimePartAnimeAttributeKey> keys = attribute.key.Where (v => v.time > i);
if (keys.Count () == 0) {
break;
}
if (prevKey == null) {
prevKey = keys.First ();
value = GetValue (prevKey);
} else {
nextKey = keys.First ();
float valuePrev = GetValue (prevKey);
float valueNext = GetValue (nextKey);
int timePrev = prevKey.time;
int timeNext = nextKey.time;
float timeNormalize = (float)(i - timePrev) / (float)(timeNext - timePrev);
timeNormalize = Mathf.Clamp01 (timeNormalize);
switch (prevKey.ipType) {
case "linear":
{
value = GetLinear (valuePrev, valueNext, timeNormalize);
break;
}
case "bezier":
{
float curveStartTime = float.Parse (prevKey.curve.Value.Split (' ') [0]);
float curveStartValue = float.Parse (prevKey.curve.Value.Split (' ') [1]);
float curveEndTime = float.Parse (prevKey.curve.Value.Split (' ') [2]);
float curveEndValue = float.Parse (prevKey.curve.Value.Split (' ') [3]);
Vector2 start = new Vector2 ((float)timePrev, valuePrev);
Vector2 controlStart = new Vector2 (curveStartTime, curveStartValue);
Vector2 end = new Vector2 ((float)timeNext, valueNext);
Vector2 controlEnd = new Vector2 (curveEndTime, curveEndValue);
value = GetBezier (start, controlStart, end, controlEnd, timeNormalize);
break;
}
case "hermite":
{
float curveStartValue = float.Parse (prevKey.curve.Value.Split (' ') [1]);
float curveEndValue = float.Parse (prevKey.curve.Value.Split (' ') [3]);
value = GetHermite (valuePrev, curveStartValue, valueNext, curveEndValue, timeNormalize);
break;
}
case "acceleration":
{
value = GetAccelerate (valuePrev, valueNext, timeNormalize);
break;
}
case "deceleration":
{
value = GetDecelerate (valuePrev, valueNext, timeNormalize);
break;
}
default:
{
value = GetValue (prevKey);
break;
}
}
}
}
keyList.Add (value);
}
for (int i = 0; i < keyList.Count; i++) {
float time = GetTime (i, fps);
float value = keyList [i];
if (i == 0) {
curve.AddKey (KeyframeUtil.GetNew (time, baseValue + value * unit, tangentMode));
} else if (i == keyList.Count - 1) {
curve.AddKey (KeyframeUtil.GetNew (time,baseValue + value * unit, tangentMode));
} else {
float prev = keyList [i - 1];
float next = keyList [i + 1];
if (value == prev && value == next) {
continue;
}
curve.AddKey (KeyframeUtil.GetNew (time, baseValue + value * unit, tangentMode));
}
}
curve.UpdateAllLinearTangents ();
}