本文整理汇总了C#中UnityEngine.Keyframe类的典型用法代码示例。如果您正苦于以下问题:C# Keyframe类的具体用法?C# Keyframe怎么用?C# Keyframe使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Keyframe类属于UnityEngine命名空间,在下文中一共展示了Keyframe类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetObjectData
public object SetObjectData(object obj, SerializationInfo info, StreamingContext context, ISurrogateSelector selector)
{
Keyframe[] keyframes;
AnimationCurve curve=new AnimationCurve();
// curve.preWrapMode=(WrapMode)info.GetValue("preWrapMode",typeof(WrapMode));
// curve.postWrapMode=(WrapMode)info.GetValue("postWrapMode",typeof(WrapMode));
int numKeys=info.GetInt32("keysn");
keyframes=new Keyframe[numKeys];
Keyframe keyframeCurrent;
for (int i=0; i<numKeys; i++) {
keyframeCurrent=keyframes[i]=new Keyframe(info.GetSingle("keyt"+i),
info.GetSingle("keyv"+i));
keyframeCurrent.tangentMode=info.GetInt32("keymod"+i);
keyframeCurrent.inTangent=info.GetSingle("keyin"+i);
keyframeCurrent.outTangent=info.GetSingle("keyout"+i);
}
curve.keys = keyframes;
// don't know how to make connection between AnimaitonCurver and Keyframes surrogate
// AnimationCurve surrogate keys are constructed before thoose in Keyframe surrogate resulting in 0,0 Keyframes
//return new AnimationCurve((Keyframe[])info.GetValue ("keys", typeof(Keyframe[])));
return curve;
}
示例2: Interpolate
/// <summary>
/// Creates a new Animationcurve that an interpolation between two other curves. Thanks to Oliver for creating this
/// </summary>
/// <param name="CurveA"></param>
/// <param name="CurveB"></param>
/// <param name="step"></param>
/// <returns>The new interpolated animation curve</returns>
public static AnimationCurve Interpolate(AnimationCurve CurveA, AnimationCurve CurveB, float step)
{
int I = CurveA.length < CurveB.length ? CurveB.length : CurveA.length;
var keys = new Keyframe[I];
for (int i = 0; i < I; ++i)
{
var a = GetKey(CurveA, i, I);
var b = GetKey(CurveB, i, I);
var time = Mathf.SmoothStep(a.time, b.time, step);
var value = Mathf.SmoothStep(a.value, b.value, step);
var inTangent = Mathf.SmoothStep(a.inTangent, b.inTangent, step);
var outTangent = Mathf.SmoothStep(a.outTangent, b.outTangent, step);
var c = new Keyframe(time, value, inTangent, outTangent);
keys[i] = c;
}
return new AnimationCurve(keys);
}
示例3: AddKeyframe
public void AddKeyframe(float t, float val)
{
// Simplify keys
if (ReduceKeyframes && keyframes.Count >= 2) {
var keyStart = keyframes[keyframes.Count-2];
var keyEnd = keyframes[keyframes.Count-1];
// UseReductionThreshold: be wary, traveler. works "ok" but is not a sophisticated keyframe reduction technique
if (UseReductionThreshold) {
float deltaStart = Mathf.Abs (keyStart.value - val);
float deltaEnd = Mathf.Abs (keyEnd.value - val);
if ( deltaStart < ReductionThreshold
&& deltaEnd < ReductionThreshold) {
keyEnd.time = t;
keyEnd.value = val;
return;
}
} else {
if ( Mathf.Approximately (keyStart.value, val)
&& Mathf.Approximately (keyEnd.value, val)) {
keyEnd.time = t;
return;
}
}
}
var k = new Keyframe(t, val);
keyframes.Add (k);
}
示例4: TreeGroup
public TreeGroup()
{
Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.distributionCurve = new AnimationCurve(keys);
this.distributionNodes = 5;
this.distributionTwirl = 0f;
this.distributionPitch = 0f;
Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.distributionPitchCurve = new AnimationCurve(keyframeArray2);
this.distributionScale = 1f;
Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 0.3f) };
this.distributionScaleCurve = new AnimationCurve(keyframeArray3);
this.showAnimationProps = true;
this.animationPrimary = 0.5f;
this.animationSecondary = 0.5f;
this.animationEdge = 1f;
this.visible = true;
this.lockFlags = 0;
this.nodeIDs = new int[0];
this.parentGroupID = -1;
this.childGroupIDs = new int[0];
this.nodes = new List<TreeNode>();
this.parentGroup = null;
this.childGroups = new List<TreeGroup>();
}
示例5: TreeGroupBranch
public TreeGroupBranch()
{
Keyframe[] keys = new Keyframe[] { new Keyframe(0f, 1f, -1f, -1f), new Keyframe(1f, 0f, -1f, -1f) };
this.radiusCurve = new AnimationCurve(keys);
this.radiusMode = true;
this.capSmoothing = 0f;
this.crinklyness = 0.1f;
Keyframe[] keyframeArray2 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.crinkCurve = new AnimationCurve(keyframeArray2);
this.seekBlend = 0f;
Keyframe[] keyframeArray3 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.seekCurve = new AnimationCurve(keyframeArray3);
this.noise = 0.1f;
Keyframe[] keyframeArray4 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.noiseCurve = new AnimationCurve(keyframeArray4);
this.noiseScaleU = 0.2f;
this.noiseScaleV = 0.1f;
this.flareSize = 0f;
this.flareHeight = 0.1f;
this.flareNoise = 0.3f;
this.weldHeight = 0.1f;
this.weldSpreadTop = 0f;
this.weldSpreadBottom = 0f;
this.breakingChance = 0f;
this.breakingSpot = new Vector2(0.4f, 0.6f);
this.frondCount = 1;
this.frondWidth = 1f;
Keyframe[] keyframeArray5 = new Keyframe[] { new Keyframe(0f, 1f), new Keyframe(1f, 1f) };
this.frondCurve = new AnimationCurve(keyframeArray5);
this.frondRange = new Vector2(0.1f, 1f);
this.frondRotation = 0f;
this.frondCrease = 0f;
}
示例6: Write
public void Write(SceneWriter writer, object component)
{
AnimationCurve curve = component as AnimationCurve;
if (curve == null)
{
throw new Exception(GetType() + " cannot export components of type " + component.GetType());
}
writer.WriteElement("PreLoop", ConvertLoopType(curve.preWrapMode));
writer.WriteElement("PostLoop", ConvertLoopType(curve.postWrapMode));
StringBuilder sb = new StringBuilder();
// NOTE: Keyframe.tangentMode might say something about if the tangetn is smooth or broken?
Keyframe[] normalizedKeys = new Keyframe[curve.keys.Length];
for (int i = 0; i < curve.keys.Length; i++)
{
Keyframe k = curve.keys[i];
normalizedKeys[i] = new Keyframe(k.time, k.value, k.inTangent, k.outTangent);
if (i > 0)
{
Keyframe j = curve.keys[i - 1];
normalizedKeys[i - 1].outTangent = DenormalizeTangent(j.time, k.time, j.outTangent);
normalizedKeys[i].inTangent = DenormalizeTangent(j.time, k.time, k.inTangent);
}
}
foreach (Keyframe item in normalizedKeys)
{
sb.AppendFormat("{0} {1} {2} {3} {4} ", item.time, item.value, item.inTangent, item.outTangent, "Smooth");
}
writer.WriteElement("Keys", sb.ToString().TrimEnd());
}
示例7: FromKeyframe
public void FromKeyframe(Keyframe k)
{
this.inTangent = k.inTangent;
this.outTangent = k.outTangent;
this.time = k.time;
this.value = k.value;
}
示例8: AddKeyIfChanged
public static void AddKeyIfChanged(this AnimationCurve curve, Keyframe keyframe)
{
var keys = curve.keys;
//If this is the first key on this curve, always add
//NOTE: Add TWO copies of the first frame, then we adjust the last frame as we move along
//This guarantees a minimum of two keys in each curve
if (keys.Length == 0)
{
curve.AddKey(keyframe);
keyframe.time += float.Epsilon;
curve.AddKey(keyframe);
}
else
{
//TODO: This method of keyframe reduction causes artifacts in animations that are supposed to deliberately pause
//Find the last keyframe
Keyframe lastKey = keys[keys.Length - 1];
if (lastKey.time >= keyframe.time)
Debug.LogError("Keyframes not supplied in consecutive order!!!");
//Grab 2 frames ago
var last2Key = keys[keys.Length - 2];
//If the previous 2 frames were different, add a new frame
if (lastKey.value != last2Key.value)
{
curve.AddKey(keyframe);
}
//The previous frame is redundant - just move it
else
{
curve.MoveKey(keys.Length - 1, keyframe);
}
}
}
示例9: ToKeyframeArray
public static Keyframe[] ToKeyframeArray(SerializableKeyframe[] sks)
{
Keyframe[] keys = new Keyframe[sks.Length];
for(int i = 0; i < keys.Length; i++)
keys[i] = sks[i].ToKeyframe();
return keys;
}
示例10: FromKeyframeArray
public static SerializableKeyframe[] FromKeyframeArray(Keyframe[] ks)
{
SerializableKeyframe[] keys = new SerializableKeyframe[ks.Length];
for(int i = 0; i < keys.Length; i++)
keys[i] = new SerializableKeyframe(ks[i]);
return keys;
}
示例11: constructor
public static int constructor(IntPtr l)
{
try {
int argc = LuaDLL.lua_gettop(l);
UnityEngine.Keyframe o;
if(argc==3){
System.Single a1;
checkType(l,2,out a1);
System.Single a2;
checkType(l,3,out a2);
o=new UnityEngine.Keyframe(a1,a2);
pushValue(l,o);
return 1;
}
else if(argc==5){
System.Single a1;
checkType(l,2,out a1);
System.Single a2;
checkType(l,3,out a2);
System.Single a3;
checkType(l,4,out a3);
System.Single a4;
checkType(l,5,out a4);
o=new UnityEngine.Keyframe(a1,a2,a3,a4);
pushValue(l,o);
return 1;
}
LuaDLL.luaL_error(l,"New object failed.");
return 0;
}
catch(Exception e) {
LuaDLL.luaL_error(l, e.ToString());
return 0;
}
}
示例12: KFProxy
public KFProxy(Keyframe _val)
{
inTangent = _val.inTangent;
outTangent = _val.outTangent;
tangentMode = _val.tangentMode;
time = _val.time;
value = _val.value;
}
示例13: GetAverageKeyValue
private float GetAverageKeyValue(Keyframe[] keyFrames)
{
float num = 0f;
foreach (Keyframe keyframe in keyFrames)
{
num += keyframe.value;
}
return (num / ((float) keyFrames.Length));
}
示例14: AnimationWindowKeyframe
public AnimationWindowKeyframe(AnimationWindowCurve curve, Keyframe key)
{
this.time = key.time;
this.value = key.value;
this.curve = curve;
this.m_InTangent = key.inTangent;
this.m_OutTangent = key.outTangent;
this.m_TangentMode = key.tangentMode;
}
示例15: KeyFrameCopy
public KeyFrameCopy(int idx, int selectionIdx, Keyframe source)
{
this.idx = idx;
this.selectionIdx = selectionIdx;
this.time = source.time;
this.value = source.value;
this.inTangent = source.inTangent;
this.outTangent = source.outTangent;
}