/// <summary> /// Oscillates around a value. This will animation from /// startValue > startValue + amount > startValue - amount- > startValue, /// in a smooth circular motion. /// </summary> /// <param name="amount"> /// The maximum amount to oscillate away from the default value. /// </param> public static CommandDelegate Oscillate(Ref<float> single, float amount, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); float baseValue = 0f; return Commands.Sequence( Commands.Do( () => baseValue = single.Value), Commands.Duration( t => { single.Value = baseValue + Mathf.Sin((float) t * 2f * Mathf.PI) * amount; }, duration, ease) ); }
public static CommandDelegate AlphaFrom(Ref<Color32> color, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(color, "color"); Ref<double> alphaRef = new Ref<double>( () => color.Value.a / 255.0, (t) => { Color32 tempColor = color.Value; tempColor.a = (byte) (t * 255); color.Value = tempColor; } ); return ChangeFrom(alphaRef, startAlpha, duration, ease); }
public static CommandDelegate AlphaTo(Ref<Color> color, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(color, "color"); Ref<float> alphaRef = new Ref<float>( () => color.Value.a, (t) => { Color tempColor = color.Value; tempColor.a = t; color.Value = tempColor; } ); return ChangeTo(alphaRef, endAlpha, duration, ease); }
public static CommandDelegate AlphaBy(GUITexture texture, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(texture, "texture"); return(ChangeBy(texture.ToAlphaRef(), offset, duration, ease)); }
public static CommandDelegate RotateTo(GameObject gameObject, Quaternion endRotation, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(gameObject, "gameObject"); return RotateTo(gameObject.transform, endRotation, duration, ease, isLocalSpace); }
public static CommandDelegate AlphaFrom(Renderer renderer, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return AlphaFrom(renderer.material, startAlpha, duration, ease); }
public static CommandDelegate AlphaTo(GameObject gameObject, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(gameObject, "gameObject"); return AlphaTo(gameObject.GetComponent<Renderer>().material, endAlpha, duration, ease); }
public static CommandDelegate TintBy(GUITexture texture, Color offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(texture, "texture"); return TintBy(texture.ToColorRef(), offset, duration, ease); }
public static CommandDelegate TintTo(Material material, Color endColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(material, "material"); return TintTo(material.ToColorRef(), endColour, duration, ease); }
public static CommandDelegate AlphaFromOffset(GUIText text, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(text, "text"); return(ChangeFromOffset(text.ToAlphaRef(), offset, duration, ease)); }
public static CommandDelegate ScaleTo(Transform transform, float endScale, double duration, CommandEase ease = null) { CheckArgumentNonNull(transform, "transform"); return ScaleTo(transform, Vector3.one * endScale, duration, ease); }
public static CommandDelegate AlphaFromOffset(Material material, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(material, "material"); return(ChangeFromOffset(material.ToAlphaRef(), offset, duration, ease)); }
public static CommandDelegate AlphaFromOffset(SpriteRenderer renderer, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return(ChangeFromOffset(renderer.ToAlphaRef(), offset, duration, ease)); }
public static CommandDelegate AlphaFromOffset(Renderer renderer, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return(AlphaFromOffset(renderer.material, offset, duration, ease)); }
public static CommandDelegate AlphaFromOffset(GameObject gameObject, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(gameObject, "gameObject"); return(AlphaFromOffset(gameObject.GetComponent <Renderer>().material, offset, duration, ease)); }
public static CommandDelegate AlphaFrom(GUITexture texture, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(texture, "texture"); return(ChangeFrom(texture.ToAlphaRef(), startAlpha, duration, ease)); }
public static CommandDelegate AlphaBy(Material material, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(material, "material"); return ChangeBy(material.ToAlphaRef(), offset, duration, ease); }
public static CommandDelegate MoveFromOffset(GameObject gameObject, Vector3 offset, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(gameObject, "gameObject"); return(MoveFromOffset(gameObject.transform, offset, duration, ease, isLocalSpace)); }
public static CommandDelegate ScaleFrom(GameObject gameObject, float startScale, double duration, CommandEase ease = null) { CheckArgumentNonNull(gameObject, "gameObject"); return ScaleFrom(gameObject.transform, startScale, duration, ease); }
public static CommandDelegate MoveFromOffset(Transform transform, Vector3 offset, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(transform, "transform"); return(ChangeFromOffset(transform.ToPositionRef(isLocalSpace), offset, duration, ease)); }
public static CommandDelegate AlphaBy(SpriteRenderer renderer, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return ChangeBy(renderer.ToAlphaRef(), offset, duration, ease); }
public static CommandDelegate RotateTo(GameObject gameObject, Quaternion endRotation, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(gameObject, "gameObject"); return(RotateTo(gameObject.transform, endRotation, duration, ease, isLocalSpace)); }
public static CommandDelegate TintFrom(GUITexture texture, Color startColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(texture, "texture"); return TintFrom(texture.ToColorRef(), startColour, duration, ease); }
public static CommandDelegate RotateTo(Transform transform, Quaternion endRotation, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(transform, "transform"); return(RotateTo(transform.ToRotationRef(isLocalSpace), endRotation, duration, ease)); }
public static CommandDelegate TintTo(GUIText text, Color endColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(text, "text"); return TintTo(text.ToColorRef(), endColour, duration, ease); }
public static CommandDelegate AlphaTo(Material material, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(material, "material"); return(ChangeTo(material.ToAlphaRef(), endAlpha, duration, ease)); }
public static CommandDelegate AlphaFrom(SpriteRenderer renderer, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return ChangeFrom(renderer.ToAlphaRef(), startAlpha, duration, ease); }
public static CommandDelegate AlphaTo(SpriteRenderer renderer, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return(ChangeTo(renderer.ToAlphaRef(), endAlpha, duration, ease)); }
public static CommandEase OutEase(CommandEase inEase) { return t => 1.0 - inEase(1.0 - t); }
public static CommandDelegate AlphaTo(GUIText text, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(text, "text"); return(ChangeTo(text.ToAlphaRef(), endAlpha, duration, ease)); }
public static CommandDelegate ChangeFromOffset(Ref <Vector4> vector, Vector4 offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(vector, "vector"); return(Commands.Defer(() => Commands.ChangeFrom(vector, vector.Value + offset, duration, ease))); }
public static CommandDelegate ChangeBy(Ref <double> single, double offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); double lastT = 0.0; return(Commands.Sequence( Commands.Do(delegate() { lastT = 0.0; }), Commands.Duration(delegate(double t) { single.Value += offset * (t - lastT); lastT = t; }, duration, ease) )); }
public static CommandDelegate MoveTo(Transform transform, Vector3 endPosition, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(transform, "transform"); return ChangeTo(transform.ToPositionRef(isLocalSpace), endPosition, duration, ease); }
public static CommandDelegate ChangeBy(Ref <short> single, short offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); var reference = ToDoubleRef(single); return(Commands.Sequence( Commands.Do(() => reference.Value = (double)single.Value), Commands.ChangeBy(reference, (double)offset, duration, ease) )); }
public static CommandDelegate RotateTo(Transform transform, Quaternion endRotation, double duration, CommandEase ease = null, bool isLocalSpace = false) { CheckArgumentNonNull(transform, "transform"); return RotateTo(transform.ToRotationRef(isLocalSpace), endRotation, duration, ease); }
public static CommandDelegate ChangeFrom(Ref <double> single, double startSingle, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); double endSingle = 0.0; return(Commands.Sequence( Commands.Do(delegate() { endSingle = single.Value; }), Commands.Duration(delegate(double t) { single.Value = (endSingle - startSingle) * t + startSingle; }, duration, ease) )); }
public static CommandDelegate ScaleBy(Transform transform, Vector3 scaleFactor, double duration, CommandEase ease = null) { CheckArgumentNonNull(transform, "transform"); return ScaleBy(transform.ToScaleRef(), scaleFactor, duration, ease); }
public static CommandDelegate ScaleBy(Ref <float> scale, float scaleFactor, double duration, CommandEase ease = null) { CheckArgumentNonNull(scale, "scale"); float lastScaleFactor = 1.0f; return(Commands.Sequence( Commands.Do(delegate(){ lastScaleFactor = 1.0f; }), Commands.Duration(delegate(double t) { float newScaleFactor = (float)t * (scaleFactor - 1.0f) + 1.0f; scale.Value = scale.Value * newScaleFactor / lastScaleFactor; lastScaleFactor = newScaleFactor; }, duration, ease) )); }
public static CommandDelegate ScaleTo(GameObject gameObject, Vector3 endScale, double duration, CommandEase ease = null) { CheckArgumentNonNull(gameObject, "gameObject"); return ScaleTo(gameObject.transform, endScale, duration, ease); }
public static CommandDelegate ScaleBy(Ref <double> scale, double scaleFactor, double duration, CommandEase ease = null) { CheckArgumentNonNull(scale, "scale"); double lastScaleFactor = 1.0; return(Commands.Sequence( Commands.Do(delegate(){ lastScaleFactor = 1.0; }), Commands.Duration(delegate(double t) { double newScaleFactor = t * (scaleFactor - 1.0) + 1.0; scale.Value = scale.Value * newScaleFactor / lastScaleFactor; lastScaleFactor = newScaleFactor; }, duration, ease) )); }
public static CommandDelegate ScaleTo(Transform transform, Vector3 endScale, double duration, CommandEase ease = null) { CheckArgumentNonNull(transform, "transform"); return ChangeTo(transform.ToScaleRef(), endScale, duration, ease); }
public static CommandDelegate ChangeTo(Ref <float> single, float endSingle, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); float startSingle = 0.0f; return(Commands.Sequence( Commands.Do(delegate() { startSingle = single.Value; }), Commands.Duration(delegate(double t) { single.Value = (endSingle - startSingle) * (float)t + startSingle; }, duration, ease) )); }
public static CommandDelegate TintBy(Renderer renderer, Color offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return TintBy(renderer.material, offset, duration, ease); }
public static CommandDelegate ChangeTo(Ref <long> single, long endValue, double duration, CommandEase ease = null) { CheckArgumentNonNull(single, "single"); var reference = ToDoubleRef(single); return(Commands.Sequence( Commands.Do(() => reference.Value = (double)single.Value), Commands.ChangeTo(reference, (double)endValue, duration, ease) )); }
public static CommandDelegate TintFrom(Renderer renderer, Color startColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return TintFrom(renderer.material, startColour, duration, ease); }
public static CommandDelegate ChangeTo <T>(IInterpolatable <T> interpolatable, T endValue, double duration, CommandEase ease = null) { CheckArgumentNonNull(interpolatable, "interpolatable"); T startValue = interpolatable.GetValue(); return(Commands.Sequence( Commands.Do(delegate() { startValue = interpolatable.GetValue(); }), Commands.Duration(delegate(double t) { interpolatable.Interpolate(startValue, endValue, t); }, duration, ease) )); }
public static CommandDelegate TintTo(GameObject gameObject, Color endColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(gameObject, "gameObject"); return TintTo(gameObject.GetComponent<Renderer>().material, endColour, duration, ease); }
public static CommandDelegate ChangeTo <T>(Ref <T> val, T endValue, IInterpolator <T> interpolator, double duration, CommandEase ease = null) where T : struct { CheckArgumentNonNull(val, "val"); CheckArgumentNonNull(interpolator, "interpolator"); T startValue = val.Value; return(Commands.Sequence( Commands.Do(delegate() { startValue = val.Value; }), Commands.Duration(delegate(double t) { val.Value = interpolator.Interpolate(startValue, endValue, t); }, duration, ease) )); }
public static CommandDelegate TintTo(SpriteRenderer renderer, Color endColour, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return TintTo(renderer.ToColorRef(), endColour, duration, ease); }
/// <summary> /// An <c>CommandDuration</c> runs over a duration of time. /// </summary> /// <param name="command"> /// The command to execute. Must be non-null. /// </param> /// <param name="duration"> /// The duration of time, in seconds, to apply the command over. /// Must be greater than or equal to 0. /// </param> /// <param name="ease"> /// An easing function to apply to the <c>t</c> parameter of an /// <c>CommandDuration</c> delegate. If null, linear easing is used. /// </param> /// <exception cref="System.ArgumentNullException"></exception> /// <exception cref="System.ArgumentOutOfRange"></exception> public static CommandDelegate Duration(CommandDuration command, double duration, CommandEase ease = null) { CheckArgumentNonNull(command); CheckDurationGreaterThanOrEqualToZero(duration); if (duration == 0.0) { // Sometimes it is convenient to create duration commands with // a time of zero, so we have a special case. return((ref double deltaTime) => { var t = 1.0; if (ease != null) { t = ease(t); } command(t); return true; }); } var elapsedTime = 0.0; return((ref double deltaTime) => { elapsedTime += deltaTime; deltaTime = 0.0; var t = (elapsedTime / duration); t = t < 0.0 ? 0.0 : (t > 1.0 ? 1.0 : t); if (ease != null) { t = ease(t); } command(t); var finished = elapsedTime >= duration; if (!finished) { return false; } deltaTime = elapsedTime - duration; elapsedTime = 0.0; return true; }); }
public static CommandDelegate AlphaBy(GUIText text, float offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(text, "text"); return ChangeBy(text.ToAlphaRef(), offset, duration, ease); }
public static CommandDelegate ChangeBy(Ref <Vector4> vector, Vector4 offset, double duration, CommandEase ease = null) { CheckArgumentNonNull(vector, "vector"); double lastT = 0.0; return(Commands.Sequence( Commands.Do(delegate() { lastT = 0.0; }), Commands.Duration(delegate(double t) { vector.Value += offset * (float)(t - lastT); lastT = t; }, duration, ease) )); }
public static CommandDelegate AlphaFrom(Material material, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(material, "material"); return ChangeFrom(material.ToAlphaRef(), startAlpha, duration, ease); }
public static CommandDelegate ChangeFrom(Ref <Rect> rect, Rect startRect, double duration, CommandEase ease = null) { CheckArgumentNonNull(rect, "rect"); return(ChangeFrom(rect, startRect, duration, new Vector2(0.5f, 0.5f), ease)); }
public static CommandDelegate AlphaFrom(GUIText text, float startAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(text, "text"); return ChangeFrom(text.ToAlphaRef(), startAlpha, duration, ease); }
public static CommandDelegate ChangeFrom(Ref <Rect> rect, Rect startRect, double duration, Vector2 anchorPoint, CommandEase ease = null) { CheckArgumentNonNull(rect, "rect"); Rect endRect = new Rect(); Vector2 startAnchorPoint = Vector2.zero; Vector2 endAnchorPoint = Vector2.zero; return(Commands.Sequence( Commands.Do(delegate() { endRect = rect.Value; startAnchorPoint = new Vector2( startRect.x + startRect.width * anchorPoint.x, startRect.y + startRect.height * anchorPoint.y ); endAnchorPoint = new Vector2( endRect.x + endRect.width * anchorPoint.x, endRect.y + endRect.height * anchorPoint.y ); }), Commands.Duration(delegate(double t) { Rect newRect = new Rect(); newRect.width = (endRect.width - startRect.width) * (float)t + startRect.width; newRect.height = (endRect.height - startRect.height) * (float)t + startRect.height; Vector2 newAnchorPoint = Vector2.Lerp(startAnchorPoint, endAnchorPoint, (float)t); newRect.x = newAnchorPoint.x - anchorPoint.x * newRect.width; newRect.y = newAnchorPoint.y - anchorPoint.y * newRect.height; rect.Value = newRect; }, duration, ease) )); }
/// <summary> /// Combines two easing functions. The inEase parameter maps to the range /// 0.0 <= t < 0.5, outEase maps to the range 0.5 <= t < 1.0 , /// </summary> public static CommandEase InOutEase(CommandEase inEase, CommandEase outEase) { return t => { if (t < 0.5) { return 0.5 * inEase(t / 0.5); } return 0.5 * outEase( (t - 0.5) / 0.5) + 0.5; }; }
public static CommandDelegate ChangeTo(Ref <Vector3> vector, Vector3 endVector, double duration, CommandEase ease = null) { CheckArgumentNonNull(vector, "vector"); Vector3 startVector = Vector3.zero; return(Commands.Sequence( Commands.Do(delegate() { startVector = vector.Value; }), Commands.Duration(delegate(double t) { vector.Value = (endVector - startVector) * (float)t + startVector; }, duration, ease) )); }
public static CommandEase WeightedComposite( double weightOne, CommandEase easeOne, double weightTwo, CommandEase easeTwo, double weightThree, CommandEase easeThree) { double totalWeight = weightOne + weightTwo + weightThree; return t => { double currentWeight = t * totalWeight; if (currentWeight < weightOne) { return easeOne(t * 3.0) / 3.0; } else if (currentWeight < weightOne + weightTwo) { return easeTwo(3 * (t - 1.0/3.0)) / 3.0 + 1.0/3.0; } else { return easeThree(3 * (t - 2.0/3.0)) / 3.0 + 2.0/3.0; } }; }
public static CommandDelegate AlphaTo(Renderer renderer, float endAlpha, double duration, CommandEase ease = null) { CheckArgumentNonNull(renderer, "renderer"); return(AlphaTo(renderer.material, endAlpha, duration, ease)); }