Add a new key to the curve.
static Interpolators() { // See: http://www.alsacreations.com/tuto/lire/876-transitions-css3-transition-timing-function.html LinearCurve = AnimationCurve.Linear(0f, 0f, 1f, 1f); EaseOutCurve = new AnimationCurve(); EaseOutCurve.AddKey(new Keyframe(0f, 0f) { inTangent = 2, outTangent = 2, tangentMode = 0 }); EaseOutCurve.AddKey(new Keyframe(1f, 1f) { inTangent = 0, outTangent = 0, tangentMode = 0 }); EaseInCurve = new AnimationCurve(); EaseInCurve.AddKey(new Keyframe(0f, 0f) { inTangent = 0, outTangent = 0, tangentMode = 0 }); EaseInCurve.AddKey(new Keyframe(1f, 1f) { inTangent = 2, outTangent = 2, tangentMode = 0 }); EaseInOutCurve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f); }
//Create default curve for the dynamic bias private AnimationCurve defineCurve() { AnimationCurve temp = new AnimationCurve(); temp.AddKey(-1, -1); temp.AddKey(-0.55f, -0.95f); temp.AddKey(-0.001f, -0.5f); temp.AddKey(0.001f, 0.5f); temp.AddKey(0.55f, 0.95f); temp.AddKey(1, 1); temp.SmoothTangents(2, 1); temp.SmoothTangents(3, -1); return temp; }
/// <summary> /// Constructor /// </summary> public AbstractForceController() : base(ControllerType.AbstractForceController) { Enabled = true; Strength = 1.0f; Position = new Vector2(0, 0); MaximumSpeed = 100.0f; TimingMode = TimingModes.Switched; ImpulseTime = 0.0f; ImpulseLength = 1.0f; Triggered = false; StrengthCurve = new AnimationCurve(); Variation = 0.0f; Randomize = new System.Random(1234); DecayMode = DecayModes.None; DecayCurve = new AnimationCurve(); DecayStart = 0.0f; DecayEnd = 0.0f; StrengthCurve.AddKey(0, 5); StrengthCurve.AddKey(0.1f, 5); StrengthCurve.AddKey(0.2f, -4); StrengthCurve.AddKey(1f, 0); }
public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps) { var textureSheetAnimationModule = ups.textureSheetAnimation; textureSheetAnimationModule.enabled = true; textureSheetAnimationModule.numTilesX = (int)columns; textureSheetAnimationModule.numTilesY = (int)rows; textureSheetAnimationModule.animation = ParticleSystemAnimationType.WholeSheet; if (randomFrame) { textureSheetAnimationModule.frameOverTime = new UnityEngine.ParticleSystem.MinMaxCurve(0.0f, 1.0f); } else if (lifeDuration) { var curve = new UnityEngine.AnimationCurve(); curve.AddKey(new Keyframe(0.0f, 0.0f)); curve.AddKey(new Keyframe(1.0f, 1.0f)); CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curve); textureSheetAnimationModule.frameOverTime = new UnityEngine.ParticleSystem.MinMaxCurve(1.0f, curve); textureSheetAnimationModule.cycleCount = 1; } else { var curve = new UnityEngine.AnimationCurve(); curve.AddKey(new Keyframe(0.0f, 0.0f)); curve.AddKey(new Keyframe(1.0f, 1.0f)); CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curve); textureSheetAnimationModule.frameOverTime = new UnityEngine.ParticleSystem.MinMaxCurve(1.0f, curve); textureSheetAnimationModule.cycleCount = 1; } }
// Use this for initialization void Start() { m_InitialPosition = gameObject.transform.localPosition; m_RelPosition.Set(0, 0, 0); m_Translations = new Vector3[3]; m_Translations[0].Set(m_Speed, 0, 0); m_Translations[1].Set(0, m_Speed, 0); m_Translations[2].Set(0, 0, m_Speed); gameObject.AddComponent<Animation>(); gameObject.animation.animatePhysics = true; m_Forward = new AnimationClip(); var curvex = new AnimationCurve(); var curvey = new AnimationCurve(); var curvez = new AnimationCurve(); var minpos = m_InitialPosition+m_MinIncrement; var maxpos = m_InitialPosition-m_MaxIncrement; float dist = (minpos-maxpos).magnitude; m_MaxTime = dist/m_Speed; curvex.AddKey(0f, minpos.x); curvex.AddKey(dist/m_Speed, maxpos.x); curvey.AddKey(0f, minpos.y); curvey.AddKey(dist/m_Speed, maxpos.y); curvez.AddKey(0f, minpos.z); curvez.AddKey(dist/m_Speed, maxpos.z); m_Forward.wrapMode = WrapMode.ClampForever; m_Forward.SetCurve("", typeof(Transform), "localPosition.x", curvex); m_Forward.SetCurve("", typeof(Transform), "localPosition.y", curvey); m_Forward.SetCurve("", typeof(Transform), "localPosition.z", curvez); this.animation.AddClip(m_Forward, "Forward"); this.animation.Play("Forward"); m_ForwardState = this.animation["Forward"]; }
AnimationCurve GetNewCurve() { AnimationCurve newCurve = new AnimationCurve(); newCurve.AddKey(0f, 0f); newCurve.AddKey(1f, 1f); return newCurve; }
public override void Init() { base.Init(); m_FlyCurve = new AnimationCurve(); m_FlyCurve.AddKey(new Keyframe() { time = 0f, value = 0f }); m_FlyCurve.AddKey(new Keyframe() { time = 1f, value = 1f }); }
/// <summary> /// Rebuild all Lookup tables for the path... This should be called when ever the samples number changes or any points are moved /// </summary> public void Rebuild() { // Scrap old curves uvLUT = new AnimationCurve(); xLUT = new AnimationCurve(); yLUT = new AnimationCurve(); zLUT = new AnimationCurve(); // Add known start and end points to uvLUT uvLUT.AddKey(0,0); uvLUT.AddKey(1,1); samples = Mathf.Max(samples, 2); // Force samples to always be greater than 1 float uvStepSize = (1.0f / (controlPoints.Length - 1)) / samples; // This is how much we increase our iTween.PointOnPath amount by each evaluation float pathLength = length; // Get length of path from iTween float distanceTraveled = 0; // Keep track of actual distance traveled along the path float sampleUV = uvStepSize; // Set initial sample point to uvStepSize, there is no need to sample position 0 Vector3 sampleCurrent = controlPoints[0]; // Current point sampled Vector3 sampleLast = controlPoints[0]; // Previous point sampled - used to get distance and normal Vector3 normal = Vector3.forward; // Normal from last point to current point while(sampleUV < 1) { sampleCurrent = iTween.PointOnPath(controlPoints, sampleUV); // Sample point from iTween distanceTraveled += Vector3.Distance(sampleLast, sampleCurrent); // Increment distance traveled float factor = distanceTraveled / pathLength; // Get percentage in actual distance that distanceTraveled = of pathLength uvLUT.AddKey(factor, sampleUV); // Add key on Lookup table normal = (sampleCurrent - sampleLast).normalized; // Normal from last sample point to current xLUT.AddKey(sampleUV, normal.x); // Save each component of the normal to their own curves yLUT.AddKey(sampleUV, normal.y); zLUT.AddKey(sampleUV, normal.z); sampleUV += uvStepSize; // Increament sampleUV by uvStepSize sampleLast = sampleCurrent; // Save current point as last } if (controlPoints[0] == controlPoints[controlPoints.Length-1]) // Check if first and last points are equal... if so make sure the normal LUTs loop as well { looping = true; sampleCurrent = iTween.PointOnPath(controlPoints, 1); normal = (sampleCurrent - sampleLast).normalized; xLUT.AddKey(0, normal.x); yLUT.AddKey(0, normal.y); zLUT.AddKey(0, normal.z); xLUT.AddKey(1, normal.x); yLUT.AddKey(1, normal.y); zLUT.AddKey(1, normal.z); } else looping = false; }
private static AnimationCurve DefaultCurve() { AnimationCurve curve = new AnimationCurve(); curve.AddKey(0, 0); curve.AddKey(0.5f, 1); curve.AddKey(1, 0); curve.preWrapMode = WrapMode.Loop; curve.postWrapMode = WrapMode.Loop; return curve; }
public static AnimationCurve SineCurve(float length, float magnitude) { AnimationCurve a = new AnimationCurve(); a.preWrapMode = WrapMode.Loop; a.postWrapMode = WrapMode.Loop; a.AddKey(0 , 0); a.AddKey(.25f * length , -magnitude); a.AddKey(.5f * length , 0); a.AddKey(.75f * length , magnitude); a.AddKey(length , 0); return a; }
public override void Init() { base.Init(); m_FlyCurve = new AnimationCurve(); m_FlyCurve.AddKey(new Keyframe() { time = 0f, value = 0f }); m_FlyCurve.AddKey(new Keyframe() { time = 1f, value = 1f }); m_FSMManager.RegisterCondition("IsFarEnoughFly", IsFarEnoughFly); m_FSMManager.LoadFSM(m_Entity.GetFSMPath()); }
public void TestLinearCurve500Precision(float time) { var animCurve = new UnityEngine.AnimationCurve(); animCurve.AddKey(0f, 0f); animCurve.AddKey(500f, 1f); var keyframeCurve = animCurve.ToAnimationCurveBlobAssetRef(); var eval = AnimationCurveEvaluator.Evaluate(time, keyframeCurve); var expected = time / 500f; Assert.IsTrue(NearlyEqual(expected, eval, kTolerance), $"Expected {expected:n6} but was {eval:n6}."); keyframeCurve.Dispose(); }
static void CalculateCurve(Vector3 pos1, Vector3 pos2, AnimationCurve curve, out float distance) { { var t1 = pos1; t1.y = 0f; var t2 = pos2; t2.y = 0f; distance = Vector3.Distance( t1, t2 ); } curve.Clear(); curve.AddKey( 0f, pos1.y ); curve.AddKey( 0.5f, distance * Constants.instance.jumpCurveHeightDifference + Mathf.Max( pos1.y, pos2.y ) ); curve.AddKey( 1f, pos2.y ); }
public static AnimationCurve String2AnimationCurve(string curveString, char sp = ';') { UnityEngine.AnimationCurve curve = new UnityEngine.AnimationCurve(); if (string.IsNullOrEmpty(curveString)) { return(curve); } try { var curveValues = curveString.Split(new char[] { sp }); foreach (var keyFrameValue in curveValues) { Keyframe keyFrame = new Keyframe(); if (!String2KeyFrame(keyFrameValue, out keyFrame)) { ggc.Foundation.Log.LogErrorMsg("Wrong KeyFrame Value:" + keyFrameValue + " in AnimationCurve Config: " + curveString); continue; } curve.AddKey(keyFrame); } return(curve); } catch { ggc.Foundation.Log.LogErrorMsg("Wrong AnimationCurve Value: " + curveString); return(curve); } }
static int AddKey(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2) { UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve)); UnityEngine.Keyframe arg0 = StackTraits <UnityEngine.Keyframe> .Check(L, 2); int o = obj.AddKey(arg0); LuaDLL.lua_pushinteger(L, o); return(1); } else if (count == 3) { UnityEngine.AnimationCurve obj = (UnityEngine.AnimationCurve)ToLua.CheckObject(L, 1, typeof(UnityEngine.AnimationCurve)); float arg0 = (float)LuaDLL.luaL_checknumber(L, 2); float arg1 = (float)LuaDLL.luaL_checknumber(L, 3); int o = obj.AddKey(arg0, arg1); LuaDLL.lua_pushinteger(L, o); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: UnityEngine.AnimationCurve.AddKey")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static public int AddKey(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); UnityEngine.Keyframe a1; checkType(l, 2, out a1); var ret = self.AddKey(a1); pushValue(l, ret); return(1); } else if (argc == 3) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); var ret = self.AddKey(a1, a2); pushValue(l, ret); return(1); } LuaDLL.luaL_error(l, "No matched override function to call"); return(0); } catch (Exception e) { LuaDLL.luaL_error(l, e.ToString()); return(0); } }
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); }
public void TestBackwardCurveWithCache(float timeStep, int keyframeCount) { var animCurve = new UnityEngine.AnimationCurve(); for (var i = 0; i < keyframeCount; ++i) { animCurve.AddKey(new UnityEngine.Keyframe(i, i * timeStep, Mathf.Infinity, Mathf.Infinity)); } var curveBlob = animCurve.ToAnimationCurveBlobAssetRef(); var curve = new Unity.Animation.AnimationCurve(); curve.SetAnimationCurveBlobAssetRef(curveBlob); Measure.Method(() => { // The longer the time step, the more the cache gets reused. for (var t = keyframeCount * timeStep; t >= 0.0f; t -= 0.1f) { AnimationCurveEvaluator.Evaluate(t, ref curve); } }) .WarmupCount(1) .MeasurementCount(100) .Run(); curveBlob.Dispose(); }
static public int AddKey(IntPtr l) { try { int argc = LuaDLL.lua_gettop(l); if (argc == 4) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); System.Single a1; checkType(l, 3, out a1); System.Single a2; checkType(l, 4, out a2); var ret = self.AddKey(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); UnityEngine.Keyframe a1; checkValueType(l, 3, out a1); var ret = self.AddKey(a1); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function to call"); return(2); } catch (Exception e) { return(error(l, e)); } }
public ResourceObject Parse(ByteBuffer bb) { UnityEngine.AnimationClip clip = new UnityEngine.AnimationClip(); Schema.AnimationClip _clip = Schema.AnimationClip.GetRootAsAnimationClip(bb); clip.frameRate = _clip.FrameRate; clip.wrapMode = (UnityEngine.WrapMode)_clip.WrapMode; clip.legacy = true; for (int i = 0; i < _clip.BindingsLength; i++) { Schema.CurveBinding bind = _clip.GetBindings(i); Schema.AnimationCurve _curve = bind.Curve; UnityEngine.AnimationCurve curve = new UnityEngine.AnimationCurve(); for (int j = 0; j < _curve.KeyFramesLength; j++) { Schema.KeyFrame _kf = _curve.GetKeyFrames(j); UnityEngine.Keyframe kf = new UnityEngine.Keyframe(_kf.Time, _kf.Value, _kf.InTangent, _kf.OutTangent); kf.tangentMode = _kf.TangentMode; curve.AddKey(kf); } curve.preWrapMode = (UnityEngine.WrapMode)_curve.PreWrapMode; curve.postWrapMode = (UnityEngine.WrapMode)_curve.PostWrapMode; var assembly = Assembly.Load("UnityEngine"); Type type = assembly.GetType(bind.Type); clip.SetCurve(bind.Path, type, bind.PropertyName, curve); } return(new ResourceObjectSingle(clip)); }
public void ApplyToUnityParticleSystem(UnityEngine.ParticleSystem ups, ParticleSystem ps) { var sizeModule = ups.sizeOverLifetime; sizeModule.enabled = true; sizeModule.separateAxes = true; var curvX = new UnityEngine.AnimationCurve(); var curvY = new UnityEngine.AnimationCurve(); var curvZ = new UnityEngine.AnimationCurve(); //重复的key第二次不会添加 for (int i = keyFrameLifeTime.Count - 1; i >= 0; --i) { curvX.AddKey(keyFrameLifeTime[i], sizeX[i]); curvY.AddKey(keyFrameLifeTime[i], sizeY[i]); curvZ.AddKey(keyFrameLifeTime[i], sizeZ[i]); //curvZ.AddKey(keyFrameLifeTime[i], sizeZ[i] <= 0.001f ? 1.0f:sizeZ[i] ); } CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curvX); CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curvY); CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curvZ); sizeModule.x = new UnityEngine.ParticleSystem.MinMaxCurve(maxXYZ[0], curvX); //exchange yz if (maxXYZ[2] <= 0.001f) { sizeModule.y = new UnityEngine.ParticleSystem.MinMaxCurve(maxXYZ[1], curvY); } else { sizeModule.y = new UnityEngine.ParticleSystem.MinMaxCurve(maxXYZ[2], curvZ); } sizeModule.z = new UnityEngine.ParticleSystem.MinMaxCurve(maxXYZ[1], curvY); }
public static void Apply(UnityEngine.AnimationCurve src, UnityEngine.AnimationCurve dest) { dest.keys = new Keyframe[] {}; foreach (var keyf in src.keys) { dest.AddKey(keyf); } }
// Use this for initialization void Start() { Animation anim = GetComponent<Animation> (); AnimationCurve curve = new AnimationCurve(); curve.AddKey (0, 1); //curve.AddKey (1, 2); //curve.AddKey (2, 3); curve.AddKey (3, 4); curve.AddKey (6, -4); AnimationClip clip = new AnimationClip (); clip.legacy = true; clip.SetCurve ("", typeof(Transform), "localPosition.x", curve); anim.AddClip (clip, "test"); //anim.PlayQueued ("test2", QueueMode.CompleteOthers); //anim ["test"].speed = 3; anim.Play ("test"); }
public void TestStepAnimationCurveNode(float time) { var animCurve = new UnityEngine.AnimationCurve(); animCurve.AddKey(new UnityEngine.Keyframe(0, 0, Mathf.Infinity, Mathf.Infinity)); animCurve.AddKey(new UnityEngine.Keyframe(0.5f, 1, Mathf.Infinity, Mathf.Infinity)); animCurve.AddKey(new UnityEngine.Keyframe(1, 1, Mathf.Infinity, Mathf.Infinity)); var expected = animCurve.Evaluate(time); var dotsCurve = animCurve.ToDotsAnimationCurve(); var curveNode = CreateNode <EvaluateCurveNode>(); Set.SendMessage(curveNode, EvaluateCurveNode.SimulationPorts.AnimationCurve, dotsCurve); Set.SetData(curveNode, EvaluateCurveNode.KernelPorts.Time, time); var output = CreateGraphValue(curveNode, EvaluateCurveNode.KernelPorts.Output); Set.Update(default);
public static UnityEngine.AnimationCurve GenerateAnimationCurve(List <CurveAnchor> anchors, bool negative = false, float valueScale = 1.0f) { var curve = new UnityEngine.AnimationCurve(); foreach (CurveAnchor point in anchors) { curve.AddKey(point.Time, valueScale * point.Value * (negative ? -1.0f : 1.0f)); } CurveExtended.CurveExtension.ForceUpdateAllLinearTangents(curve); return(curve); }
public static AnimationCurve FromXMLtoAnimationCurve(XmlNode node) { AnimationCurve output = new AnimationCurve(); if(node == null || !node.HasChildNodes) { output.AddKey(0, 1); output.AddKey(1, 1); return output; } foreach(XmlNode keyframeNode in node.SelectNodes("keyframe")) { Keyframe keyFrame = new Keyframe(); keyFrame.inTangent = float.Parse(keyframeNode["inTangent"].FirstChild.Value); keyFrame.outTangent = float.Parse(keyframeNode["outTangent"].FirstChild.Value); keyFrame.time = float.Parse(keyframeNode["time"].FirstChild.Value); keyFrame.value = float.Parse(keyframeNode["value"].FirstChild.Value); output.AddKey(keyFrame); } return output; }
void Start() { m_InitialPosition = gameObject.transform.localPosition; m_WorldControler = GameObject.Find("GameWorld").GetComponent<WorldControllerScript>(); m_CurrentWorldNumber = m_WorldControler.GetCurrentWorldNumber(); m_RelPosition.Set(0, 0, 0); m_Translations = new Vector3[3]; m_Translations[0].Set(m_Speed, 0, 0); m_Translations[1].Set(0, m_Speed, 0); m_Translations[2].Set(0, 0, m_Speed); m_BumpersRenderer = new Renderer[2]; m_BumpersRenderer[0] = gameObject.transform.FindChild("bumperLeft").GetComponent<Renderer>(); m_BumpersRenderer[1] = gameObject.transform.FindChild("bumperRight").GetComponent<Renderer>(); m_LastUpdateWorldNumber = 0; m_IsMoving = true; gameObject.AddComponent<Animation>(); gameObject.animation.animatePhysics = true; m_Forward = new AnimationClip(); var curvex = new AnimationCurve(); var curvey = new AnimationCurve(); var curvez = new AnimationCurve(); var minpos = m_InitialPosition+m_MinIncrement; var maxpos = m_InitialPosition-m_MaxIncrement; float dist = (minpos-maxpos).magnitude; m_MaxTime = dist/m_Speed; curvex.AddKey(0f, minpos.x); curvex.AddKey(dist/m_Speed, maxpos.x); curvey.AddKey(0f, minpos.y); curvey.AddKey(dist/m_Speed, maxpos.y); curvez.AddKey(0f, minpos.z); curvez.AddKey(dist/m_Speed, maxpos.z); m_Forward.wrapMode = WrapMode.ClampForever; m_Forward.SetCurve("", typeof(Transform), "localPosition.x", curvex); m_Forward.SetCurve("", typeof(Transform), "localPosition.y", curvey); m_Forward.SetCurve("", typeof(Transform), "localPosition.z", curvez); this.animation.AddClip(m_Forward, "Forward"); this.animation.Play("Forward"); }
void Start() { flickerCurve = new AnimationCurve(new Keyframe[20]); Random.seed = (int)gameObject.GetInstanceID(); int keys = 20; for (int i = 0; i < keys; i++){ flickerCurve.AddKey(new Keyframe(1/(float)keys*(float)i,Random.Range(min,max))); } flickerCurve.preWrapMode = WrapMode.Loop; flickerCurve.postWrapMode = WrapMode.Loop; }
public AnimationCurve loadAnimationCurve(string[] curveData) { char[] cParams = new char[] { ' ', ',', ';', '\t' }; AnimationCurve animationCurve = new AnimationCurve(); try { for (int i = 0; i < curveData.Length; i++) { string[] keyTmp = curveData[i].Split(cParams, StringSplitOptions.RemoveEmptyEntries); if (keyTmp.Length == 4) { print("*RSS* " + keyTmp[0] + " " + keyTmp[1] + " " + keyTmp[2] + " " + keyTmp[3]); Keyframe key = new Keyframe(); key.time = float.Parse(keyTmp[0]); key.value = float.Parse(keyTmp[1]); key.inTangent = float.Parse(keyTmp[2]); key.outTangent = float.Parse(keyTmp[3]); animationCurve.AddKey(key); } else if (keyTmp.Length == 2) { print("*RSS* " + keyTmp[0] + " " + keyTmp[1]); Keyframe key = new Keyframe(); key.time = float.Parse(keyTmp[0]); key.value = float.Parse(keyTmp[1]); animationCurve.AddKey(key); } else { MonoBehaviour.print("*RSS* Invalid animationCurve data: animationCurve data must have exactly two or four parameters!"); } } return animationCurve; } catch (Exception e) { print("Caught exception while parsing animationcurve: " + e.Message); return null; } }
static public int AddKey(IntPtr l) { try { #if DEBUG var method = System.Reflection.MethodBase.GetCurrentMethod(); string methodName = GetMethodName(method); #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.BeginSample(methodName); #else Profiler.BeginSample(methodName); #endif #endif int argc = LuaDLL.lua_gettop(l); if (argc == 2) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); UnityEngine.Keyframe a1; checkValueType(l, 2, out a1); var ret = self.AddKey(a1); pushValue(l, true); pushValue(l, ret); return(2); } else if (argc == 3) { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); var ret = self.AddKey(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } pushValue(l, false); LuaDLL.lua_pushstring(l, "No matched override function AddKey to call"); return(2); } catch (Exception e) { return(error(l, e)); } #if DEBUG finally { #if UNITY_5_5_OR_NEWER UnityEngine.Profiling.Profiler.EndSample(); #else Profiler.EndSample(); #endif } #endif }
void UpdateCurve() { var spectrum = target as AudioSpectrum; // Create a new curve to update the UI. curve = new AnimationCurve (); // Add keys for the each band. var bands = spectrum.PeakLevels; for (var i = 0; i < bands.Length; i++) { curve.AddKey (1.0f / bands.Length * i, bands [i]); } }
public AnimationCurve getCustomEaseCurve() { AnimationCurve curve = new AnimationCurve(); if(customEase.Count < 0) { return curve; } if(customEase.Count % 4 != 0) { Debug.LogError("Animator: Error retrieving custom ease."); return curve; } for(int i=0;i<customEase.Count;i+=4) { curve.AddKey(new Keyframe(customEase[i],customEase[i+1],customEase[i+2],customEase[i+3])); } return curve; }
private AnimationCurve FlipCurve() { AnimationCurve newCurve = new AnimationCurve(); for (int i = 0; i < curve.length; i++) { Keyframe key = curve[i]; key.time = 1f - key.time; key.inTangent = key.inTangent * -1; key.outTangent = key.outTangent * -1; newCurve.AddKey(key); } return newCurve; }
static public int AddKey__Keyframe(IntPtr l) { try { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); UnityEngine.Keyframe a1; checkValueType(l, 2, out a1); var ret = self.AddKey(a1); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
public void SetDefaultValue(Vector3 value) { uniformValue = value; rangeX.min = value.x; rangeX.max = value.x; rangeY.min = value.y; rangeY.max = value.y; rangeZ.min = value.z; rangeZ.max = value.z; curveX = new UnityEngine.AnimationCurve(); curveX.AddKey(new UnityEngine.Keyframe(0, value.x)); curveY = new UnityEngine.AnimationCurve(); curveY.AddKey(new UnityEngine.Keyframe(0, value.y)); curveZ = new UnityEngine.AnimationCurve(); curveZ.AddKey(new UnityEngine.Keyframe(0, value.z)); }
void create_animation() { AnimationCurve curve_height,curve_x,curve_z; AnimationClip clip; Animation anim; tempcount = 4; time_slice[] height_data = new time_slice[144]; for (int time=0; time<143; time++) { height_data[time] = new time_slice(); for(int i=0;i<20*20;i++){ height_data[time].height[i] = float.Parse(strArr[tempcount-2]); height_data[time].x[i] = float.Parse(strArr[tempcount-3]); height_data[time].z[i] = float.Parse(strArr[tempcount-1]); tempcount = tempcount+4; } } Debug.Log (height_data.Length); tempcount = 0; for (float i=0; i<20; i++) { for (float j=-0; j<20; j++) { ammo = GameObject.Find (i.ToString () + "," + j.ToString () + "terrain"); anim = ammo.gameObject.GetComponent<Animation>(); curve_height = new AnimationCurve(); curve_x = new AnimationCurve(); curve_z = new AnimationCurve(); clip = new AnimationClip(); for(int k=0;k<143;k++){ curve_height.AddKey(k*timesclice,height_data[k].height[tempcount]); curve_x.AddKey(k*timesclice,height_data[k].x[tempcount]); curve_z.AddKey(k*timesclice,height_data[k].z[tempcount]); } tempcount++; clip.legacy = true; clip.SetCurve("",typeof(Transform), "localPosition.y", curve_height); clip.SetCurve("",typeof(Transform),"localPosition.x",curve_x); clip.SetCurve("",typeof(Transform), "localPosition.z", curve_z); anim.AddClip(clip,"anim"); anim.Play("anim"); //Debug.Log(clip.length); anim["anim"].speed =1; } } }
static public int AddKey__Single__Single(IntPtr l) { try { UnityEngine.AnimationCurve self = (UnityEngine.AnimationCurve)checkSelf(l); System.Single a1; checkType(l, 2, out a1); System.Single a2; checkType(l, 3, out a2); var ret = self.AddKey(a1, a2); pushValue(l, true); pushValue(l, ret); return(2); } catch (Exception e) { return(error(l, e)); } }
/// <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); }
/// <summary> /// Add a new key to an AnimationCurve. /// Ensures the integrity of other key's tangent modes. /// </summary> /// <param name="curve">The existing AnimationCurve.</param> /// <param name="keyframe">The new keyframe</param> /// <returns>The index of the newly added key.</returns> public static int AddKey(AnimationCurve curve, Keyframe keyframe) { if (curve.length == 0) { return curve.AddKey(keyframe); } else if (curve.length == 1) { // Save the existing keyframe data. (Unity changes the tangent info). Keyframe temp = curve[0]; int newIndex = curve.AddKey(keyframe); if(newIndex == -1) { return 0; } else if(newIndex == 0) { curve.MoveKey(1, temp); } else { curve.MoveKey(0, temp); } return newIndex; } else { Keyframe left = new Keyframe(); Keyframe right = new Keyframe(); for (int i = 0; i < curve.length - 1; i++) { Keyframe l = curve[i]; Keyframe r = curve[i + 1]; if (l.time < keyframe.time && keyframe.time < r.time) { left = l; right = r; } } int index = curve.AddKey(keyframe); // Handle left neighbour. if (index > 0) { // Restore the saved data. curve.MoveKey(index - 1, left); // Update tangent data based on tangent mode. int tangentMode = curve[index - 1].tangentMode; if (IsAuto(tangentMode)) { curve.SmoothTangents(index - 1, 0); } if (IsBroken(tangentMode)) { if (IsRightLinear(tangentMode)) { SetKeyRightLinear(curve, index - 1); } } } // Handle the Right neighbour. if (index < curve.length - 1) { // Restore the saved data. curve.MoveKey(index + 1, right); // Update tangent data based on tangent mode. int tangentMode = curve[index + 1].tangentMode; if (IsAuto(tangentMode)) { curve.SmoothTangents(index + 1, 0); } if (IsBroken(tangentMode)) { if (IsLeftLinear(tangentMode)) { SetKeyLeftLinear(curve, index + 1); } } } return index; } }
private static UnityEngine.AnimationClip ProcessClip(AssetStudio.AnimationClip animationClip, string savePath, string bundleName, string materialAttributeName, CoordinateAttributeSet attributeSet, UnityEngine.SkinnedMeshRenderer[] skinnedMeshRenderers) { var uCurve = new UnityEngine.AnimationCurve(); var vCurve = new UnityEngine.AnimationCurve(); var clip = animationClip.m_MuscleClip.m_Clip; var streamedFrames = clip.m_StreamedClip.ReadData(); var clipBindingConstant = animationClip.m_ClipBindingConstant; for (int frameIndex = 1; frameIndex < streamedFrames.Count - 1; frameIndex++) { StreamedClip.StreamedCurveKey uCoordKey = null, vCoordKey = null; foreach (var key in streamedFrames[frameIndex].keyList) { var binding = clipBindingConstant.FindBinding(key.index); if (binding.attribute == attributeSet.UAttribute) { uCoordKey = key; } else if (binding.attribute == attributeSet.VAttribute) { vCoordKey = key; } } if (uCoordKey == null || vCoordKey == null) { continue; } // Round to 0.25 steps since the input UVs might not match perfectly var roundedUv = new Vector2(Mathf.Round(uCoordKey.value * 4) / 4, Mathf.Round(vCoordKey.value * 4) / 4); var value = RtdxTextureTo2x4Mappings[roundedUv]; uCurve.AddKey(streamedFrames[frameIndex].time, value.x); vCurve.AddKey(streamedFrames[frameIndex].time, value.y); } var newClip = new UnityEngine.AnimationClip { frameRate = animationClip.m_SampleRate }; foreach (var skinnedMeshRenderer in skinnedMeshRenderers) { AnimationUtility.SetEditorCurve(newClip, new EditorCurveBinding { path = skinnedMeshRenderer.gameObject.name, type = typeof(UnityEngine.SkinnedMeshRenderer), propertyName = $"material.{materialAttributeName}.z" }, uCurve); AnimationUtility.SetEditorCurve(newClip, new EditorCurveBinding { path = skinnedMeshRenderer.gameObject.name, type = typeof(UnityEngine.SkinnedMeshRenderer), propertyName = $"material.{materialAttributeName}.w" }, vCurve); } // We need to use this stupid workaround instead of doing it when adding the key because // apparently it glitches if the curve wasn't added to an animation AnimationHelpers.SetAnimationTangentsToConstant(newClip); string animationPath = $"{savePath}/{animationClip.m_Name}.anim"; AssetDatabase.CreateAsset(newClip, animationPath); AssetImporter.GetAtPath(animationPath).assetBundleName = bundleName; return(newClip); }
void Load() { if (PathToSpecFile.Length == 0) { _spectroCurves = null; return; } string filePath = Application.streamingAssetsPath + "/" + PathToSpecFile; FileStream fs = File.OpenRead(filePath); BinaryReader b = new BinaryReader(fs); int numCurves = b.ReadInt32(); //float sampleRate = b.ReadSingle(); //float timeBetweenSamples = 1.0f / sampleRate; float timeBetweenSamples = b.ReadSingle(); _spectroCurves = new AnimationCurve[numCurves]; float time = 0.0f; for (int i = 0; i < numCurves; i++) { AnimationCurve curve = new AnimationCurve(); _spectroCurves[i] = curve; time = 0.0f; float[] curveValues = ReadFloats(b); for (int j = 0; j < curveValues.Length; j++) { curve.AddKey(time, curveValues[j]); time += timeBetweenSamples; } } //Debug.Log("Loaded " + time + " seconds of FFT data from " + PathToSpecFile); //_fftFreqBands = ReadFloats(b); }
void Start () { ShaderChange = 0; // VS AnimationCurve To C# for Wind // Put this code on 'Start' or 'Awake' fonction Wind= new AnimationCurve(); Wind.AddKey(0,0); Wind.keys[0].tangentMode = 0; Wind.keys[0].inTangent = 0f; Wind.keys[0].outTangent = 0f; Wind.AddKey(0.1004994f,0.06637689f); Wind.keys[1].tangentMode = 0; Wind.keys[1].inTangent = 0f; Wind.keys[1].outTangent = 0f; Wind.AddKey(0.2430963f,-0.06465532f); Wind.keys[2].tangentMode = 0; Wind.keys[2].inTangent = -0.07599592f; Wind.keys[2].outTangent = -0.07599592f; Wind.AddKey(0.3425266f,0.02290122f); Wind.keys[3].tangentMode = 0; Wind.keys[3].inTangent = 0.03580004f; Wind.keys[3].outTangent = 0.03580004f; Wind.AddKey(0.4246872f,-0.02232522f); Wind.keys[4].tangentMode = 0; Wind.keys[4].inTangent = -0.006025657f; Wind.keys[4].outTangent = -0.006025657f; Wind.AddKey(0.5104106f,0.1647801f); Wind.keys[5].tangentMode = 0; Wind.keys[5].inTangent = 0.02981164f; Wind.keys[5].outTangent = 0.02981164f; Wind.AddKey(0.6082056f,-0.04679203f); Wind.keys[6].tangentMode = 0; Wind.keys[6].inTangent = -0.3176928f; Wind.keys[6].outTangent = -0.3176928f; Wind.AddKey(0.7794942f,0.2234365f); Wind.keys[7].tangentMode = 0; Wind.keys[7].inTangent = 0.2063811f; Wind.keys[7].outTangent = 0.2063811f; Wind.AddKey(0.8546611f,-0.003165513f); Wind.keys[8].tangentMode = 0; Wind.keys[8].inTangent = 0.02264977f; Wind.keys[8].outTangent = 0.02264977f; Wind.AddKey(1.022495f,-0.07358052f); Wind.keys[9].tangentMode = 0; Wind.keys[9].inTangent = 2.450916f; Wind.keys[9].outTangent = 2.450916f; Wind.AddKey(1.250894f,-0.1813075f); Wind.keys[10].tangentMode = 0; Wind.keys[10].inTangent = 0.02214685f; Wind.keys[10].outTangent = 0.02214685f; Wind.AddKey(1.369877f,-0.06861454f); Wind.keys[11].tangentMode = 0; Wind.keys[11].inTangent = -1.860534f; Wind.keys[11].outTangent = -1.860534f; Wind.AddKey(1.484951f,-0.1543293f); Wind.keys[12].tangentMode = 0; Wind.keys[12].inTangent = 0.0602752f; Wind.keys[12].outTangent = 0.0602752f; Wind.AddKey(1.583562f,0.100938f); Wind.keys[13].tangentMode = 0; Wind.keys[13].inTangent = 0.08665025f; Wind.keys[13].outTangent = 0.08665025f; Wind.AddKey(1.687307f,-0.100769f); Wind.keys[14].tangentMode = 0; Wind.keys[14].inTangent = 0.01110137f; Wind.keys[14].outTangent = 0.01110137f; Wind.AddKey(1.797593f,0.04921142f); Wind.keys[15].tangentMode = 0; Wind.keys[15].inTangent = 3.407104f; Wind.keys[15].outTangent = 3.407104f; Wind.AddKey(1.927248f,-0.1877219f); Wind.keys[16].tangentMode = 0; Wind.keys[16].inTangent = -0.001117587f; Wind.keys[16].outTangent = -0.001117587f; Wind.AddKey(2.067694f,0.2742145f); Wind.keys[17].tangentMode = 0; Wind.keys[17].inTangent = 4.736587f; Wind.keys[17].outTangent = 4.736587f; Wind.AddKey(2.184602f,-0.06127208f); Wind.keys[18].tangentMode = 0; Wind.keys[18].inTangent = -0.1308322f; Wind.keys[18].outTangent = -0.1308322f; Wind.AddKey(2.305948f,0.1891117f); Wind.keys[19].tangentMode = 0; Wind.keys[19].inTangent = 0.04030764f; Wind.keys[19].outTangent = 0.04030764f; Wind.AddKey(2.428946f,-0.1695723f); Wind.keys[20].tangentMode = 0; Wind.keys[20].inTangent = -0.2463162f; Wind.keys[20].outTangent = -0.2463162f; Wind.AddKey(2.55922f,0.0359862f); Wind.keys[21].tangentMode = 0; Wind.keys[21].inTangent = 0.3967434f; Wind.keys[21].outTangent = 0.3967434f; Wind.AddKey(2.785119f,-0.08398628f); Wind.keys[22].tangentMode = 0; Wind.keys[22].inTangent = -0.2388284f; Wind.keys[22].outTangent = -0.2388284f; Wind.AddKey(3f,0f); Wind.keys[23].tangentMode = 0; Wind.keys[23].inTangent = 0f; Wind.keys[23].outTangent = 0f; Wind.postWrapMode= WrapMode.Loop; Wind.preWrapMode= WrapMode.Loop; }
static AnimationCurve EnsureCurveKeyCount (AnimationCurve curve) { if (curve.length == 1) curve.AddKey(curve.keys[0].time + 0.25f, curve.keys[0].value); return curve; }
void OnWizardCreate() { //test create animation /* AnimationClip clip = new AnimationClip (); AnimationCurve curveX = new AnimationCurve (); AnimationCurve curveY = new AnimationCurve (); AnimationCurve curveZ = new AnimationCurve (); for (int i=0; i<=60; i++) { curveX.AddKey (i / 60f, i); curveY.AddKey (i / 60f, i); curveZ.AddKey (i / 60f, i); } clip.SetCurve ("root", typeof(Transform), "m_LocalPosition.x", curveX); clip.SetCurve ("root", typeof(Transform), "m_LocalPosition.y", curveY); clip.SetCurve ("root", typeof(Transform), "m_LocalPosition.z", curveZ); AssetDatabase.CreateAsset (clip, "Assets/CreatedAsset/testAnim.anim"); */ if (anmFile == null) { Debug.LogError ("null anm file"); return; } //try { AnimationClip clip = new AnimationClip(); string anmPath = AssetDatabase.GetAssetPath (anmFile); Dictionary<string,string> nameToPath = new Dictionary<string, string>(); if(obj != null) { Transform[] children = obj.GetComponentsInChildren<Transform>(); foreach(Transform child in children) { Transform cur = child; string path = child.name; while(cur != null && cur.parent != obj && cur.parent != null) { cur = cur.parent; path = cur.name + "/" + path; } Debug.Log(child.name); nameToPath.Add (child.name,path); } } using (FileStream fs = File.OpenRead(anmPath)) { byte[] headerBlock = new byte[28]; fs.Read (headerBlock, 0, 28); string id = System.Text.Encoding.ASCII.GetString (headerBlock, 0, 8).TrimEnd ('\0'); int version = BitConverter.ToInt32 (headerBlock, 8); int dontknow = BitConverter.ToInt32 (headerBlock, 12); int numOfBones = BitConverter.ToInt32 (headerBlock, 16); int numOfFrames = BitConverter.ToInt32 (headerBlock, 20); int playBackFPS = BitConverter.ToInt32 (headerBlock, 24); //int boneBlockSize = 36 + (numOfFrames * 28); byte[] boneHeaderBlock = new byte[36]; byte[] frameBlock = new byte[28]; for (int i=0; i<numOfBones; i++) { fs.Read (boneHeaderBlock, 0, 36); string boneName = System.Text.Encoding.ASCII.GetString (boneHeaderBlock, 0, 32).TrimEnd ('\0'); int dontknow2 = BitConverter.ToInt32 (boneHeaderBlock, 32); string path = boneName; if(nameToPath.ContainsKey(boneName)) { path = nameToPath[boneName]; } AnimationCurve curveRX = new AnimationCurve(); AnimationCurve curveRY = new AnimationCurve(); AnimationCurve curveRZ = new AnimationCurve(); AnimationCurve curveRW = new AnimationCurve(); AnimationCurve curvePX = new AnimationCurve(); AnimationCurve curvePY = new AnimationCurve(); AnimationCurve curvePZ = new AnimationCurve(); for (int j=0; j<numOfFrames; j++) { fs.Read (frameBlock, 0, 28); float rx = BitConverter.ToSingle (frameBlock, 0); float ry = BitConverter.ToSingle (frameBlock, 4); float rz = BitConverter.ToSingle (frameBlock, 8); float rw = BitConverter.ToSingle (frameBlock, 12); float px = BitConverter.ToSingle (frameBlock, 16); float py = BitConverter.ToSingle (frameBlock, 20); float pz = BitConverter.ToSingle (frameBlock, 24); float time = j/60f; curveRX.AddKey(time,rx); curveRY.AddKey(time,ry); curveRZ.AddKey (time,rz); curveRW.AddKey(time,rw); curvePX.AddKey(time,px); curvePY.AddKey(time,py); curvePZ.AddKey(time,pz); } clip.SetCurve(path,typeof(Transform),"m_LocalRotation.x",curveRX); clip.SetCurve(path,typeof(Transform),"m_LocalRotation.y",curveRY); clip.SetCurve(path,typeof(Transform),"m_LocalRotation.z",curveRZ); clip.SetCurve(path,typeof(Transform),"m_LocalRotation.w",curveRW); clip.SetCurve(path,typeof(Transform),"m_LocalPosition.x",curvePX); clip.SetCurve(path,typeof(Transform),"m_LocalPosition.y",curvePY); clip.SetCurve(path,typeof(Transform),"m_LocalPosition.z",curvePZ); } /* Debug.Log ("version : " + version + "\nnum of bones : " + numOfBones + "\nnum of frames : " + numOfFrames + "\nplaybackFPS : " + playBackFPS); int expectedsize = 28 + ((28 * numOfFrames) + 36) * numOfBones; Debug.Log ("Expected Size : " + expectedsize + "\nread Size : " + fs.Length);*/ AssetDatabase.CreateAsset(clip,"Assets/CreatedAsset/"+name+".anim"); } //} catch (Exception e) { // Debug.LogError(e); //} }
private void SetKeys (AnimationCurve curve, TimeLine timeLine, Func<SpatialInfo, float> infoValue, Animation animation) { foreach (var key in timeLine.keys) { //Create a keyframe for every key on its personal TimeLine curve.AddKey (key.time, infoValue (key.info)); } var lastIndex = (animation.looping) ? 0 : timeLine.keys.Length - 1; //Depending on the loop type, duplicate the first or last frame curve.AddKey (animation.length, infoValue (timeLine.keys [lastIndex].info)); //At the end of the curve }
private void SetKeys (AnimationCurve curve, TimeLine timeLine, ref Sprite[] sprites, Animation animation) { foreach (var key in timeLine.keys) { //Create a key for every key on its personal TimeLine var info = (SpriteInfo)key.info; curve.AddKey (new Keyframe (key.time, GetIndexOrAdd (ref sprites, Folders [info.folder] [info.file]), inf, inf)); } //InTangent and OutTangent are set to Infinity to make transitions instant instead of gradual var lastIndex = (animation.looping) ? 0 : timeLine.keys.Length - 1; var lastInfo = (SpriteInfo)timeLine.keys [lastIndex].info; curve.AddKey (new Keyframe (animation.length, GetIndexOrAdd (ref sprites, Folders [lastInfo.folder] [lastInfo.file]), inf, inf)); }
public static AnimationCurve AnimationCurveFromString(string s, float defaultBurnTime) { AnimationCurve ac = new AnimationCurve(); if (s == "") { Debug.LogWarning("No Burn Profile found! Defaulting to constant burn rate."); ac.AddKey(0, (float)(1 / defaultBurnTime)); return ac; } //Debug.Log(s); s.Trim(); Char[] delimiters = new Char[] { ',', ';' }; String[] result; String time; String value; String inTang; String outTang; Keyframe k = new Keyframe(); bool cont = true; int i = 0; do { result = s.Split(delimiters, 2); time = result[0]; s = result[1]; result = s.Split(delimiters, 2); value = result[0]; s = result[1]; result = s.Split(delimiters, 2); inTang = result[0]; s = result[1]; result = s.Split(delimiters, 2); outTang = result[0]; if (result.Length > 1) { s = result[1]; cont = true; } else cont = false; k.time = Convert.ToSingle(time); k.value = Convert.ToSingle(value); k.inTangent = Convert.ToSingle(inTang); k.outTangent = Convert.ToSingle(outTang); ac.AddKey(k); i++; } while (cont); return ac; }