Here are the examples of the csharp api UnityEngine.AnimationCurve.Evaluate(float) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
66 Examples
19
Source : ColorCorrectionCurves.cs
with Apache License 2.0
from activey
with Apache License 2.0
from activey
public void UpdateParameters ()
{
CheckResources(); // textures might not be created if we're tweaking UI while disabled
if (redChannel != null && greenChannel != null && blueChannel != null)
{
for (float i = 0.0f; i <= 1.0f; i += 1.0f / 255.0f)
{
float rCh = Mathf.Clamp (redChannel.Evaluate(i), 0.0f, 1.0f);
float gCh = Mathf.Clamp (greenChannel.Evaluate(i), 0.0f, 1.0f);
float bCh = Mathf.Clamp (blueChannel.Evaluate(i), 0.0f, 1.0f);
rgbChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 0, new Color(rCh,rCh,rCh) );
rgbChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 1, new Color(gCh,gCh,gCh) );
rgbChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 2, new Color(bCh,bCh,bCh) );
float zC = Mathf.Clamp (zCurve.Evaluate(i), 0.0f,1.0f);
zCurveTex.SetPixel ((int) Mathf.Floor(i*255.0f), 0, new Color(zC,zC,zC) );
rCh = Mathf.Clamp (depthRedChannel.Evaluate(i), 0.0f,1.0f);
gCh = Mathf.Clamp (depthGreenChannel.Evaluate(i), 0.0f,1.0f);
bCh = Mathf.Clamp (depthBlueChannel.Evaluate(i), 0.0f,1.0f);
rgbDepthChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 0, new Color(rCh,rCh,rCh) );
rgbDepthChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 1, new Color(gCh,gCh,gCh) );
rgbDepthChannelTex.SetPixel ((int) Mathf.Floor(i*255.0f), 2, new Color(bCh,bCh,bCh) );
}
rgbChannelTex.Apply ();
rgbDepthChannelTex.Apply ();
zCurveTex.Apply ();
}
}
19
Source : Tonemapping.cs
with Apache License 2.0
from activey
with Apache License 2.0
from activey
public float UpdateCurve()
{
float range = 1.0f;
if (remapCurve.keys.Length < 1)
remapCurve = new AnimationCurve(new Keyframe(0, 0), new Keyframe(2, 1));
if (remapCurve != null)
{
if (remapCurve.length > 0)
range = remapCurve[remapCurve.length - 1].time;
for (float i = 0.0f; i <= 1.0f; i += 1.0f/255.0f)
{
float c = remapCurve.Evaluate(i*1.0f*range);
curveTex.SetPixel((int) Mathf.Floor(i*255.0f), 0, new Color(c, c, c));
}
curveTex.Apply();
}
return 1.0f/range;
}
19
Source : UITweener.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public void Sample(float factor, bool isFinished)
{
float num = Mathf.Clamp01(factor);
if (this.method == UITweener.Method.EaseIn)
{
num = 1f - Mathf.Sin(1.57079637f * (1f - num));
if (this.steeperCurves)
{
num *= num;
}
}
else if (this.method == UITweener.Method.EaseOut)
{
num = Mathf.Sin(1.57079637f * num);
if (this.steeperCurves)
{
num = 1f - num;
num = 1f - num * num;
}
}
else if (this.method == UITweener.Method.EaseInOut)
{
num -= Mathf.Sin(num * 6.28318548f) / 6.28318548f;
if (this.steeperCurves)
{
num = num * 2f - 1f;
float num2 = Mathf.Sign(num);
num = 1f - Mathf.Abs(num);
num = 1f - num * num;
num = num2 * num * 0.5f + 0.5f;
}
}
else if (this.method == UITweener.Method.BounceIn)
{
num = this.BounceLogic(num);
}
else if (this.method == UITweener.Method.BounceOut)
{
num = 1f - this.BounceLogic(1f - num);
}
this.OnUpdate((this.animationCurve == null) ? num : this.animationCurve.Evaluate(num), isFinished);
}
19
Source : AttractionForceAffector.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public override void Update()
{
Vector3 vector;
if (this.Node.SyncClient)
{
vector = this.Position - this.Node.GetLocalPosition();
}
else
{
vector = this.Node.ClientTrans.position + this.Position - this.Node.GetLocalPosition();
}
float elapsedTime = this.Node.GetElapsedTime();
float num;
if (this.UseCurve)
{
num = this.AttractionCurve.Evaluate(elapsedTime);
}
else
{
num = this.Magnitude;
}
float d = num;
this.Node.Velocity += vector.normalized * d * Time.deltaTime;
}
19
Source : RotateAffector.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public override void Update()
{
float elapsedTime = this.Node.GetElapsedTime();
if (this.Type == RSTYPE.CURVE)
{
this.Node.RotateAngle = (float)((int)this.RotateCurve.Evaluate(elapsedTime));
}
else if (this.Type == RSTYPE.SIMPLE)
{
float rotateAngle = this.Node.RotateAngle + this.Delta * Time.deltaTime;
this.Node.RotateAngle = rotateAngle;
}
}
19
Source : ScaleAffector.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public override void Update()
{
float elapsedTime = this.Node.GetElapsedTime();
if (this.Type == RSTYPE.CURVE)
{
if (this.ScaleXCurve != null)
{
this.Node.Scale.x = this.ScaleXCurve.Evaluate(elapsedTime);
}
if (this.ScaleYCurve != null)
{
this.Node.Scale.y = this.ScaleYCurve.Evaluate(elapsedTime);
}
}
else if (this.Type == RSTYPE.SIMPLE)
{
float num = this.Node.Scale.x + this.DeltaX * Time.deltaTime;
float num2 = this.Node.Scale.y + this.DeltaY * Time.deltaTime;
if (num * this.Node.Scale.x > 0f)
{
this.Node.Scale.x = num;
}
if (num2 * this.Node.Scale.y > 0f)
{
this.Node.Scale.y = num2;
}
}
}
19
Source : VortexAffector.cs
with GNU General Public License v3.0
from aelariane
with GNU General Public License v3.0
from aelariane
public override void Update()
{
Vector3 vector = this.Node.GetLocalPosition() - this.Node.Owner.EmitPoint;
float magnitude = vector.magnitude;
if (magnitude == 0f)
{
return;
}
float d = Vector3.Dot(this.Direction, vector);
vector -= d * this.Direction;
Vector3 vector2 = Vectors.zero;
if (vector == Vectors.zero)
{
vector2 = vector;
}
else
{
vector2 = Vector3.Cross(this.Direction, vector).normalized;
}
float elapsedTime = this.Node.GetElapsedTime();
float num;
if (this.UseCurve)
{
num = this.VortexCurve.Evaluate(elapsedTime);
}
else
{
num = this.Magnitude;
}
vector2 *= num * Time.deltaTime;
this.Node.Position += vector2;
}
19
Source : SphericalGravitationalPoint.cs
with MIT License
from ArchonInteractive
with MIT License
from ArchonInteractive
public Vector3 GetForceAt(Vector3 location)
{
var deltaPos = _transform.position - location;
var sqrDist = deltaPos.sqrMagnitude;
if (_isGlobal || sqrDist < _radiusSqr)
{
var strength = _dropoffCurve.Evaluate(sqrDist / _radiusSqr) * _strength;
var force = deltaPos.normalized;
force.x *= strength;
force.y *= strength;
force.z *= strength;
return force;
}
return new Vector3();
}
19
Source : ChangeAtRuntime.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
void FixedUpdate ()
{
nowtime += Time.deltaTime*mult;
if (nowtime >= ChangeTime)
{
mult = -1f;
}
else if(nowtime <= 0f)
{
mult = 1f;
}
float ratio = Curve.Evaluate(nowtime / ChangeTime);
Points[0] = Vector3.Lerp(new Vector3(0f,2f),new Vector3(0f,5f),ratio);
//Step 1: Remove old fixture
fix.Delete();
//Step 2: Add new fixture component
fix = gameObject.AddComponent<LPFixturePoly>();
//Call DefinePoints to set the polys points programmatically
fix.DefinePoints(Points);
//Step 3: Initialise the new fixture (preplaceding in the LPBody)
fix.Initialise(bod);
}
19
Source : FoamWeightDrawer.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public override void UpdateParticles(List<LPParticle> partdata)
{
if (GetComponent<ParticleEmitter>().particleCount < partdata.Count)
{
GetComponent<ParticleEmitter>().Emit(partdata.Count - GetComponent<ParticleEmitter>().particleCount);
particles = GetComponent<ParticleEmitter>().particles;
}
for (int i=0; i < particles.Length; i ++)
{
if (i > partdata.Count - 1)
{
particles[i].energy = 0f;
}
else
{
particles[i].position = partdata[i].Position;
particles[i].color = Color.Lerp(Foam,Liquid,curve.Evaluate( partdata[i].Weight));
}
}
GetComponent<ParticleEmitter>().particles = particles;
}
19
Source : ThreeColorFoamWeightDrawer.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public override void UpdateParticles(List<LPParticle> partdata)
{
if (GetComponent<ParticleEmitter>().particleCount < partdata.Count)
{
GetComponent<ParticleEmitter>().Emit(partdata.Count - GetComponent<ParticleEmitter>().particleCount);
particles = GetComponent<ParticleEmitter>().particles;
}
for (int i=0; i < particles.Length; i ++)
{
if (i > partdata.Count - 1)
{
particles[i].energy = 0f;
}
else
{
particles[i].position = partdata[i].Position;
float val = 1- ( curve.Evaluate(partdata[i].Weight/divisor));
if (val < threshold)
{
particles[i].color = Color.Lerp(Low,Mid,val/threshold) ;
}
else
{
particles[i].color = Color.Lerp(Mid,High,(val-threshold)/(1f-threshold));
}
}
}
GetComponent<ParticleEmitter>().particles = particles;
}
19
Source : WeightAndColorDrawer.cs
with MIT License
from BelkinAndrey
with MIT License
from BelkinAndrey
public override void UpdateParticles(List<LPParticle> partdata)
{
if (GetComponent<ParticleEmitter>().particleCount < partdata.Count)
{
GetComponent<ParticleEmitter>().Emit(partdata.Count - GetComponent<ParticleEmitter>().particleCount);
particles = GetComponent<ParticleEmitter>().particles;
}
for (int i=0; i < particles.Length; i ++)
{
if (i > partdata.Count - 1)
{
particles[i].energy = 0f;
}
else
{
particles[i].position = partdata[i].Position;
float val = 1- ( curve.Evaluate(partdata[i].Weight/divisor));
if (val < threshold)
{
particles[i].color = Color.Lerp(partdata[i]._Color - SubtractColor,partdata[i]._Color ,val/threshold) ;
}
else
{
particles[i].color = Color.Lerp(partdata[i]._Color,partdata[i]._Color + AddColor,(val-threshold)/(1f-threshold));
}
}
}
GetComponent<ParticleEmitter>().particles = particles;
}
19
Source : BoxDrawer.cs
with MIT License
from CameronVetter
with MIT License
from CameronVetter
public Vector3 Evaluate(float time)
{
return new Vector3(CurveX.Evaluate(time), CurveY.Evaluate(time), CurveZ.Evaluate(time));
}
19
Source : LineDrawer.cs
with MIT License
from dag10
with MIT License
from dag10
protected bool Draw_AnimatedBox(AnimatedBox box)
{
// Update the time
if (!box.Update(Time.deltaTime))
{
return false;
}
if (box.IsAnimationComplete)
{
// Animation is done, just preplaced through
return Draw_Box(box.Center, box.Rotation, box.Color, box.HalfSize, box.LineWidth);
}
// Draw it using the current anim state
return Draw_Box(
box.AnimPosition.Evaluate(box.Time),
box.Rotation * Quaternion.AngleAxis(360.0f * box.AnimRotation.Evaluate(box.Time), Vector3.up),
box.Color,
box.HalfSize * box.AnimScale.Evaluate(box.Time),
box.LineWidth);
}
19
Source : DistanceHaptics.cs
with MIT License
from dag10
with MIT License
from dag10
IEnumerator Start()
{
while ( true )
{
float distance = Vector3.Distance( firstTransform.position, secondTransform.position );
SteamVR_TrackedObject trackedObject = GetComponentInParent<SteamVR_TrackedObject>();
if ( trackedObject )
{
float pulse = distanceIntensityCurve.Evaluate( distance );
SteamVR_Controller.Input( (int)trackedObject.index ).TriggerHapticPulse( (ushort)pulse );
}
float nextPulse = pulseIntervalCurve.Evaluate( distance );
yield return new WaitForSeconds( nextPulse );
}
}
19
Source : LinearAudioPitch.cs
with MIT License
from dag10
with MIT License
from dag10
private void Apply()
{
float y = pitchCurve.Evaluate( linearMapping.value );
audioSource.pitch = Mathf.Lerp( minPitch, maxPitch, y );
}
19
Source : Throwable.cs
with MIT License
from dag10
with MIT License
from dag10
private void HandAttachedUpdate( Hand hand )
{
//Trigger got released
if ( !hand.GetStandardInteractionButton() )
{
// Detach ourselves late in the frame.
// This is so that any vehicles the player is attached to
// have a chance to finish updating themselves.
// If we detach now, our position could be behind what it
// will be at the end of the frame, and the object may appear
// to teleport behind the hand when the player releases it.
StartCoroutine( LateDetach( hand ) );
}
if ( attachEaseIn )
{
float t = Util.RemapNumberClamped( Time.time, attachTime, attachTime + snapAttachEaseInTime, 0.0f, 1.0f );
if ( t < 1.0f )
{
t = snapAttachEaseInCurve.Evaluate( t );
transform.position = Vector3.Lerp( attachPosition, attachEaseInTransform.position, t );
transform.rotation = Quaternion.Lerp( attachRotation, attachEaseInTransform.rotation, t );
}
else if ( !snapAttachEaseInCompleted )
{
gameObject.SendMessage( "OnThrowableAttachEaseInCompleted", hand, SendMessageOptions.DontRequireReceiver );
snapAttachEaseInCompleted = true;
}
}
}
19
Source : SoundBowClick.cs
with MIT License
from dag10
with MIT License
from dag10
public void PlayBowTensionClicks( float normalizedTension )
{
// Tension is a float between 0 and 1. 1 being max tension and 0 being no tension
float y = pitchTensionCurve.Evaluate( normalizedTension );
thisAudioSource.pitch = ( ( maxPitch - minPitch ) * y ) + minPitch;
thisAudioSource.PlayOneShot( bowClick );
}
19
Source : CharacterMotor.cs
with MIT License
from deadgg
with MIT License
from deadgg
private Vector3 GetDesiredHorizontalVelocity(Vector3 moveDirection)
{
var desiredLocalDirection = transform.InverseTransformDirection(moveDirection);
var maxSpeed = MaxSpeedInDirection(desiredLocalDirection);
if (state.isGrounded)
{
float movementSlopeAngle = Mathf.Asin(state.velocity.normalized.y) * Mathf.Rad2Deg;
maxSpeed = maxSpeed * movement.slopeSpeedMultiplier.Evaluate(movementSlopeAngle);
}
return transform.TransformDirection(desiredLocalDirection * maxSpeed);
}
19
Source : FOVKick.cs
with MIT License
from Donut-Studios
with MIT License
from Donut-Studios
public IEnumerator FOVKickUp()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t < TimeToIncrease)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToIncrease)*FOVIncrease);
t += Time.deltaTime;
yield return new WaitForEndOfFrame();
}
}
19
Source : FOVKick.cs
with MIT License
from Donut-Studios
with MIT License
from Donut-Studios
public IEnumerator FOVKickDown()
{
float t = Mathf.Abs((Camera.fieldOfView - originalFov)/FOVIncrease);
while (t > 0)
{
Camera.fieldOfView = originalFov + (IncreaseCurve.Evaluate(t/TimeToDecrease)*FOVIncrease);
t -= Time.deltaTime;
yield return new WaitForEndOfFrame();
}
//make sure that fov returns to the original size
Camera.fieldOfView = originalFov;
}
19
Source : CurveControlledBob.cs
with MIT License
from Donut-Studios
with MIT License
from Donut-Studios
public Vector3 DoHeadBob(float speed)
{
float xPos = m_OriginalCameraPosition.x + (Bobcurve.Evaluate(m_CyclePositionX)*HorizontalBobRange);
float yPos = m_OriginalCameraPosition.y + (Bobcurve.Evaluate(m_CyclePositionY)*VerticalBobRange);
m_CyclePositionX += (speed*Time.deltaTime)/m_BobBaseInterval;
m_CyclePositionY += ((speed*Time.deltaTime)/m_BobBaseInterval)*VerticaltoHorizontalRatio;
if (m_CyclePositionX > m_Time)
{
m_CyclePositionX = m_CyclePositionX - m_Time;
}
if (m_CyclePositionY > m_Time)
{
m_CyclePositionY = m_CyclePositionY - m_Time;
}
return new Vector3(xPos, yPos, 0f);
}
19
Source : RigidbodyFirstPersonController.cs
with MIT License
from Donut-Studios
with MIT License
from Donut-Studios
private float SlopeMultiplier()
{
float angle = Vector3.Angle(m_GroundContactNormal, Vector3.up);
return movementSettings.SlopeCurveModifier.Evaluate(angle);
}
19
Source : PickableSpawnerExample.cs
with GNU General Public License v3.0
from grygus
with GNU General Public License v3.0
from grygus
void Update()
{
if (_ratioTimer < _ratioMaxTime)
_ratioTimer += Time.deltaTime;
else
_ratioTimer = 0;
var spawnCount = (int)(_spawnRatio.Evaluate(_ratioTimer / _ratioMaxTime)*_maxSpawned);
if (spawnCount >= 0)
{
while (spawnCount > _activeGameObjects.Count)
{
Spawn();
}
while(spawnCount < _activeGameObjects.Count)
{
Cache<GameObject>.Caches[_prefab.name].Push(_activeGameObjects[0]);
_activeGameObjects.RemoveAt(0);
}
}
}
19
Source : SLayoutAnimation.cs
with MIT License
from inkle
with MIT License
from inkle
public void Update()
{
// Use unscaledDeltaTime so that we don't get affected by slow motion effects
// etc, but on the other hand, don't allow it to be a large delta - unscaledDeltaTime
// can get the absolutely true/real time between frames, which when the game gets
// stalled/paused for some reason can give us unexpected results.
float dt = Mathf.Min(Time.unscaledDeltaTime, 1.0f/15.0f);
_time += dt;
if( isComplete )
return;
if( _properties != null ) {
foreach(var property in _properties) {
float lerpValue = 0.0f;
if( _time > property.delay ) {
lerpValue = Mathf.Clamp01((_time-property.delay) / property.duration);
// TODO: Allow different curves?
if( _customCurve != null ) {
lerpValue = _customCurve.Evaluate(lerpValue);
} else {
lerpValue = Mathf.SmoothStep(0.0f, 1.0f, lerpValue);
}
property.Animate(lerpValue);
}
}
}
if( timeIsUp )
Done();
}
19
Source : MalbersTools.cs
with MIT License
from Interactml
with MIT License
from Interactml
public static IEnumerator AlignTransform_Position(Transform t1, Vector3 NewPosition, float time, AnimationCurve curve = null)
{
float elapsedTime = 0;
Vector3 CurrentPos = t1.position;
while ((time > 0) && (elapsedTime <= time))
{
float result = curve != null ? curve.Evaluate(elapsedTime / time) : elapsedTime / time; //Evaluation of the Pos curve
t1.position = Vector3.LerpUnclamped(CurrentPos, NewPosition, result);
elapsedTime += Time.deltaTime;
yield return null;
}
t1.position = NewPosition;
}
19
Source : MalbersTools.cs
with MIT License
from Interactml
with MIT License
from Interactml
public static IEnumerator AlignTransform_Rotation(Transform t1, Quaternion NewRotation, float time, AnimationCurve curve = null)
{
float elapsedTime = 0;
Quaternion CurrentRot = t1.rotation;
while ((time > 0) && (elapsedTime <= time))
{
float result = curve != null ? curve.Evaluate(elapsedTime / time) : elapsedTime / time; //Evaluation of the Pos curve
t1.rotation = Quaternion.LerpUnclamped(CurrentRot, NewRotation, result);
elapsedTime += Time.deltaTime;
yield return null;
}
t1.rotation = NewRotation;
}
19
Source : MalbersTools.cs
with MIT License
from Interactml
with MIT License
from Interactml
public static IEnumerator AlignTransformsC(Transform t1, Quaternion rotation, float time, AnimationCurve curve = null)
{
float elapsedTime = 0;
Quaternion CurrentRot = t1.rotation;
while ((time > 0) && (elapsedTime <= time))
{
float result = curve != null ? curve.Evaluate(elapsedTime / time) : elapsedTime / time; //Evaluation of the Pos curve
t1.rotation = Quaternion.SlerpUnclamped(CurrentRot, rotation, result);
elapsedTime += Time.deltaTime;
yield return null;
}
t1.rotation = rotation;
}
19
Source : MalbersTools.cs
with MIT License
from Interactml
with MIT License
from Interactml
public static IEnumerator AlignLookAtTransform(Transform t1, Transform t2, float time, AnimationCurve curve = null)
{
float elapsedTime = 0;
Quaternion CurrentRot = t1.rotation;
Vector3 direction = (t2.position - t1.position).normalized;
direction.y = t1.forward.y;
Quaternion FinalRot = Quaternion.LookRotation(direction);
while ((time > 0) && (elapsedTime <= time))
{
float result = curve != null ? curve.Evaluate(elapsedTime / time) : elapsedTime / time; //Evaluation of the Pos curve
t1.rotation = Quaternion.SlerpUnclamped(CurrentRot, FinalRot, result);
elapsedTime += Time.deltaTime;
yield return null;
}
t1.rotation = FinalRot;
}
19
Source : MalbersTools.cs
with MIT License
from Interactml
with MIT License
from Interactml
public static IEnumerator AlignTransformsC(Transform t1, Transform t2, float time, bool Position = true, bool Rotation = true, AnimationCurve curve = null)
{
float elapsedTime = 0;
Vector3 CurrentPos = t1.position;
Quaternion CurrentRot = t1.rotation;
while ((time > 0) && (elapsedTime <= time))
{
float result = curve != null ? curve.Evaluate(elapsedTime / time) : elapsedTime / time; //Evaluation of the Pos curve
if (Position) t1.position = Vector3.LerpUnclamped(CurrentPos, t2.position, result);
if (Rotation) t1.rotation = Quaternion.SlerpUnclamped(CurrentRot, t2.rotation, result);
elapsedTime += Time.deltaTime;
yield return null;
}
if (Position) t1.position = t2.position;
if (Rotation) t1.rotation = t2.rotation;
}
19
Source : BlendShapesSequencer.cs
with MIT License
from IxxyXR
with MIT License
from IxxyXR
void Update()
{
var curve = AnimationCurve.EaseInOut(0, 0, 1, 1);
float elapsedTime = (Time.time - startTime) % duration;
float completion = elapsedTime / duration;
int cycle = Mathf.FloorToInt((Time.time - startTime) / duration);
if (cycle % 2 == 1)
{
completion = 1 - completion;
}
float morphDuration = 1f / Morphs.Count;
float transitionDuration = morphDuration * transitionRatio;
if (!initialized) Rebuild();
for (var i = 0; i < Morphs.Count; i++)
{
float morphStart = i * morphDuration;
float morphEnd = ((i+1) * morphDuration) + transitionDuration;
float introCompletion = curve.Evaluate(Mathf.Clamp01(Mathf.InverseLerp(morphStart, morphStart + transitionDuration, completion)));
float outroCompletion = 1 - curve.Evaluate(Mathf.Clamp01(Mathf.InverseLerp(morphEnd - transitionDuration, morphEnd, completion)));
float val = Mathf.Min(introCompletion, outroCompletion);
var blendFrame = i + 1; // The first frame is the same as the base mesh
polymorphSkinnedMeshRenderer.SetBlendShapeWeight(blendFrame, Mathf.Lerp(0, 100, val));
}
}
19
Source : CurveEditor.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
float EvaluateTangent(AnimationCurve curve, float time)
{
int prev = -1, next = 0;
for (int i = 0; i < curve.keys.Length; i++)
{
if (time > curve.keys[i].time)
{
prev = i;
next = i + 1;
}
else break;
}
if (next == 0)
return 0f;
if (prev == curve.keys.Length - 1)
return 0f;
const float kD = 1e-3f;
float tp = Mathf.Max(time - kD, curve.keys[prev].time);
float tn = Mathf.Min(time + kD, curve.keys[next].time);
float vp = curve.Evaluate(tp);
float vn = curve.Evaluate(tn);
if (Mathf.Approximately(tn, tp))
return (vn - vp > 0f) ? float.PositiveInfinity : float.NegativeInfinity;
return (vn - vp) / (tn - tp);
}
19
Source : CurveEditor.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
void EditCreateKeyframe(AnimationCurve curve, Vector3 position, bool createOnCurve, float zeroKeyConstantValue)
{
float tangent = EvaluateTangent(curve, position.x);
if (createOnCurve)
{
position.y = curve.length == 0
? zeroKeyConstantValue
: curve.Evaluate(position.x);
}
AddKeyframe(curve, new Keyframe(position.x, position.y, tangent, tangent));
}
19
Source : ColorGradingCurve.cs
with MIT License
from liangxiegame
with MIT License
from liangxiegame
public float Evaluate(float t)
{
if (curve.length == 0)
return m_ZeroValue;
if (!m_Loop || curve.length == 1)
return curve.Evaluate(t);
return m_InternalLoopingCurve.Evaluate(t);
}
19
Source : UIFontInspector.cs
with MIT License
from mamoniem
with MIT License
from mamoniem
void ApplyEffect (Effect effect, Color foreground, Color background)
{
BMFont bf = mFont.bmFont;
int offsetX = 0;
int offsetY = 0;
if (mFont.atlas != null)
{
UISpriteData sd = mFont.atlas.GetSprite(bf.spriteName);
if (sd == null) return;
offsetX = sd.x;
offsetY = sd.y + mFont.texHeight - sd.paddingTop;
}
string path = replacedetDatabase.GetreplacedetPath(mFont.texture);
Texture2D bfTex = NGUIEditorTools.ImportTexture(path, true, true, false);
Color32[] atlas = bfTex.GetPixels32();
// First we need to extract textures for all the glyphs, making them bigger in the process
List<BMGlyph> glyphs = bf.glyphs;
List<Texture2D> glyphTextures = new List<Texture2D>(glyphs.Count);
for (int i = 0, imax = glyphs.Count; i < imax; ++i)
{
BMGlyph glyph = glyphs[i];
if (glyph.width < 1 || glyph.height < 1) continue;
int width = glyph.width;
int height = glyph.height;
if (effect == Effect.Outline || effect == Effect.Shadow || effect == Effect.Border)
{
width += 2;
height += 2;
--glyph.offsetX;
--glyph.offsetY;
}
else if (effect == Effect.Crop && width > 2 && height > 2)
{
width -= 2;
height -= 2;
++glyph.offsetX;
++glyph.offsetY;
}
int size = width * height;
Color32[] colors = new Color32[size];
Color32 clear = background;
clear.a = 0;
for (int b = 0; b < size; ++b) colors[b] = clear;
if (effect == Effect.Crop)
{
for (int y = 0; y < height; ++y)
{
for (int x = 0; x < width; ++x)
{
int fx = x + glyph.x + offsetX + 1;
int fy = y + (mFont.texHeight - glyph.y - glyph.height) + 1;
if (mFont.atlas != null) fy += bfTex.height - offsetY;
colors[x + y * width] = atlas[fx + fy * bfTex.width];
}
}
}
else
{
for (int y = 0; y < glyph.height; ++y)
{
for (int x = 0; x < glyph.width; ++x)
{
int fx = x + glyph.x + offsetX;
int fy = y + (mFont.texHeight - glyph.y - glyph.height);
if (mFont.atlas != null) fy += bfTex.height - offsetY;
Color c = atlas[fx + fy * bfTex.width];
if (effect == Effect.Border)
{
colors[x + 1 + (y + 1) * width] = c;
}
else
{
if (effect == Effect.AlphaCurve) c.a = Mathf.Clamp01(mCurve.Evaluate(c.a));
Color bg = background;
bg.a = (effect == Effect.BackgroundCurve) ? Mathf.Clamp01(mCurve.Evaluate(c.a)) : c.a;
Color fg = foreground;
fg.a = (effect == Effect.ForegroundCurve) ? Mathf.Clamp01(mCurve.Evaluate(c.a)) : c.a;
if (effect == Effect.Outline || effect == Effect.Shadow)
{
colors[x + 1 + (y + 1) * width] = Color.Lerp(bg, c, c.a);
}
else
{
colors[x + y * width] = Color.Lerp(bg, fg, c.a);
}
}
}
}
// Apply the appropriate affect
if (effect == Effect.Shadow) NGUIEditorTools.AddShadow(colors, width, height, NGUISettings.backgroundColor);
else if (effect == Effect.Outline) NGUIEditorTools.AddDepth(colors, width, height, NGUISettings.backgroundColor);
}
Texture2D tex = new Texture2D(width, height, TextureFormat.ARGB32, false);
tex.SetPixels32(colors);
tex.Apply();
glyphTextures.Add(tex);
}
// Pack all glyphs into a new texture
Texture2D final = new Texture2D(bfTex.width, bfTex.height, TextureFormat.ARGB32, false);
Rect[] rects = final.PackTextures(glyphTextures.ToArray(), 1);
final.Apply();
// Make RGB channel use the background color (Unity makes it black by default)
Color32[] fcs = final.GetPixels32();
Color32 bc = background;
for (int i = 0, imax = fcs.Length; i < imax; ++i)
{
if (fcs[i].a == 0)
{
fcs[i].r = bc.r;
fcs[i].g = bc.g;
fcs[i].b = bc.b;
}
}
final.SetPixels32(fcs);
final.Apply();
// Update the glyph rectangles
int index = 0;
int tw = final.width;
int th = final.height;
for (int i = 0, imax = glyphs.Count; i < imax; ++i)
{
BMGlyph glyph = glyphs[i];
if (glyph.width < 1 || glyph.height < 1) continue;
Rect rect = rects[index++];
glyph.x = Mathf.RoundToInt(rect.x * tw);
glyph.y = Mathf.RoundToInt(rect.y * th);
glyph.width = Mathf.RoundToInt(rect.width * tw);
glyph.height = Mathf.RoundToInt(rect.height * th);
glyph.y = th - glyph.y - glyph.height;
}
// Update the font's texture dimensions
mFont.texWidth = final.width;
mFont.texHeight = final.height;
if (mFont.atlas == null)
{
// Save the final texture
byte[] bytes = final.EncodeToPNG();
NGUITools.DestroyImmediate(final);
System.IO.File.WriteAllBytes(path, bytes);
replacedetDatabase.Refresh(ImportreplacedetOptions.ForceSynchronousImport);
}
else
{
// Update the atlas
final.name = mFont.spriteName;
bool val = NGUISettings.atlasTrimming;
NGUISettings.atlasTrimming = false;
UIAtlasMaker.AddOrUpdate(mFont.atlas, final);
NGUISettings.atlasTrimming = val;
NGUITools.DestroyImmediate(final);
}
// Cleanup
for (int i = 0; i < glyphTextures.Count; ++i)
NGUITools.DestroyImmediate(glyphTextures[i]);
// Refresh all labels
mFont.MarkAsChanged();
}
19
Source : UITweener.cs
with MIT License
from mamoniem
with MIT License
from mamoniem
public void Sample (float factor, bool isFinished)
{
// Calculate the sampling value
float val = Mathf.Clamp01(factor);
if (method == Method.EaseIn)
{
val = 1f - Mathf.Sin(0.5f * Mathf.PI * (1f - val));
if (steeperCurves) val *= val;
}
else if (method == Method.EaseOut)
{
val = Mathf.Sin(0.5f * Mathf.PI * val);
if (steeperCurves)
{
val = 1f - val;
val = 1f - val * val;
}
}
else if (method == Method.EaseInOut)
{
const float pi2 = Mathf.PI * 2f;
val = val - Mathf.Sin(val * pi2) / pi2;
if (steeperCurves)
{
val = val * 2f - 1f;
float sign = Mathf.Sign(val);
val = 1f - Mathf.Abs(val);
val = 1f - val * val;
val = sign * val * 0.5f + 0.5f;
}
}
else if (method == Method.BounceIn)
{
val = BounceLogic(val);
}
else if (method == Method.BounceOut)
{
val = 1f - BounceLogic(1f - val);
}
// Call the virtual update
OnUpdate((animationCurve != null) ? animationCurve.Evaluate(val) : val, isFinished);
}
19
Source : HermiteCurve.cs
with Apache License 2.0
from mogoson
with Apache License 2.0
from mogoson
public Vector3 GetPointAt(float key)
{
return new Vector3(xCurve.Evaluate(key), yCurve.Evaluate(key), zCurve.Evaluate(key));
}
19
Source : FlowerBloom.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
void Update() {
if (open)
phase_ += Time.deltaTime / openTime;
else
phase_ -= Time.deltaTime / closeTime;
phase_ = Mathf.Clamp(phase_, 0.0f, 1.0f);
float percent_done = openCurve.Evaluate(phase_);
float angle = closeAngle + percent_done * (openAngle - closeAngle);
foreach (HingeJoint hinge in pedals) {
JointSpring spring = hinge.spring;
spring.targetPosition = angle;
hinge.spring = spring;
}
}
19
Source : PetalMesh.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
private void UpdateMesh() {
for (int v = 0; v < numVertices / 2; ++v) {
float phase = (2.0f * v) / (numVertices - 2);
float flower_width = flowerCurve.Evaluate(phase);
float width = flower_width + morph * (morphCurve.Evaluate(phase) - flower_width);
float growth_delay = growthDelayCurve.Evaluate(phase);
float growth_amount = (growthProgress - growth_delay) / (1.0f - growth_delay);
width *= Mathf.Clamp(growth_amount, 0.0f, 1.0f);
Vector3 vertex1 = new Vector3(2.0f * phase - 1, 0, -width);
Vector3 vertex1_a = firstSegment.transform.TransformPoint(vertex1);
Vector3 vertex1_b = lastSegment.transform.TransformPoint(vertex1);
Vector3 vertex1_t = vertex1_a + phase * (vertex1_b - vertex1_a);
Vector3 vertex2 = new Vector3(2.0f * phase - 1, 0, width);
Vector3 vertex2_a = firstSegment.transform.TransformPoint(vertex2);
Vector3 vertex2_b = lastSegment.transform.TransformPoint(vertex2);
Vector3 vertex2_t = vertex2_a + phase * (vertex2_b - vertex2_a);
vertices_[2 * v] = transform.InverseTransformPoint(vertex1_t);
vertices_[2 * v + 1] = transform.InverseTransformPoint(vertex2_t);
}
}
19
Source : StemMesh.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
private void UpdateMesh() {
if (is_diminishing_ && stump_width_ != 0.0f) {
stump_width_ -= Time.deltaTime / stumpDiminishTime;
stump_width_ = Mathf.Clamp(stump_width_, 0.0f, 1.0f);
if (stump_width_ == 0.0f)
KillStump();
}
for (int i = 0; i < segments.Length; ++i) {
if (!broken[i] && segments[i].GetComponent<HingeJoint>() == null) {
InitMesh();
broken[i] = true;
}
}
int vertex_index = 0;
float angle = 360.0f / sides;
bool is_stump = true;
for (int i = 0; i < segments.Length; ++i) {
float phase = (1.0f * i) / (segments.Length - 1);
float width = Mathf.Clamp(segments.Length * growthProgress - i, 0.0f, 1.0f);
is_stump = is_stump && !broken[i];
if (is_stump)
width *= stump_width_;
Vector3 offset = new Vector3(width * stemCurve.Evaluate(phase), 0, 0);
for (int side = 0; side < sides; ++side) {
vertices_[vertex_index++] =
transform.InverseTransformPoint(segments[i].transform.TransformPoint(offset));
offset = Quaternion.AngleAxis(angle, Vector3.up) * offset;
}
}
}
19
Source : HandFader.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
void Update () {
_smoothedConfidence += (_handModel.GetLeapHand().Confidence - _smoothedConfidence) / confidenceSmoothing;
float fade = confidenceCurve.Evaluate(_smoothedConfidence);
_renderer.enabled = fade != 0.0f;
_renderer.material.SetFloat("_Fade", confidenceCurve.Evaluate(_smoothedConfidence));
}
19
Source : FadeTextByRotation.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
void Update () {
// Make sure there is a reference transform to reference.
if (ReferenceTransform_AutoDiscovered == null) {
bool registered = registerReferenceTransform();
if (!registered) {
Debug.LogError("No reference transform. Exiting.");
return;
}
}
// Make sure there are text labels to operate on.
if (m_textLabels.Length == 0) {
return;
}
float referenceDotDirection = Vector3.Dot(ReferenceTransform_AutoDiscovered.forward, transform.forward);
referenceDotDirection = Mathf.Clamp01(referenceDotDirection);
// We say opacity mod because the actual opacity will be
// the original opacity * the opacity mod.
// The original opacity is replacedumed to be the max opacity.
float opacityMod = FadeCurve.Evaluate(referenceDotDirection);
float goalOpacity = m_originalLabelOpacity * opacityMod;
// ForEach over an array is memory-optimized in Unity so we can use it.
// Usually want to avoid this because of spurious allocs due to the enumerator.
foreach(Text textComponent in m_textLabels) {
Color textColor = textComponent.color;
textColor.a = goalOpacity;
textComponent.color = textColor;
}
}
19
Source : DisconnectionNotice.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
void Update() {
if (embeddedReplacementImage != null && IsEmbedded()) {
GetComponent<GUITexture>().texture = embeddedReplacementImage;
}
if (IsConnected())
frames_disconnected_ = 0;
else
frames_disconnected_++;
if (frames_disconnected_ < waitFrames)
fadedIn -= Time.deltaTime / fadeOutTime;
else
fadedIn += Time.deltaTime / fadeInTime;
fadedIn = Mathf.Clamp(fadedIn, 0.0f, 1.0f);
SetAlpha(fade.Evaluate(fadedIn));
}
19
Source : GrabbingHand.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
protected void ContinueSoftPinch() {
Quaternion target_rotation = palm_rotation_ * rotation_from_palm_;
Vector3 target_position = filtered_pinch_position_ + target_rotation * object_pinch_offset_;
Vector3 delta_position = target_position - active_object_.transform.position;
float strength = (releaseBreakDistance - delta_position.magnitude) / releaseBreakDistance;
strength = releaseStrengthCurve.Evaluate(strength);
active_object_.GetComponent<Rigidbody>().AddForce(delta_position.normalized * strength * positionFiltering,
ForceMode.Acceleration);
Quaternion delta_rotation = target_rotation *
Quaternion.Inverse(active_object_.transform.rotation);
float angle = 0.0f;
Vector3 axis = Vector3.zero;
delta_rotation.ToAngleAxis(out angle, out axis);
active_object_.GetComponent<Rigidbody>().AddTorque(strength * rotationFiltering * angle * axis,
ForceMode.Acceleration);
}
19
Source : EnhancelScrollView.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
private float GetScaleValue(float sliderValue, float added)
{
float scaleValue = scaleCurve.Evaluate(positionCenterTime + sliderValue + added);
return scaleValue;
}
19
Source : EnhancelScrollView.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
private float GetXPosValue(float sliderValue, float added)
{
float evaluateValue = startXPos + positionCurve.Evaluate(positionCenterTime + sliderValue + added) * width;
return evaluateValue;
}
19
Source : UITween.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
public void MoveAnimation(RectTransform _rectTransform, float _counterTween)
{
float evaluatedValue = currentAnimationCurvePos.Evaluate(_counterTween);
Vector3 valueAdded = (currentEndPos - currentStartPos) * evaluatedValue;
_rectTransform.ancreplaceddPosition = (Vector2)(currentStartPos + valueAdded);
}
19
Source : UITween.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
public void ScaleAnimation(RectTransform _rectTransform, float _counterTween)
{
float evaluatedValue = currentAnimationCurveScale.Evaluate(_counterTween);
Vector3 valueAdded = (currentEndScale - currentStartScale) * evaluatedValue;
_rectTransform.localScale = currentStartScale + valueAdded;
}
19
Source : UITween.cs
with Apache License 2.0
from OOXXXXOO
with Apache License 2.0
from OOXXXXOO
public void RotateAnimation(RectTransform _rectTransform, float _counterTween)
{
float evaluatedValue = currentAnimationCurveRot.Evaluate(_counterTween);
Vector3 valueAdded = (currentEndRot - currentStartRot) * evaluatedValue;
_rectTransform.localEulerAngles = currentStartRot + valueAdded;
}
19
Source : InterpolatedValue.cs
with MIT License
from pampas93
with MIT License
from pampas93
public T FrameUpdate()
{
if (IsRunning)
{
if (skipFirstUpdateFrame && !firstUpdateFrameSkipped)
{
firstUpdateFrameSkipped = true;
timeInterpolationStartedAt = CurrentTime;
return Value;
}
float timeDelta = CurrentTime - timeInterpolationStartedAt;
// Normalize the delta to curve duration
timeDelta *= Curve.Duration() / Duration;
Value = ApplyCurveValue(startValue, targetValue, Curve.Evaluate(timeDelta));
if (timeDelta >= Curve.Duration())
{
EnsureDisabled();
}
}
return Value;
}
See More Examples