本文整理汇总了C#中UnityEngine.AnimationCurve.MoveKey方法的典型用法代码示例。如果您正苦于以下问题:C# AnimationCurve.MoveKey方法的具体用法?C# AnimationCurve.MoveKey怎么用?C# AnimationCurve.MoveKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UnityEngine.AnimationCurve
的用法示例。
在下文中一共展示了AnimationCurve.MoveKey方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateTangentsFromMode
// UnityEditor.CurveUtility.cs (c) Unity Technologies
public static void UpdateTangentsFromMode(AnimationCurve curve, int index)
{
if (index < 0 || index >= curve.length)
return;
Keyframe key = curve [index];
if (KeyframeUtil.GetKeyTangentMode (key, 0) == TangentMode.Linear && index >= 1) {
key.inTangent = CalculateLinearTangent (curve, index, index - 1);
curve.MoveKey (index, key);
}
if (KeyframeUtil.GetKeyTangentMode (key, 1) == TangentMode.Linear && index + 1 < curve.length) {
key.outTangent = CalculateLinearTangent (curve, index, index + 1);
curve.MoveKey (index, key);
}
if (KeyframeUtil.GetKeyTangentMode (key, 0) != TangentMode.Smooth && KeyframeUtil.GetKeyTangentMode (key, 1) != TangentMode.Smooth)
return;
curve.SmoothTangents (index, 0.0f);
}
示例2: SetLinear
public static void SetLinear(ref AnimationCurve curve) {
for (int i = 0; i < curve.length; i++) {
Keyframe boxed = curve.keys[i]; // getting around the fact that Keyframe is a struct by pre-boxing
boxed.tangentMode = GetNewTangentKeyMode(boxed.tangentMode, TangentDirection.Left, TangentMode.Linear);
boxed.tangentMode = GetNewTangentKeyMode(boxed.tangentMode, TangentDirection.Right, TangentMode.Linear);
curve.MoveKey(i, (Keyframe)boxed);
curve.SmoothTangents(i, 0f);
}
}
示例3: AddKeyframeToCurve
/// <summary>
/// Adds the keyframe to curve.
/// </summary>
/// <param name="animationCurve">Animation curve.</param>
/// <param name="animatedClip">Animated clip.</param>
/// <param name="binding">Binding.</param>
/// <param name="value">Value.</param>
/// <param name="type">Type.</param>
/// <param name="time">Time.</param>
public static void AddKeyframeToCurve(AnimationCurve animationCurve, AnimationClip animatedClip, EditorCurveBinding binding, float value, Type type, float time)
{
//frame comparing (frame=(int)(time*animatedClip.frameRate)
int keyframeIndex = Array.FindIndex (animationCurve.keys, (itm) => (int)(itm.time * animatedClip.frameRate) == (int)(time * animatedClip.frameRate));
Keyframe key = default(Keyframe);
if (keyframeIndex < 0) {
if (type == typeof(bool) || type == typeof(float)) {
key = new Keyframe (time, value);
if (type == typeof(bool)) {
//CurveUtility.SetKeyTangentMode (ref key, 0, TangentMode.Stepped);
//CurveUtility.SetKeyTangentMode (ref key, 1, TangentMode.Stepped);
//CurveUtility.SetKeyBroken (ref key, true);
key.SetKeyTangentMode (0, TangentMode.Stepped);
key.SetKeyTangentMode (1, TangentMode.Stepped);
key.SetKeyBroken (true);
} else {
int num = animationCurve.AddKey (key);
if (num != -1) {
animationCurve.SetKeyModeFromContext (num);
}
}
}
} else {
//??? maybe I should add new time too
//animationCurve.keys[keyframeIndex].value=value;
key = animationCurve.keys [keyframeIndex];
key.value = value;
animationCurve.MoveKey (keyframeIndex, key);
}
//Save changes
SaveCurve (animationCurve, animatedClip, binding);
}
示例4: OnGUI
void OnGUI()
{
bool isCurveChanged = false;
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true), GUILayout.Height(50));
EditorGUILayout.LabelField("Click _curve to edit ->", GUILayout.ExpandWidth(false));
EditorGUI.BeginChangeCheck();
_curve = EditorGUILayout.CurveField(_curve, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true));
if (EditorGUI.EndChangeCheck())
{
isCurveChanged = true;
}
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
EditorGUILayout.Separator();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
EditorGUILayout.LabelField("Nr.", GUILayout.MinWidth(20.0f));
EditorGUILayout.LabelField("X", GUILayout.MinWidth(50.0f));
EditorGUILayout.LabelField("Y", GUILayout.MinWidth(50.0f));
EditorGUILayout.LabelField("inTangent", GUILayout.MinWidth(50.0f));
EditorGUILayout.LabelField("outTangent", GUILayout.MinWidth(50.0f));
GUILayout.EndHorizontal();
for (int i = 0; i < _curve.keys.Length; i++)
{
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
EditorGUILayout.LabelField(i + ".", GUILayout.MinWidth(20.0f));
EditorGUI.BeginChangeCheck();
float x = EditorGUILayout.FloatField(_curve.keys[i].time);
float y = EditorGUILayout.FloatField(_curve.keys[i].value);
//int mode = EditorGUILayout.IntField( curve.keys[i].tangentMode );
float inTangent = EditorGUILayout.FloatField(_curve.keys[i].inTangent);
float outTangent = EditorGUILayout.FloatField(_curve.keys[i].outTangent);
if (EditorGUI.EndChangeCheck())
{
if ((i == 0 || (_curve.keys.Length > 0 && x != _curve.keys[0].time)) && (i == _curve.length - 1 || (x != _curve.keys[_curve.length - 1].time)))
{
Keyframe keyframe = new Keyframe(x, y, inTangent, outTangent);
//keyframe.tangentMode = (int)mode;
_curve.MoveKey(i, keyframe);
isCurveChanged = true;
}
}
GUILayout.EndHorizontal();
EditorGUILayout.Separator();
}
if (isCurveChanged)
{
CurveSerialProp.animationCurveValue = _curve;
CurveSerialProp.serializedObject.ApplyModifiedProperties();
_curve = CurveSerialProp.animationCurveValue;
}
}
示例5: setLinearInterval
public static void setLinearInterval(AnimationCurve curve, int i, int nextI)
{
Keyframe thisKeyframe = curve[i];
Keyframe nextKeyframe = curve[nextI];
thisKeyframe.outTangent = CurveExtension.CalculateLinearTangent(curve, i, nextI);
nextKeyframe.inTangent = CurveExtension.CalculateLinearTangent(curve, nextI, i);
KeyframeUtil.SetKeyBroken((object)thisKeyframe, true);
KeyframeUtil.SetKeyBroken((object)nextKeyframe, true);
KeyframeUtil.SetKeyTangentMode((object)thisKeyframe, 1, TangentMode.Linear);
KeyframeUtil.SetKeyTangentMode((object)nextKeyframe, 0, TangentMode.Linear);
curve.MoveKey(i, thisKeyframe);
curve.MoveKey(nextI, nextKeyframe);
}
示例6: setSteppedInterval
public static void setSteppedInterval(AnimationCurve curve, int i, int nextI)
{
if (curve.keys[i].value == curve.keys[nextI].value){
return;
}
object thisKeyframeBoxed = curve[i];
object nextKeyframeBoxed = curve[nextI];
if (!KeyframeUtil.isKeyBroken(thisKeyframeBoxed))
KeyframeUtil.SetKeyBroken(thisKeyframeBoxed, true);
if (!KeyframeUtil.isKeyBroken(nextKeyframeBoxed))
KeyframeUtil.SetKeyBroken(nextKeyframeBoxed, true);
KeyframeUtil.SetKeyTangentMode(thisKeyframeBoxed, 1, TangentMode.Stepped);
KeyframeUtil.SetKeyTangentMode(nextKeyframeBoxed, 0, TangentMode.Stepped);
Keyframe thisKeyframe = (Keyframe)thisKeyframeBoxed;
Keyframe nextKeyframe = (Keyframe)nextKeyframeBoxed;
thisKeyframe.outTangent = float.PositiveInfinity;
nextKeyframe.inTangent = float.PositiveInfinity;
curve.MoveKey(i, thisKeyframe);
curve.MoveKey(nextI, nextKeyframe);
}
示例7: UpdateTangentsFromMode
void UpdateTangentsFromMode(AnimationCurve curve, int index)
{
if (index < 0 || index >= curve.length)
return;
Keyframe key = curve[index];
// Adjust linear tangent
if (GetKeyTangentMode(key, 0) == TangentMode.Linear && index >= 1)
{
key.inTangent = CalculateLinearTangent(curve[index], curve[index-1]);
}
if (GetKeyTangentMode(key, 1) == TangentMode.Linear && index+1 < curve.length)
{
key.outTangent = CalculateLinearTangent(curve[index], curve[index+1]);
}
float smoothWeight = 0.0F;
// if (index > 0 && index < curve.length - 1)
// {
// smoothWeight = Mathf.InverseLerp(curve[index - 1].time, curve[index + 1].time, curve[index].time) * 2 - 1;
// }
if (GetKeyTangentMode(key, 0) == TangentMode.Smooth)
{
curve.SmoothTangents(index, smoothWeight);
key.inTangent = curve[index].inTangent;
}
if (GetKeyTangentMode(key, 1) == TangentMode.Smooth)
{
curve.SmoothTangents(index, smoothWeight);
key.outTangent = curve[index].outTangent;
}
curve.MoveKey(index, key);
}
示例8: setCustomTangents
public static void setCustomTangents(AnimationCurve curve, int i, int nextI, JsonData tangentArray)
{
float diffValue = curve[nextI].value - curve[i].value;
float diffTime = curve[nextI].time - curve[i].time;
if (diffValue == 0)
return;
float cx1 = parseFloat(tangentArray[0]);
float cy1 = parseFloat(tangentArray[1]);
float cx2 = parseFloat(tangentArray[2]);
float cy2 = parseFloat(tangentArray[3]);
Vector2 p0 = new Vector2(0 , curve[i].value);
Vector2 p3 = new Vector2(diffTime , curve[nextI].value);
Vector2 cOrig1 = new Vector2(diffTime * cx1, curve[i].value);
cOrig1.y += diffValue > 0 ? diffValue * cy1 : -1.0f * Mathf.Abs(diffValue * cy1);
Vector2 cOrig2 = new Vector2(diffTime * cx2, curve[i].value);
cOrig2.y += diffValue > 0 ? diffValue * cy2 : -1.0f * Mathf.Abs(diffValue * cy2);
Vector2 p1 = getBezierPoint(p0, cOrig1, cOrig2, p3, 1.0f / 3.0f);
Vector2 p2 = getBezierPoint(p0, cOrig1, cOrig2, p3, 2.0f / 3.0f);
Vector2 c1tg, c2tg, c1, c2;
calcControlPoints(p0,p1,p2,p3, out c1, out c2);
c1tg = c1 - p0;
c2tg = c2 - p3;
float outTangent = c1tg.y / c1tg.x;
float inTangent = c2tg.y / c2tg.x;
object thisKeyframeBoxed = curve[i];
object nextKeyframeBoxed = curve[nextI];
if (!KeyframeUtil.isKeyBroken(thisKeyframeBoxed))
KeyframeUtil.SetKeyBroken(thisKeyframeBoxed, true);
KeyframeUtil.SetKeyTangentMode(thisKeyframeBoxed, 1, TangentMode.Editable);
if (!KeyframeUtil.isKeyBroken(nextKeyframeBoxed))
KeyframeUtil.SetKeyBroken(nextKeyframeBoxed, true);
KeyframeUtil.SetKeyTangentMode(nextKeyframeBoxed, 0, TangentMode.Editable);
Keyframe thisKeyframe = (Keyframe)thisKeyframeBoxed;
Keyframe nextKeyframe = (Keyframe)nextKeyframeBoxed;
thisKeyframe.outTangent = outTangent;
nextKeyframe.inTangent = inTangent;
curve.MoveKey(i, thisKeyframe);
curve.MoveKey(nextI, nextKeyframe);
//* test method
bool ok = true;
float startTime = thisKeyframe.time;
float epsilon = 0.001f;
for (float j=0; j < 25f; j++) {
float t = j/25.0f;
Vector2 t1 = getBezierPoint(p0, cOrig1, cOrig2, p3, t);
Vector2 t2 = getBezierPoint(p0, c1, c2, p3, t);
float curveValue = curve.Evaluate(startTime + diffTime * t);
if (!NearlyEqual(t1.y, t2.y, epsilon)
|| !NearlyEqual(t2.y, curveValue, epsilon)){
Debug.LogError("time = "+ t + " t1 = ["+t1.y.ToString("N8")+"] t2 = ["+t2.y.ToString("N8")+"] curve = ["+curveValue.ToString("N8")+"]");
ok = false;
}
}
if (!ok)
Debug.LogWarning("something wrong with bezier points");
//*/
}
示例9: MoveKey
/// <summary>
/// Move/Change an existing key in an AnimationCurve.
/// Maintains TangentMode and updates neighbours.
/// </summary>
/// <param name="curve">The existing AnimationCurve.</param>
/// <param name="index">The index of the current Keyframe.</param>
/// <param name="keyframe">The new Keyframe data.</param>
/// <returns>The index of the Keyframe.</returns>
public static int MoveKey(AnimationCurve curve, int index, Keyframe keyframe)
{
// Save the tangent mode.
Keyframe old = curve[index];
keyframe.tangentMode = old.tangentMode;
int newIndex = curve.MoveKey(index, keyframe);
// Respect the tangentMode and update as necessary.
if (IsAuto(keyframe.tangentMode))
{
curve.SmoothTangents(newIndex, 0);
}
else if (IsBroken(keyframe.tangentMode))
{
if (IsLeftLinear(keyframe.tangentMode))
{
SetKeyLeftLinear(curve, newIndex);
}
if (IsRightLinear(keyframe.tangentMode))
{
SetKeyRightLinear(curve, newIndex);
}
}
// update the left neighbour
if (newIndex > 0)
{
// Update tangent data based on tangent mode.
int tangentMode = curve[newIndex - 1].tangentMode;
if (IsAuto(tangentMode))
{
curve.SmoothTangents(newIndex - 1, 0);
}
if (IsBroken(tangentMode))
{
if (IsRightLinear(tangentMode))
{
SetKeyRightLinear(curve, newIndex - 1);
}
}
}
// update the right neighbour
if (newIndex < curve.length - 1)
{
// Update tangent data based on tangent mode.
int tangentMode = curve[newIndex + 1].tangentMode;
if (IsAuto(tangentMode))
{
curve.SmoothTangents(newIndex + 1, 0);
}
if (IsBroken(tangentMode))
{
if (IsLeftLinear(tangentMode))
{
SetKeyLeftLinear(curve, newIndex + 1);
}
}
}
return newIndex;
}
示例10: SetKeyRightLinear
/// <summary>
/// Set the indexed key of an AnimationCurve to RightLinear.
/// </summary>
/// <param name="curve">The curve to change.</param>
/// <param name="index">The index of the key to set to RightLinear.</param>
public static void SetKeyRightLinear(AnimationCurve curve, int index)
{
Keyframe kf = curve[index];
float tangentValue = kf.outTangent;
if (index < curve.length - 1)
{
Keyframe next = curve[index + 1];
tangentValue = (next.value - kf.value) / (next.time - kf.time);
}
Keyframe newKeyframe = new Keyframe(kf.time, kf.value, kf.inTangent, tangentValue);
// Get current tangent mode.
int leftTangent = (IsAuto(kf.tangentMode) || kf.tangentMode == 0) ? 0 : (kf.tangentMode % 8) - 1;
newKeyframe.tangentMode = leftTangent + 16 + 1;
curve.MoveKey(index, newKeyframe);
}
示例11: SetKeyRightTangentMode
public static void SetKeyRightTangentMode(AnimationCurve curve, int index, TangentMode tangentMode)
{
if (curve == null)
{
throw new ArgumentNullException("curve");
}
if ((index < 0) || (index >= curve.length))
{
throw new ArgumentException("Index out of bounds.");
}
Keyframe key = curve[index];
if (tangentMode != TangentMode.Free)
{
SetKeyBroken(ref key, true);
}
SetKeyRightTangentMode(ref key, tangentMode);
curve.MoveKey(index, key);
UpdateTangentsFromModeSurrounding(curve, index);
}
示例12: UpdateTangentsFromMode
private static void UpdateTangentsFromMode(AnimationCurve curve, int index)
{
if (index < 0 || index >= curve.length)
{
return;
}
Keyframe key = curve[index];
if (CurveUtility.GetKeyTangentMode(key, 0) == TangentMode.Linear && index >= 1)
{
key.inTangent = CurveUtility.CalculateLinearTangent(curve, index, index - 1);
curve.MoveKey(index, key);
}
if (CurveUtility.GetKeyTangentMode(key, 1) == TangentMode.Linear && index + 1 < curve.length)
{
key.outTangent = CurveUtility.CalculateLinearTangent(curve, index, index + 1);
curve.MoveKey(index, key);
}
if (CurveUtility.GetKeyTangentMode(key, 0) == TangentMode.Smooth || CurveUtility.GetKeyTangentMode(key, 1) == TangentMode.Smooth)
{
curve.SmoothTangents(index, 0f);
}
}
示例13: SetKeyBroken
/// <summary>
/// <para>Change the specified keyframe broken tangent flag.</para>
/// </summary>
/// <param name="curve">The curve to modify.</param>
/// <param name="index">Keyframe index.</param>
/// <param name="broken">Broken flag.</param>
public static void SetKeyBroken(AnimationCurve curve, int index, bool broken)
{
if (curve == null)
{
throw new ArgumentNullException("curve");
}
if ((index < 0) || (index >= curve.length))
{
throw new ArgumentException("Index out of bounds.");
}
Keyframe key = curve[index];
SetKeyBroken(ref key, broken);
curve.MoveKey(index, key);
UpdateTangentsFromModeSurrounding(curve, index);
}
示例14: Internal_UpdateTangents
private static void Internal_UpdateTangents(AnimationCurve curve, int index)
{
if ((index >= 0) && (index < curve.length))
{
Keyframe key = curve[index];
if ((GetKeyLeftTangentMode(key) == TangentMode.Linear) && (index >= 1))
{
key.inTangent = Internal_CalculateLinearTangent(curve, index, index - 1);
curve.MoveKey(index, key);
}
if ((GetKeyRightTangentMode(key) == TangentMode.Linear) && ((index + 1) < curve.length))
{
key.outTangent = Internal_CalculateLinearTangent(curve, index, index + 1);
curve.MoveKey(index, key);
}
if ((GetKeyLeftTangentMode(key) == TangentMode.ClampedAuto) || (GetKeyRightTangentMode(key) == TangentMode.ClampedAuto))
{
Internal_CalculateAutoTangent(curve, index);
}
if ((GetKeyLeftTangentMode(key) == TangentMode.Auto) || (GetKeyRightTangentMode(key) == TangentMode.Auto))
{
curve.SmoothTangents(index, 0f);
}
if (((GetKeyLeftTangentMode(key) == TangentMode.Free) && (GetKeyRightTangentMode(key) == TangentMode.Free)) && !GetKeyBroken(key))
{
key.outTangent = key.inTangent;
curve.MoveKey(index, key);
}
if (GetKeyLeftTangentMode(key) == TangentMode.Constant)
{
key.inTangent = float.PositiveInfinity;
curve.MoveKey(index, key);
}
if (GetKeyRightTangentMode(key) == TangentMode.Constant)
{
key.outTangent = float.PositiveInfinity;
curve.MoveKey(index, key);
}
}
}
示例15: AddAnimationReturnToGameDeck
private void AddAnimationReturnToGameDeck(Vector3 endPosition)
{
var clip = new AnimationClip();
var curve = AnimationCurve.EaseInOut(0, transform.position.x, 1, endPosition.x);
clip.SetCurve("",typeof(Transform),"localPosition.x", curve);
curve = AnimationCurve.EaseInOut(0, transform.position.y, 0.7f, 0f);
clip.SetCurve("",typeof(Transform),"localPosition.y", curve);
curve = new AnimationCurve();
curve.AddKey(0, transform.position.z);
var keyframe = curve[0];
keyframe.outTangent = 1;
curve.MoveKey(0, keyframe);
curve.AddKey(0.4f, transform.position.z+2.5f);
curve.AddKey(0.70f, transform.position.z+4.7f);
curve.AddKey(1f, endPosition.z);
keyframe = curve[3];
keyframe.inTangent = 0;
curve.MoveKey(3, keyframe);
clip.SetCurve("",typeof(Transform),"localPosition.z", curve);
clip.wrapMode = WrapMode.Once;
// var animEv= new AnimationEvent();
// animEv.functionName="animFinished";
// animEv.time=clip.length;
// clip.AddEvent(animEv);
clip.legacy = true;
GetComponent<Animation>().AddClip(clip, "ReturnToGameDeckAnimation");
}