{"id":27125436,"url":"https://github.com/dubit/duck-tween","last_synced_at":"2025-10-11T13:40:42.210Z","repository":{"id":56439334,"uuid":"139445590","full_name":"dubit/duck-tween","owner":"dubit","description":"A tween library for unity","archived":false,"fork":false,"pushed_at":"2020-11-07T16:15:07.000Z","size":76,"stargazers_count":25,"open_issues_count":8,"forks_count":4,"subscribers_count":4,"default_branch":"development","last_synced_at":"2023-08-03T20:22:28.088Z","etag":null,"topics":["animation","csharp","tween","tweening","unity"],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dubit.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-07-02T13:11:56.000Z","updated_at":"2023-08-03T20:22:28.089Z","dependencies_parsed_at":"2022-08-15T18:41:01.991Z","dependency_job_id":null,"html_url":"https://github.com/dubit/duck-tween","commit_stats":null,"previous_names":[],"tags_count":6,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Fduck-tween","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Fduck-tween/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Fduck-tween/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dubit%2Fduck-tween/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dubit","download_url":"https://codeload.github.com/dubit/duck-tween/tar.gz/refs/heads/development","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247675602,"owners_count":20977376,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["animation","csharp","tween","tweening","unity"],"created_at":"2025-04-07T14:53:19.738Z","updated_at":"2025-10-11T13:40:37.167Z","avatar_url":"https://github.com/dubit.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# unity-tween\n\n## What is it?\nA simple to use tween library, for moving things with code\n\n## What are the requirements?\n * Unity 2018.x +\n\n# Contributing\n\n## Releasing\n* Use [gitflow](https://nvie.com/posts/a-successful-git-branching-model/)\n* Create a release branch for the release\n* On that branch, bump version number in package json file, any other business (docs/readme updates)\n* Merge to master via pull request and tag the merge commit on master.\n* Merge back to development.\n\n## DUCK\n\nThis repo is part of DUCK (dubit unity component kit)\nDUCK is a series of repos containing reusable component, utils, systems \u0026 tools. \n\nDUCK packages can be added to a project as git submodules or by using [Unity Package Manager](https://docs.unity3d.com/Manual/upm-git.html). \n\n## How to use it\n\n### Creating Tweens\nThere are a lot of ways to create tweens, the 2 primary ways are\n\n#### Using Constructors:\n```c#\n// animation position using a MoveAnimation\nvar animation = new MoveAnimation(targetObject, from, to, duration, easing);\n```\n\n#### Using extension methods\n```c#\n// This is just shorthand for the above\nvar animation = myTransform.Move(from, to, duration, easing);\n```\n\nAlthough there are a lot of these, the function signatures are usually similar\n\n| Name           | Description  |\n| -------------- | -------------|\n| `target`       | The object that the tween will affect |\n| `from`         | the initial state (could be position, rotation, scale, opacity, color etc |\n| `to`           | the final state (will be the same type as `from`|\n| `duration`     | The duration in seconds of how long the tween will take to complete, defaults to `1.0f` |\n| `easing`       | The type of easing to apply, defaults to `Linear`, please see [easing](#easing) for more info |\n| `localSpace`   | (only on some functions), a boolean to control whether or not to use local space, for moving and rotation. |\n\n#### Delegate Animations\nSometimes you don't always know the `from` parameter at the time you create the tween. You only know that at the time we want to play the tween. Delegate animations are used to acheive this.\n\nA delegate animation takes a function that returns an animation. It won't get called until it is played.\n```c#\nvar animation = new DelegateAnimation\u003cMoveAnimation\u003e(() =\u003e {\n  return new MoveAnimation(target, target.position, finalPosition);\n});\n``` \n\nThis allows you to not worry about the starting state, just care about where it should go to.\n\nSeveral extensions exist to do this for you. `MoveTo`, `ScaleTo` `FadeTo` etc. all just make a delegate animation so at play time, the from will be the current state it's in.\n\n#### Easing\nThe easing paramater defaults to a linear ease, but you can pass any function you want into it with the following signature\n`Func\u003cfloat, float\u003e`. This library comes with several built-in ones; the most common ones found [here](https://easings.net).\n\nThey are all under the ease class with nested classes/functions for each type.\n \n Example:\nScale from 0f to 1f, over half a second using [back-out easing](https://easings.net/#easeOutBack)\n```c#\ntransform.Scale(0f, 1f, 0.5f, Ease.Back.Out)\n```\n\n### Playing Tweens\nOnce you have created one, playing a tween is easy\n```c#\ntween.Play();\n```\n\nYou can also pass in a callback for when the tween completes\n```c#\ntween.Play(() =\u003e { Debug.Log(\"It's complete\"); });\n```\n\n**Play(repeatCount)**\n\n### TweenCollections\nThere are 2 types of animation collections, a `SequencedAnimation` for creating a sequence of tweens and `ParalleledAnimation` for playing tweens in parallel.\n\nBoth are types of `AnimationCollection`.\n\nYou can create either of these collections using a fluent interface.\nThere are extension methods for every type of tween. As well as an `Add` function for adding any Tween.\n\n```c#\nvar sequence = new SequencedAnimation()\n    // Use extension methods\n    .FadeTo(spriteRenderer, 1f)\n    .Scale(transform, 0, 1f, 0.24, Ease.Back.Out)\n    // Or use a paralleled within the sequence\n    .Parallel(p =\u003e p\n        // thse are nested within the parallel\n        .Move(transform, positionA, positionB)\n        .RotateY(transform, 0, 360))\n    // or just use add\n    .Add(new MoveAnimation(target, from, to, duration)\n```\n\nParalleledAnimations are created in the same way.\n\n### Advanced playback features\n\n**Abort()**\n\nA tween can be aborted during playback by calling the abort function. The objects will be left in whatever state they are in when the tween is aborted.\n\n**FastForward()**\n\nA tween can also be fast forwarded to the end. This effectively immediately stops the tween and fires the final update frame, so the objects are left in a state equivelant to how they would be if the tween had completed.\n\n**Reverse()**\n\nCalling reverse will put the tween in reverse. It can be used prior to or during playback. If reversed it will cause the animation to play in reverse. For sequenced collections, it will play the animations in reverse order\n\n**ChangeSpeed(float multiplier)**\n\nChange speed will change the animations speed by a multiplier. For example `ChangeSpeed(2.0f)` will double the speed of the animation. The effects are permanent and therefore cumulative, so calling `ChangeSpeed(2.0f)` twice will result in the animation now being 4 times as fast as the original.\n\n**ScaleTime(float duration)**\n\nScale time allows you to change the duration of an animation. This will end up changing the speed. If this is called during playback the progress is maintained. Example. If you are 60% of the way through a 1s animation (elapsed time = 0.6f), and then call `ScaleTime(2f)`. The animation is now 2 seconds long and the progress will remain at 60%, and elapsed time will change to 1.2f. (60% of 2s). The animation therefore will not jump ot a different point, and will still be smooth.\n\n### AnimationDrivers\nThe updates for tweens are driven by animation drivers. \n\nAn animation driver is just an instance of class that implements `IAnimationDriver`. This interface just requires 2 functions, `Add(Func\u003cfloat\u003e update)` and `Remove(Func\u003cfloat\u003e update)`. This allows tweens to add and remove their update functions as they need. Once added the animation driver will call those update functions every frame, passing in the delta time.\n\nThe system uses `DefaultAnimationDriver` out of the box passing in `Time.unscaledDeltaTime`.\n\nYou can override the default driver like this:\n```c#\nTimedAnimation.DefaultDriver = myCustomAnimationDriver;\n```\nNow every new tween created after this assignment will use your driver by default.\n\nYou can also override the driver per tween for even more control like this:\n```c#\nvar tween = new MoveAnimation(transform, startPos, endPos);\ntween.AnimationDriver = myCustomAnimationDriver;\n```\nYou cannot change the animation driver during playback, it must be assigned before playing.\n\n\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubit%2Fduck-tween","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdubit%2Fduck-tween","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdubit%2Fduck-tween/lists"}