Giter Club home page Giter Club logo

interpolations's Introduction

Interpolations

Lightweight Unity library for smoothing movements and value progressions in code (dragging, easing, tweening).

https://twitter.com/stephbysteph/status/1125462189450465280

API is currently experimental and may change.

Current Features

  • Drag outs
    • On the fly dampening of changes over time (float and Vector3)
    • Optional control and status of snapping
  • Easings
    • Robert Penner easing equations, optimized
    • Easings methods pluggable to Unity's Lerp methods
  • Tweens
    • Lightweight and flexible tweening suite
    • Tween class extendable with two one-line methods
    • If needed, direct control over Tween instances and updating, for specific requirements in update timing or instancing
    • Optional runner abstraction handling instances and updates, with choice over which update event function to update within
    • Optional abstraction sugar for different tween types
    • Tween characteristics can be modified while tweening, for dynamic changes
    • Tween instances can be reused, yo-yo-ed, or recycled
    • Tween easings configurable through editor
    • Pure tweens for tweens without side effects
    • Closure tweens for custom tween instances (Float, Vector2-3, Quaternion, Color)
    • Convenience tweens for Transform control (Position, Rotation, Scale)

Examples

Smoothing out sudden value changes

// (Within an update call, i.e. FixedUpdate)
mixer.volume = Volume;
                 |
                 v
mixer.volume = mixer.volume.DragOut(Volume, 30);

Adding easing to a lerp call

Vector3.Lerp(a, b, ratio);
                     |
                     v
Vector3.Lerp(a, b, I.Cubic.InOut(ratio));

Check this cheat sheet for the effect of the different equations.

Tweening a position, the abstracted way

Tweens.Run(new PositionTween(transform))
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut);

or using a shortcut:

Tweens.RunPosition(transform)
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut);

or having it update within FixedUpdate/LateUpdate instead of Update:

Tweens.Fixed.Run...
Tweens.Late.Run...

Tweening a position, the controlling way

Tween<Vector3> positionTween;
...
positionTween = new PositionTween(transform))
      .To(targetPosition)
      .Timing(0, 1, I.Circ.InOut)
      .Start();
...
// In Update, FixedUpdate, or etc
positionTween.Update(Time.timeDelta)

Custom tweening instances

Tweens.RunFloat
(
    () => mixer.GetFloat("sfxVol", out float vol) ? vol : 0,
    vol =>
    {
        mixer.SetFloat("sfxVol", vol);
        indicator.alpha = vol;
    }
)
.To(targetVolume)
.Timing(0, 1, I.Sine.Out);
Tweens.Run(new ColorTween(myScript.GetColor, myScript.SetColor))
      .To(Color.yellow)
      .Timing(0, 1, I.Cubic.InOut);

Features Roadmap

  • Pre-setter value processor closure in Tween
  • More drag out types (Color, Quaternion, Vector2, etc)
  • More closure tween types (Vector4, etc)
  • Documentation

Possible features

  • More convenience tweens for Unity classes (CanvasGroup, Image, etc)
  • Eased sliders (editor and UI)
  • Bezier and CatmullRom Interpolations

Meta

Interpolations https://github.com/phest/interpolations

By Steph Thirion.

Easing equations by Robert Penner, optimized by Tween.js authors.

All code open source under MIT License. See LICENSE file.

interpolations's People

Contributors

phest avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

interpolations's Issues

Question about usage

Hey there,
I was wondering if you happen to know offhand if these tweens could be used in the scene view at edit time, and if so, is there any possibility of an extremely minimal example? I am wanting to try and jazz up my waypoint markers in the editor a bit by making it so they slightly animate when selected.

Thanks,
-MH

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.