// Token: 0x0600011B RID: 283 RVA: 0x0000B0F0 File Offset: 0x000092F0 private static AnimationCurve BytesToAnimationCurve(byte[] bytes, int dataPosition) { AnimationCurve animationCurve = new AnimationCurve(); int num = BitConverter.ToInt32(bytes, dataPosition); for (int i = 0; i < num; i++) { Keyframe keyframe = default(Keyframe); keyframe.time = BitConverter.ToSingle(bytes, dataPosition + 4); keyframe.value = BitConverter.ToSingle(bytes, dataPosition + 8); keyframe.inTangent = BitConverter.ToSingle(bytes, dataPosition + 12); keyframe.outTangent = BitConverter.ToSingle(bytes, dataPosition + 16); keyframe.tangentMode = BitConverter.ToInt32(bytes, dataPosition + 20); animationCurve.AddKey(keyframe); dataPosition += 20; } animationCurve.preWrapMode = (WrapMode)BitConverter.ToInt32(bytes, dataPosition + 4); animationCurve.postWrapMode = (WrapMode)BitConverter.ToInt32(bytes, dataPosition + 8); return(animationCurve); }
public static AnimationCurve InverseCurve(AnimationCurve curve) { AnimationCurve reversedCurve = new AnimationCurve(); //Get Time/Value and reverse the value float[] time = new float[curve.keys.Length]; float[] value = new float[curve.keys.Length]; int index = curve.keys.Length - 1; for (int i = 0; i < curve.keys.Length; i++) { time[i] = curve.keys[i].time; value[i] = curve.keys[index].time; reversedCurve.AddKey(time[i], value[i]); index--; } return(reversedCurve); }
public int AddKey(float time, Vector3 position, Vector3 euler_angles) { Quaternion quat = Quaternion.identity; quat.eulerAngles = euler_angles; int [] values = { posx.AddKey(time, position.x), posy.AddKey(time, position.y), posz.AddKey(time, position.z), anglex.AddKey(time, euler_angles.x), angley.AddKey(time, euler_angles.y), anglez.AddKey(time, euler_angles.z), rotx.AddKey(time, quat.x), roty.AddKey(time, quat.y), rotz.AddKey(time, quat.z), rotw.AddKey(time, quat.w), }; return(Mathf.Min(values)); }
public AnimationCurve getCustomEaseCurve() { if (customEase.Count == 0) { return(new AnimationCurve()); } if (customEase.Count % 4 != 0) { Debug.LogError("Animator: Error retrieving custom ease."); return(new AnimationCurve()); } AnimationCurve curve = new AnimationCurve(); 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); }
public override void PerBeginRecord() { base.PerBeginRecord(); animTime = new AnimationCurve(); animName = new List <animNameInfo>(); if (animator == null) { animator = GetComponent <Animator>(); if (animator == null) { Debug.LogError("animation recording object is null =>" + this.gameObject.name); enabled = false; } } Data.lastState.animaeEnable = animator.enabled; animTime.AddKey(createKey(RecordManager.Instance.GetCurrentTime(), animator.GetCurrentAnimatorStateInfo(0).normalizedTime) ); lastAnimNameHash = getCurrentName(); animName.Add(new animNameInfo(lastAnimNameHash)); }
private AnimationCurve ProcessRootCurve(AnimationCurve source) { float value = source.Evaluate(0f); float duration = source.keys[source.length - 1].time; AnimationCurve result = new AnimationCurve(); for (int i = 0; i < source.keys.Length; ++i) { result.AddKey(new Keyframe( source.keys[i].time / duration, source.keys[i].value - value, source.keys[i].inTangent, source.keys[i].outTangent, source.keys[i].inWeight, source.keys[i].outWeight )); } return(result); }
internal void Flip() { if (this.curve.length >= 2) { AnimationCurve curve = new AnimationCurve(); float num = this.curve.keys[0].time; float num2 = this.curve.keys[this.curve.length - 1].time; for (int i = 0; i < this.curve.length; i++) { Keyframe keyframe = this.GetKeyframe(i); float num4 = (num2 - keyframe.time) + num; float introduced8 = keyframe.value; float introduced9 = keyframe.inTangent; Keyframe keyframe3 = new Keyframe(num4, introduced8, introduced9, keyframe.outTangent); keyframe3.tangentMode = (keyframe.tangentMode); curve.AddKey(keyframe3); } this.Curve = curve; } }
private void LoadKeyFrames(List <Dsl.ISyntaxComponent> statements) { m_Curve = new AnimationCurve(); for (int i = 0; i < statements.Count; i++) { Dsl.CallData stCall = statements[i] as Dsl.CallData; if (stCall.GetId() == "keyframe") { if (stCall.GetParamNum() >= 4) { float time = float.Parse(stCall.GetParamId(0)); float value = float.Parse(stCall.GetParamId(1)); float inTangent = float.Parse(stCall.GetParamId(2)); float outTangent = float.Parse(stCall.GetParamId(3)); Keyframe keyframe = new Keyframe(time, value, inTangent, outTangent); m_Curve.AddKey(keyframe); } } } }
internal void Flip() { if (curve.length < 2) { return; } AnimationCurve animationCurve = new AnimationCurve(); float time = curve[0].time; float time2 = this.curve[this.curve.length - 1].time; for (int i = 0; i < this.curve.length; i++) { Keyframe keyframe = this.GetKeyframe(i); float num = time2 - keyframe.time + time; Keyframe keyframe2 = new Keyframe(num, keyframe.value, keyframe.inTangent, keyframe.outTangent); keyframe2.tangentMode = (keyframe.tangentMode); animationCurve.AddKey(keyframe2); } Curve = animationCurve; }
private void UpdateWidthCurve() { float num = Vector3.SqrMagnitude(head.transform.position - tail.transform.position); float num2 = num / 2f; AnimationCurve animationCurve = new AnimationCurve(); float num3 = 0f; do { float num4 = Mathf.Lerp(0f, num, num3); float num5 = Mathf.Abs(num2 - num4); if (itoBreaking && num2 - num4 < 0f) { num5 = 0f; } animationCurve.AddKey(num3, siruAmount * num5 / (num * distanceReduction)); num3 += 0.01f; }while (!(num3 > 1f)); ito.widthCurve = animationCurve; }
/// <summary> /// Recalculate movement input based on current value /// </summary> /// <param name="current"></param> private void RecalculateMovementInput(Vector3 current) { float totalDistance = Mathf.Abs(Vector3.Distance(_max, _min)); float currentDistance = Mathf.Abs(Vector3.Distance(current, _min)); _movementInput = totalDistance == 0f ? 0f : (currentDistance / totalDistance); if (_movingMode == MovingMode.Function) { _inverseMovementFunction = new AnimationCurve(); for (int i = 0; i < _movementFunction.length; i++) { Keyframe inverseKey = new Keyframe(_movementFunction.keys[i].value, _movementFunction.keys[i].time, InverseTangent(_movementFunction.keys[i].outTangent), InverseTangent(_movementFunction.keys[i].inTangent)); _inverseMovementFunction.AddKey(inverseKey); } _movementInput = _inverseMovementFunction.Evaluate(_movementInput); } }
public int AddKey(float time, Vector3 position, Quaternion rotation, Vector3 scale, float inTangent, float outTangent) { int index = _posX.AddKey(new Keyframe(time, position.x, inTangent, outTangent)); _posY.AddKey(new Keyframe(time, position.y, inTangent, outTangent)); _posZ.AddKey(new Keyframe(time, position.z, inTangent, outTangent)); Quaternion fixedRotation = Quaternion.Euler(CentreAngles(rotation.eulerAngles)); _rotX.AddKey(new Keyframe(time, fixedRotation.x, inTangent, outTangent)); _rotY.AddKey(new Keyframe(time, fixedRotation.y, inTangent, outTangent)); _rotZ.AddKey(new Keyframe(time, fixedRotation.z, inTangent, outTangent)); _rotW.AddKey(new Keyframe(time, fixedRotation.w, inTangent, outTangent)); _scaleX.AddKey(new Keyframe(time, scale.x, inTangent, outTangent)); _scaleY.AddKey(new Keyframe(time, scale.y, inTangent, outTangent)); _scaleZ.AddKey(new Keyframe(time, scale.z, inTangent, outTangent)); return(index); }
public void NormalizeCurveTime() { int n = 0; while (n < m_AniCurve.keys.Length) { Keyframe key = m_AniCurve[n]; float fMax = Mathf.Max(0, key.time); float fVal = Mathf.Min(1, Mathf.Max(fMax, key.time)); if (fVal != key.time) { Keyframe newKey = new Keyframe(fVal, key.value, key.inTangent, key.outTangent); m_AniCurve.RemoveKey(n); n = 0; m_AniCurve.AddKey(newKey); continue; } n++; } }
private void Start() { instance = this; GameManager.OnGameEnd += GameManager_OnGameEnd; demands = new List <AnimationCurve>(); //Each Game has its own curve, so loop that too for (int i = 0; i < gameNames.Count; i++) { AnimationCurve curve = new AnimationCurve(); foreach (var key in demandKeypoints) { curve.AddKey(new Keyframe(key.day, key.dynamics[i])); } demands.Add(CurveModifier.SetCurveLinear(curve)); } salePrices = new List <AnimationCurve>(); for (int i = 0; i < gameNames.Count; i++) { AnimationCurve curve = new AnimationCurve(); foreach (var key in saleKeypoints) { curve.AddKey(new Keyframe(key.day, key.dynamics[i])); } salePrices.Add(CurveModifier.SetCurveLinear(curve)); } buyPrices = new List <AnimationCurve>(); for (int i = 0; i < gameNames.Count; i++) { AnimationCurve curve = new AnimationCurve(); foreach (var key in buyKeypoints) { curve.AddKey(new Keyframe(key.day, key.dynamics[i])); } buyPrices.Add(CurveModifier.SetCurveLinear(curve)); } }
void Start() { if (pos.Count < 1) { return; } float totalDistance = 0, curDis = 0; Vector3 dir; particle.transform.position = new Vector3(0, 0, -2); for (int i = 1; i < pos.Count; ++i) { curDis = Vector3.Distance(pos[i], pos[i - 1]); dir = pos[i] - pos[i - 1]; //dir.Normalize(); frames.Enqueue(new frame(dir, curDis)); totalDistance += curDis; } float time = 0; while (frames.Count > 0) { frame data = frames.Dequeue(); curveX.AddKey(new Keyframe(time, data.dir.x, float.PositiveInfinity, float.PositiveInfinity)); curveY.AddKey(new Keyframe(time, data.dir.y, float.PositiveInfinity, float.PositiveInfinity)); curveZ.AddKey(new Keyframe(time, data.dir.z, float.PositiveInfinity, float.PositiveInfinity)); time += data.dis / totalDistance; } var velocity = particle.velocityOverLifetime; velocity.enabled = true; float scale = 50 / particle.startLifetime; velocity.space = ParticleSystemSimulationSpace.Local; velocity.x = new ParticleSystem.MinMaxCurve(1, curveX); velocity.y = new ParticleSystem.MinMaxCurve(1, curveY); velocity.z = new ParticleSystem.MinMaxCurve(1, curveZ); }
public IEnumerator SpawnFirework(float comboMod, Vector3 startPosition) { GameObject firework = Instantiate(fireworkPrefab); firework.transform.position = startPosition; ParticleSystem pSystem = firework.GetComponent <ParticleSystem>(); float comboBonusScalar = 1; //Applied to the size during these special ones Vector3 toAim; float yieldTime = .2f; if (DoctorMatchGameManager.Instance.comboController.ComboLevel == 2) //Big combo bonus { pSystem.startColor = Color.blue; comboBonusScalar = 1.1f; toAim = comboTransform.position; yieldTime = .6f; } else if (DoctorMatchGameManager.Instance.comboController.ComboLevel == 1) //Small combo bonus { pSystem.startColor = Color.green; comboBonusScalar = 1.1f; toAim = scoreTransform.position; yieldTime = .4f; } else { toAim = selectorTransform.position; } ParticleSystem.LimitVelocityOverLifetimeModule emissionModule = pSystem.limitVelocityOverLifetime; //HACK: Currently, you cannot modify particle system module curves directly, so we save it here and modify it later AnimationCurve ourCurve = new AnimationCurve(); for (float i = 0; i <= 1; i += .1f) { ourCurve.AddKey(i, 250 * Mathf.Pow(i - 1, 4)); //Kind of like quadratic but it gets roughly flat after .5 } emissionModule.limit = new ParticleSystem.MinMaxCurve((1 + comboMod / 20) * comboBonusScalar, ourCurve); pSystem.startSize *= (1 + comboMod / 10) * comboBonusScalar; yield return(new WaitForSeconds(yieldTime)); //Need to wait for the burst to fully stretch before we move it pSystem.GetComponent <ParticleZoom>().StartZoom(toAim); }
public static float ProjectileRotatingBandDrag(ProjectileData projectileData, float speedOfSound, float projectileSpeed) { AnimationCurve animCurve = new AnimationCurve(); //Get in inmportant points animCurve.AddKey(0.0f, 0.0f); animCurve.AddKey(0.4f, 0.0f); animCurve.AddKey(0.9f, 0.5f); animCurve.AddKey(1.2f, 3.1f); animCurve.AddKey(2.0f, 2.5f); animCurve.AddKey(4.0f, 2.5f); //Really could simplify below expression return(animCurve.Evaluate(projectileSpeed / speedOfSound) * ((projectileData.driveBandDiameter / projectileData.bulletDiameter) / (projectileData.bulletDiameter / projectileData.bulletDiameter))); }
//DONE public int AddKeyframe(Transform TransformToAdd, float time) { indexkey++; int indexKeyReturn = 0; //animationTime = keyframeTimestep * indexkey; Debug.Log(TransformToAdd); Debug.Log(curveRotationW); //FOR UI ELEMENTS if (isRectTransform) { indexKeyReturn = curveWidth.AddKey(time, UItransform.rect.width); curveHeight.AddKey(time, UItransform.rect.height); curvePositionX.AddKey(time, UItransform.anchoredPosition.x); curvePositionY.AddKey(time, UItransform.anchoredPosition.y); } //FOR GAMEOBJECTS else { curveRotationW.AddKey(time, TransformToAdd.localRotation.w); curveRotationX.AddKey(time, TransformToAdd.localRotation.x); curveRotationY.AddKey(time, TransformToAdd.localRotation.y); curveRotationZ.AddKey(time, TransformToAdd.localRotation.z); curveScaleX.AddKey(time, TransformToAdd.localScale.x); curveScaleY.AddKey(time, TransformToAdd.localScale.y); curveScaleZ.AddKey(time, TransformToAdd.localScale.z); curvePositionX.AddKey(time, TransformToAdd.localPosition.x); curvePositionY.AddKey(time, TransformToAdd.localPosition.y); indexKeyReturn = curvePositionZ.AddKey(time, TransformToAdd.localPosition.z); } //indexkey++; UpdateAnimation(); return(indexKeyReturn); }
//Can also override //<< AddAnimationCurve name time1 value1 [smooth weight1] time2 value2 [smooth weight2] ... >> public override void Run(string[] info) { if (!CheckName(info[0])) { return; } string name = info[1]; AnimationCurve curve = new AnimationCurve(); int indexToSmooth = -1; List <KeyValuePair <int, float> > smoothTangents = new List <KeyValuePair <int, float> >(); for (int i = 2; i < info.Length; i = i + 2) { float weight; if (!Single.TryParse(info[i + 1], out weight)) { continue; } if (info[i].Equals("smooth")) { smoothTangents.Add(new KeyValuePair <int, float>(indexToSmooth, weight)); } else { float time; if (!Single.TryParse(info[i + 1], out time)) { continue; } curve.AddKey(new Keyframe(time, weight)); indexToSmooth++; } } foreach (KeyValuePair <int, float> kvp in smoothTangents) { curve.SmoothTangents(kvp.Key, kvp.Value); } DefaultData.Instance.AddCurve(name, curve); }
public void OnClickBackGround(Vector2 vec2) { GameObject key = Instantiate(Resources.Load <GameObject>("Prefab/key")); key.transform.parent = _keys.transform; key.transform.localScale = Vector3.one * 0.3f; // key.transform.localPosition = Vector3.zero; key.transform.position = transform.position + new Vector3( vec2.x - transform.position.x, // ワールド座標 vec2.y - transform.position.y, 0 ); // AnimationCurve座標 float a_time = ((vec2.x - _backGround.position.x) / (_backGround.localScale.x / _nazo) + 50f) / 100f; float a_value = ((vec2.y - _backGround.position.y) / _backGround.localScale.y + 50f) / 100f; _animationCurve.AddKey(a_time, a_value - 0.5f); key.name = a_time.ToString(); DrawLine(); }
protected AnimationClip CreateRotationClip(AnimationClip clip, Quaternion[] rotations, float[] times) { AnimationCurve curveW = new AnimationCurve(); AnimationCurve curveX = new AnimationCurve(); AnimationCurve curveY = new AnimationCurve(); AnimationCurve curveZ = new AnimationCurve(); for (int i = 0; i < times.GetLength(0); i++) { curveW.AddKey(times[i], rotations[i].w); curveX.AddKey(times[i], rotations[i].x); curveY.AddKey(times[i], rotations[i].y); curveZ.AddKey(times[i], rotations[i].z); } clip.SetCurve("", typeof(Transform), "localRotation.w", curveW); clip.SetCurve("", typeof(Transform), "localRotation.x", curveX); clip.SetCurve("", typeof(Transform), "localRotation.y", curveY); clip.SetCurve("", typeof(Transform), "localRotation.z", curveZ); return(clip); }
public static void Reverse(this AnimationCurve curve) { if (curve.length < 2) { return; } var currentLength = curve[curve.length - 1].time; var keys = curve.keys.ToList(); while (curve.length > 0) { curve.RemoveKey(0); } for (var i = 0; i < keys.Count; i++) { var key = keys[i]; curve.AddKey((currentLength - key.time).Snap(), key.value); } }
public void CalculateSmoothHeigthsProfile() //float [] heightsProfile, float [] smoothHeightsProfile) { { smoothHeightsProfileCurve = new AnimationCurve(); smoothHeightsProfile = new float[heightsProfile.Length]; for (int i = 0; i < smoothHeightsProfile.Length; i++) { smoothHeightsProfile [i] = 0; int avNumber = 0; for (int j = -windowSize; j < windowSize; j++) { int k = i + j; if (k >= 0 && k < smoothHeightsProfile.Length) { smoothHeightsProfile [i] += heightsProfile[k]; avNumber++; } } smoothHeightsProfile[i] = smoothHeightsProfile[i] / (float)avNumber; smoothHeightsProfileCurve.AddKey(pArray [i], smoothHeightsProfile [i]); } }
public static void MakeCurve(Queue <FrameDate> frames, float totalDistance, float totalTime, out AnimationCurve curve_X, out AnimationCurve curve_Y, out AnimationCurve curve_Z) { curve_X = new AnimationCurve(); curve_Y = new AnimationCurve(); curve_Z = new AnimationCurve(); float curTime = 0; while (frames.Count > 0) { FrameDate data = frames.Dequeue(); curve_X.AddKey(new Keyframe(curTime, data.Direction.x, float.PositiveInfinity, float.PositiveInfinity)); curve_Y.AddKey(new Keyframe(curTime, data.Direction.y, float.PositiveInfinity, float.PositiveInfinity)); curve_Z.AddKey(new Keyframe(curTime, data.Direction.z, float.PositiveInfinity, float.PositiveInfinity)); curTime += (data.Distance / totalDistance); } }
private void DrawFunc() { var cnt = 0; var firstTime = coughCurve.keys.Length == 0; for (float i = 0; i < 10; i += 0.1f) { var x2 = i; var y2 = CoughFunction(i); var keyframe = new Keyframe(x2, y2); if (firstTime) { coughCurve.AddKey(keyframe); } else { coughCurve.MoveKey(cnt, keyframe); cnt++; } } }
/// <summary> /// AnimationCurve変換 /// </summary> /// <param name="param"></param> /// <returns></returns> protected AnimationCurve ConvertAnimationCurve(XmlElement param) { AnimationCurve val = new AnimationCurve { preWrapMode = (WrapMode)int.Parse(param.SelectSingleNode("preWrapMode").InnerText), postWrapMode = (WrapMode)int.Parse(param.SelectSingleNode("postWrapMode").InnerText) }; foreach (XmlElement keyFrameData in param.SelectNodes("Keys/Key")) { Keyframe cloneKey = new Keyframe { time = float.Parse(keyFrameData.SelectSingleNode("time").InnerText), value = float.Parse(keyFrameData.SelectSingleNode("value").InnerText), inTangent = float.Parse(keyFrameData.SelectSingleNode("inTangent").InnerText), outTangent = float.Parse(keyFrameData.SelectSingleNode("outTangent").InnerText) }; val.AddKey(cloneKey); } return(val); }
public void AddKey(Keyframe3D key) { Keyframe keyframe = new Keyframe(); keyframe.time = key.Time; keyframe.inTangent = key.InTangent.x; keyframe.outTangent = key.OutTangent.x; keyframe.value = key.Value.x; _CurveX.AddKey(keyframe); keyframe.inTangent = key.InTangent.y; keyframe.outTangent = key.OutTangent.y; keyframe.value = key.Value.y; _CurveY.AddKey(keyframe); keyframe.inTangent = key.InTangent.z; keyframe.outTangent = key.OutTangent.z; keyframe.value = key.Value.z; _CurveZ.AddKey(keyframe); }
void DrawFunc() { int cnt = 0; bool firstTime = coughCurve.keys.Length == 0; for (float i = 0; i < 10; i += 0.1f) { float x2 = i; float y2 = CoughFunction(i); Keyframe keyframe = new Keyframe(x2, y2); if (firstTime) { coughCurve.AddKey(keyframe); } else { coughCurve.MoveKey(cnt, keyframe); cnt++; } } }
// Update is called once per frame void Update() { this.GetComponent <Animator>().Play("Run"); if (choice == 0) { if (Time.time % 1 < 0.45f) { this.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, 215, 0), Time.deltaTime); } else { this.transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.Euler(0, -45, 0), Time.deltaTime); } // this.transform.position += new Vector3(-Time.time * 0.008f, 0, anim.Evaluate(Time.time)); } if (Time.time < anim.length) { anim.AddKey(new Keyframe(anim.length + 1, Mathf.Cos(anim.length + 1) * 0.05f)); } }
private void PopulateRimCurve() { rimAngleCurve = new AnimationCurve(); for (int i = 0, j = 0; i < curvePoints.Count && j < curveStepCount; ++i) { for (int k = 0; k < 4; ++k) { if (k >= curveStepCount) { break; } rimAngleCurve.AddKey(new Keyframe(curvePoints[i][k], curveValues[i][k])); ++j; } } for (int i = 0; i < rimAngleCurve.length; ++i) { SetBothTangentsToLinear(i); } }