diff --git a/CHANGELOG.md b/CHANGELOG.md index 88f541e..d263e25 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,11 +5,35 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [3.0.0] - 2023/10/22 + +### Added + +- Support for creating generic tweens with `short` values +- New extension methods for tweening `MaterialPropertyBlock` +- New extension method `Shadow.TweenAlpha` +- New interface `ITweenEventHandler` that can be used to respond to tween events without allocating GC from delegates +- New utility functions to change color components + +### Changed + +- Refactored tween extensions to not use closures to reduce GC allocations + - Source objects are now cached in the tween and passed to the getter/setter functions +- Changed property name casing to match C# conventions +- Renamed `Transform.TweenScale` to `Transform.TweenLocalScale` +- Renamed `Shadow.TweenEffectColor` to `Shadow.TweenColor` +- Renamed `Shadow.TweenEffectDistance` to `Shadow.TweenDistance` + +### Fixed + +- Fixed tweens not updating when the duration is set to zero +- Fixed interpolation snapping to round to the nearest integer instead of always rounding down + ## [2.6.1] - 2022/05/11 ### Fixed -- Prevented errors caused when tweens are created while the game or scene is unloading +- Prevented errors when tweens are created while the game or scene is unloading ### Changed diff --git a/Documentation~/articles/callbacks.md b/Documentation~/articles/callbacks.md deleted file mode 100644 index a5fbd48..0000000 --- a/Documentation~/articles/callbacks.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -slug: "/manual/callbacks" ---- - -# Callbacks - -Callbacks are used to respond to state changes of a tween. A [TweenCallback](/api/Zigurous.Tweening/TweenCallback) function delegate is invoked for each of the following events: - -- [onUpdate](/api/Zigurous.Tweening/Tween/onUpdate): Invoked every time the tween is updated -- [onStart](/api/Zigurous.Tweening/Tween/onStart): Invoked when the tween is started -- [onStop](/api/Zigurous.Tweening/Tween/onStop): Invoked when the tween is stopped -- [onLoop](/api/Zigurous.Tweening/Tween/onLoop): Invoked when the tween is looped -- [onComplete](/api/Zigurous.Tweening/Tween/onComplete): Invoked when the tween is completed -- [onKill](/api/Zigurous.Tweening/Tween/onKill): Invoked when the tween is killed - -
- -## 🗣️ Assigning callbacks - -Tween callbacks can be assigned with lambdas or normal functions. You can also use [property chaining](/manual/property-chaining) to make it easier in some cases. Tween callbacks have no parameters or return types. - -```csharp -// assigning callbacks with lambdas -tween.onUpdate = () => Debug.Log("Updated"); -tween.onStart = () => Debug.Log("Started"); -tween.onStop = () => Debug.Log("Stopped"); -tween.onLoop = () => Debug.Log("Looped"); -tween.onComplete = () => Debug.Log("Completed"); -tween.onKill = () => Debug.Log("Killed"); -``` - -```csharp -// assigning a callback with a function -Tween tween = transform.TweenPosition(Vector3.zero, 1f); -tween.onComplete = SomeFunction; -``` diff --git a/Documentation~/articles/events.md b/Documentation~/articles/events.md new file mode 100644 index 0000000..6388ba3 --- /dev/null +++ b/Documentation~/articles/events.md @@ -0,0 +1,95 @@ +--- +slug: "/manual/events" +--- + +# Events + +Various events are invoked throughout the tween lifecycle. A [TweenCallback](/api/Zigurous.Tweening/TweenCallback) function delegate can be used to respond to the following events: + +- [onUpdate](/api/Zigurous.Tweening/Tween/onUpdate): Invoked every time the tween is updated +- [onStart](/api/Zigurous.Tweening/Tween/onStart): Invoked when the tween is started +- [onStop](/api/Zigurous.Tweening/Tween/onStop): Invoked when the tween is stopped +- [onLoop](/api/Zigurous.Tweening/Tween/onLoop): Invoked when the tween is looped +- [onComplete](/api/Zigurous.Tweening/Tween/onComplete): Invoked when the tween is completed +- [onKill](/api/Zigurous.Tweening/Tween/onKill): Invoked when the tween is killed + +
+ +## 🗣️ Assigning callbacks + +Tween callbacks can be assigned with delegates or lambdas. They have no parameters or return types. You can also use [property chaining](/manual/property-chaining) to make it easier to set multiple callbacks. + +```csharp +// assigning callbacks with functions +tween.onUpdate += OnTweenUpdated +tween.onStart += OnTweenStarted; +tween.onStop += OnTweenStopped; +tween.onLoop += OnTweenLooped; +tween.onComplete += OnTweenCompleted; +tween.onKill += OnTweenKilled; +``` + +```csharp +// assigning callbacks with lambdas +tween.onUpdate += () => Debug.Log("Updated"); +tween.onStart += () => Debug.Log("Started"); +tween.onStop += () => Debug.Log("Stopped"); +tween.onLoop += () => Debug.Log("Looped"); +tween.onComplete += () => Debug.Log("Completed"); +tween.onKill += () => Debug.Log("Killed"); +``` + +```csharp +// assigning callbacks with property chaining +transform.TweenPosition(Vector3.zero, 1f) + .OnUpdate(OnTweenUpdated) + .OnStart(OnTweenStarted) + .OnStop(OnTweenStopped) + .OnLoop(OnTweenLooped) + .OnComplete(OnTweenCompleted) + .OnKill(OnTweenKilled); +``` + +## 🎫 Event Handler + +One drawback of using delegates is that it produces GC allocations. If you are highly concerned about performance, you can use the [ITweenEventHandler](/api/Zigurous.Tweening/ITweenEventHandler) interface to avoid allocations. + +```csharp +public class Example : MonoBehaviour, ITweenEventHandler +{ + private void Start() + { + transform.TweenPosition(Vector3.zero, 1f) + .SetEventHandler(this); + } + + public void OnTweenUpdate(Tween tween) + { + Debug.Log("Updated"); + } + + public void OnTweenStart(Tween tween) + { + Debug.Log("Started"); + } + + public void OnTweenStop(Tween tween) + { + Debug.Log("Stopped"); + } + + public void OnTweenLoop(Tween tween) + { + Debug.Log("Looped"); + } + + public void OnTweenComplete(Tween tween) + { + Debug.Log("Completed"); + } + + public void OnTweenKill(Tween tween) + { + Debug.Log("Killed"); + } +} diff --git a/Documentation~/articles/index.md b/Documentation~/articles/index.md index 1ea1f7f..f91dc43 100644 --- a/Documentation~/articles/index.md +++ b/Documentation~/articles/index.md @@ -10,22 +10,32 @@ The system is lightweight, optimized, type-safe, and memory efficient. Hundreds
-## 📌 Overview +## Overview -- [Scripting API](/api/Zigurous.Tweening) -- [Installation](/manual/installation) -- [Changelog](/changelog) -- [License](/license) +#### ⚙️ [Installation](/installation) + +#### 🧰 [Scripting API](/api/Zigurous.Tweening) + +#### 📋 [Changelog](/changelog) + +#### ⚖️ [License](/license)
-## 📖 Reference +## Reference + +#### 🚀 [Tweens](/manual/tweens) + +#### 🧬 [Sequences](/manual/sequences) + +#### 〽️ [Easing](/manual/easing) + +#### 🎫 [Events](/manual/events) + +#### ⛓️ [Property Chaining](/manual/property-chaining) + +#### 🏷️ [Managing Tweens](/manual/managing-tweens) + +#### 💠 [Supported Types](/manual/supported-types) -- [Tweens](/manual/tweens) -- [Sequences](/manual/sequences) -- [Easing](/manual/easing) -- [Callbacks](/manual/callbacks) -- [Property Chaining](/manual/property-chaining) -- [Managing Tweens](/manual/managing-tweens) -- [Supported Types](/manual/supported-types) -- [Settings](/manual/settings) +#### 🎛️ [Settings](/manual/settings) diff --git a/Documentation~/articles/managing-tweens.md b/Documentation~/articles/managing-tweens.md index 9f47ca8..5966600 100644 --- a/Documentation~/articles/managing-tweens.md +++ b/Documentation~/articles/managing-tweens.md @@ -17,15 +17,15 @@ Tweening.KillAll(); You can also get the current amount of tweens: ```csharp -int count = Tweening.Count; // the number of tweens alive (not necessarily active) -int alive = Tweening.ActiveCount; // the number of tween active +int count = Tweening.Count; // the number of alive tweens (not necessarily active) +int activeCount = Tweening.ActiveCount; // the number of active tweens ```
## 🏷️ Tween Ids -You can also target specific tweens by id. Every tween has an `id` property which allows you to distinguish it from others. However, this is not required, nor is the id unique. The id is set automatically unless you create tweens manually using the generic approach. +You can also target specific tweens by id. Every tween has an `id` property which allows you to distinguish it from others. However, this is not required, nor is the id unique. The id is set automatically unless you create tweens manually using the generic approach. All ids are implement as `int` values. ```csharp Tweening.Play(id); @@ -35,6 +35,12 @@ Tweening.Complete(id); Tweening.Kill(id); ``` +To manually set the id of a tween: + +```csharp +tween.id = id; +``` +
## 🎯 Target References @@ -49,18 +55,18 @@ Tweening.Complete(transform); Tweening.Kill(transform); ``` -If you create tweens manually using the generic approach, you should indicate to the tween what its target game object or component is, which will set the id of the tween based on that object's hash code. +If you create tweens manually using the generic approach, you should indicate to the tween what game object or component it is referencing. This sets both the id (see above) and scene index (see below) of the tween. ```csharp -tween.SetTarget(gameObject); -tween.SetTarget(component); +tween.SetReference(gameObject); +tween.SetReference(component); ```
## 🎬 Scene Unloading -Tweens will be killed automatically when the scene they are apart of is unloaded which prevents errors. However, this only works automatically if the tween knows which target object it is animating (see above). You should only need to worry about this if you are creating tweens manually using the generic approach. +Tweens will be killed automatically when the scene they are apart of is unloaded which prevents errors accessing objects that have been destroyed. However, this only works automatically if the tween knows which target object it is animating (see above). You should only need to worry about this if you are creating tweens manually using the generic approach. Make sure to kill your tweens before transitioning scenes, or set the target reference as outlined above. You can also manually set the scene index if desired. diff --git a/Documentation~/articles/property-chaining.md b/Documentation~/articles/property-chaining.md index 25a90b1..817d220 100644 --- a/Documentation~/articles/property-chaining.md +++ b/Documentation~/articles/property-chaining.md @@ -8,13 +8,25 @@ Property/method chaining is a technique that allows multiple properties to be as
-## ⛓️ Example +## ⛓️ Examples ```csharp +// using a tween shortcut transform.TweenPosition(Vector3.zero, 1f) .SetDelay(3f) - .SetReversed(true) + .SetReversed() .SetEase(Ease.CubicInOut) .SetLoops(-1, LoopType.PingPong) .OnLoop(() => Debug.Log("looped!")); ``` + +```csharp +// building from scratch +Tween tween = new Tweener(transform) + .SetGetter((target) => target.position) + .SetSetter((target, value) => target.position = value) + .SetEndValue(Vector3.zero) + .SetDuration(1f) + .SetEase(Ease.QuadOut) + .OnComplete(() => Debug.Log("complete!")); +``` diff --git a/Documentation~/articles/sequences.md b/Documentation~/articles/sequences.md index 4d6211b..903e719 100644 --- a/Documentation~/articles/sequences.md +++ b/Documentation~/articles/sequences.md @@ -43,6 +43,6 @@ Sequences can be controlled the same way as any other tween, meaning you can pla ```csharp Sequence sequence = Tweening.Sequence(); sequence.SetLoops(-1, LoopType.PingPong); -sequence.OnComplete(() => Debug.Log("sucess!")); +sequence.OnComplete(() => Debug.Log("success!")); sequence.Play(); ``` diff --git a/Documentation~/articles/settings.md b/Documentation~/articles/settings.md index 6581ad2..7a6dd3b 100644 --- a/Documentation~/articles/settings.md +++ b/Documentation~/articles/settings.md @@ -35,7 +35,7 @@ Settings.recyclable = true;
-## 🖥️ Changing settings in the editor +## 🎛️ Changing settings in the editor The [Settings](/api/Zigurous.Tweening/Settings) class can also be used as a MonoBehaviour added to your scene. This is generally used to provide a simple interface for changing settings in the Unity editor rather than with code. You can, of course, still use this behavior to change settings at runtime if desired, in which case there is a function to set each respective setting. diff --git a/Documentation~/articles/supported-types.md b/Documentation~/articles/supported-types.md index 6b271a0..f96d1a3 100644 --- a/Documentation~/articles/supported-types.md +++ b/Documentation~/articles/supported-types.md @@ -10,8 +10,9 @@ When creating tweens using the generic functions, the following types of values - `float` - `double` -- `long` - `int` +- `long` +- `short` - `Vector2` - `Vector2Int` - `Vector3` @@ -75,6 +76,7 @@ All of the following types offer shortcut functions for creating tweens: - `LineRenderer` - `LookAtConstraint` - `Material` +- `MaterialPropertyBlock` - `NavMeshAgent` - `NavMeshObstacle` - `OcclusionArea` diff --git a/Documentation~/articles/tweens.md b/Documentation~/articles/tweens.md index 2e6f790..c7414f7 100644 --- a/Documentation~/articles/tweens.md +++ b/Documentation~/articles/tweens.md @@ -18,29 +18,25 @@ A tween is an animation of a value from a start position to an end position usin Most of the time you will be creating tweens by using the shortcut extension methods available on most Unity objects. See the [Supported Types](/manual/supported-types) manual for the full list of classes that provide shortcut functions. Here are just a few examples: ```csharp -transform.TweenPosition(endValue, duration); -material.TweenColor(endValue, duration); -camera.TweenFieldOfView(endValue, duration); -light.TweenIntensity(endValue, duration); +transform.TweenPosition(Vector3.zero, duration); +material.TweenColor(Color.white, duration); +camera.TweenFieldOfView(90f, duration); +light.TweenIntensity(1f, duration); ```
### Generic Approach -Although most of the time you will not be creating tweens with this approach, it is the basis of the entire tweening system so it is valuable to understand how it works. Essentially any value represented by a number can be tweened. The [Supported Types](/manual/supported-types) manual lists all of the specific types that can be tweened. +Although most of the time you will not be creating tweens with this approach, it is the basis of the entire tweening system so it is valuable to understand how it works. Essentially any value represented by a number can be tweened. The [Supported Types](/manual/supported-types) manual provides a list of all types that can be tweened. ```csharp -float currentValue, endValue, duration; - // Setup delegates to get and set a value -TweenGetter getter = () => { return currentValue; }; -TweenSetter setter = newValue => { currentValue = newValue; }; - -// Create a tween that animates to the end value from the current value -Tweening.To(getter, setter, endValue, duration); +TweenGetter getter = (target) => target.position; +TweenSetter setter = (target, value) => target.position = value; -// Create a tween that animates from the end value to the current value -Tweening.From(getter, setter, endValue, duration); +// Create a tween that animates to the end value over a duration +Tweening.To(transform, getter, setter, Vector3.one, 1f); +Tweening.From(transform, getter, setter, Vector3.one, 1f); ```
@@ -69,10 +65,10 @@ All of these properties can be set with [property chaining](/manual/property-cha ## 🌪️ Controlling tweens -Often times you might want to manually control the state of the tween, even if it is just pausing and resuming a tween. There are several methods available to transition a tween to a different state. *Note*: not all states can be transitioned to depending on the current state. See [Managing Tweens](/manual/managing-tweens) for ways to control tweens globally. +Often times you might want to manually control the state of the tween, even if it is just pausing and resuming a tween. There are several methods available to transition a tween to a different state. *Note:* not all states can be transitioned to depending on the current state. See [Managing Tweens](/manual/managing-tweens) for ways to control tweens globally. ```csharp -tween.Play(); // starts or resumes the the tween +tween.Play(); // starts or resumes the tween tween.Stop(); // pauses the tween if it is already playing tween.Restart(); // restarts the tween from the beginning if not killed tween.Complete(); // completes the tween, jumping to the end value @@ -92,7 +88,7 @@ There are a number of properties available to read the current state of a tween. - `Killed`: The tween is killed, making it no longer usable. ```csharp -TweenState state = tween.state; // the current animation state of the tween +TweenState state = tween.State; // the current animation state of the tween bool playing = tween.IsPlaying; // true if playing bool stopped = tween.IsStopped; // true if stopped @@ -100,9 +96,9 @@ bool complete = tween.IsComplete; // true if complete bool killed = tween.IsKilled; // true if killed bool delayed = tween.IsDelayed; // true if delayed -float elapsed = tween.elapsed; // the amount of seconds playing +float elapsed = tween.Elapsed; // the amount of seconds playing float percent = tween.PercentComplete; // the percentage of completion -float delayElapsed = tween.delayElapsed; // the amount of seconds delayed +float delayElapsed = tween.DelayElapsed; // the amount of seconds delayed -int iterations = tween.iterations; // the number of times completed +int iterations = tween.Iterations; // the number of times completed ``` diff --git a/Documentation~/data/sidenav.json b/Documentation~/data/sidenav.json index f2604cd..07cebfd 100644 --- a/Documentation~/data/sidenav.json +++ b/Documentation~/data/sidenav.json @@ -36,8 +36,8 @@ "path": "/manual/easing" }, { - "name": "Callbacks", - "path": "/manual/callbacks" + "name": "Events", + "path": "/manual/events" }, { "name": "Property Chaining", diff --git a/README.md b/README.md index cb5e8e1..65b8c84 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ The system is lightweight, optimized, type-safe, and memory efficient. Hundreds - [Tweens](https://docs.zigurous.com/com.zigurous.tweening/manual/tweens) - [Sequences](https://docs.zigurous.com/com.zigurous.tweening/manual/sequences) - [Easing](https://docs.zigurous.com/com.zigurous.tweening/manual/easing) -- [Callbacks](https://docs.zigurous.com/com.zigurous.tweening/manual/callbacks) +- [Events](https://docs.zigurous.com/com.zigurous.tweening/manual/events) - [Property Chaining](https://docs.zigurous.com/com.zigurous.tweening/manual/property-chaining) - [Managing Tweens](https://docs.zigurous.com/com.zigurous.tweening/manual/managing-tweens) - [Supported Types](https://docs.zigurous.com/com.zigurous.tweening/manual/supported-types) diff --git a/Runtime/ColorExtensions.cs b/Runtime/ColorExtensions.cs new file mode 100644 index 0000000..d822b57 --- /dev/null +++ b/Runtime/ColorExtensions.cs @@ -0,0 +1,56 @@ +using UnityEngine; + +namespace Zigurous.Tweening +{ + /// + /// Utility extension methods for colors. + /// + internal static class ColorExtensions + { + /// + /// Returns a copy of the color with the red component changed. + /// + /// The color to change. + /// The new red component. + /// A copy of the color with the red component changed. + public static Color WithRed(this Color color, float red) + { + return new Color(red, color.g, color.b, color.a); + } + + /// + /// Returns a copy of the color with the green component changed. + /// + /// The color to change. + /// The new green component. + /// A copy of the color with the green component changed. + public static Color WithGreen(this Color color, float green) + { + return new Color(color.r, green, color.b, color.a); + } + + /// + /// Returns a copy of the color with the blue component changed. + /// + /// The color to change. + /// The new blue component. + /// A copy of the color with the blue component changed. + public static Color WithBlue(this Color color, float blue) + { + return new Color(color.r, color.g, blue, color.a); + } + + /// + /// Returns a copy of the color with the alpha component changed. + /// + /// The color to change. + /// The new alpha component. + /// A copy of the color with the alpha component changed. + public static Color WithAlpha(this Color color, float alpha) + { + return new Color(color.r, color.g, color.b, alpha); + } + + } + +} diff --git a/Runtime/ColorExtensions.cs.meta b/Runtime/ColorExtensions.cs.meta new file mode 100644 index 0000000..b23c7bc --- /dev/null +++ b/Runtime/ColorExtensions.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 856265b6de5c23643846b48aee7d1539 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Delegates.cs b/Runtime/Delegates.cs index a6a906a..596db84 100644 --- a/Runtime/Delegates.cs +++ b/Runtime/Delegates.cs @@ -1,25 +1,36 @@ namespace Zigurous.Tweening { /// - /// A function delegate that gets the current value of a parameter. + /// A function delegate that gets the current value of a parameter from an + /// object. /// - /// The type of the parameter. + /// The type of object to get the parameter from. + /// The type of the parameter. + /// The object to get the value from. /// The current value of the parameter. - public delegate T TweenGetter(); + public delegate U TweenGetter(T target); /// - /// A function delegate that sets a new value of a parameter. + /// A function delegate that sets a new value of a parameter on an object. /// - /// The type of the parameter. + /// The type of object to set the parameter on. + /// The type of the parameter. + /// The object to set the value on. /// The new value of the parameter. - public delegate void TweenSetter(T value); + public delegate void TweenSetter(T target, U value); /// - /// A function delegate that can be invoked during various tween events - /// and/or state changes. + /// A function delegate invoked during tween lifecycle events. /// public delegate void TweenCallback(); + /// + /// A function delegate invoked during tween lifecycle events with a + /// provided reference to the tween that invoked the event. + /// + /// The tween that invoked the event. + public delegate void TweenReferenceCallback(Tween tween); + /// /// A function delegate that interpolates the value between /// and by . @@ -31,5 +42,4 @@ /// Snaps the interpolated value to the nearest whole number. /// The interpolated value between the start and end value. public delegate T Interpolater(T a, T b, float t, bool snapping); - } diff --git a/Runtime/EaseFunction.cs b/Runtime/EaseFunction.cs index 9170d26..fbe7cbf 100644 --- a/Runtime/EaseFunction.cs +++ b/Runtime/EaseFunction.cs @@ -167,7 +167,6 @@ public static float QuadInOut(float x) return x < 0.5f ? 2f * x * x : 1f - Mathf.Pow(-2f * x + 2f, 2f) / 2f; - } /// diff --git a/Runtime/Extensions/Audio/AudioChorusFilterTweens.cs b/Runtime/Extensions/Audio/AudioChorusFilterTweens.cs index 7647f53..33c3cd9 100644 --- a/Runtime/Extensions/Audio/AudioChorusFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioChorusFilterTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class AudioChorusFilterTweens { public static Tween TweenDelay(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.delay, - setter: delay => filter.delay = delay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.delay, (target, value) => target.delay = value, to, duration) + .SetReference(filter); public static Tween TweenRate(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.rate, - setter: rate => filter.rate = rate, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.rate, (target, value) => target.rate = value, to, duration) + .SetReference(filter); public static Tween TweenDepth(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.depth, - setter: depth => filter.depth = depth, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.depth, (target, value) => target.depth = value, to, duration) + .SetReference(filter); public static Tween TweenDryMix(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.dryMix, - setter: dryMix => filter.dryMix = dryMix, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.dryMix, (target, value) => target.dryMix = value, to, duration) + .SetReference(filter); public static Tween TweenWetMix1(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.wetMix1, - setter: wetMix1 => filter.wetMix1 = wetMix1, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.wetMix1, (target, value) => target.wetMix1 = value, to, duration) + .SetReference(filter); public static Tween TweenWetMix2(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.wetMix2, - setter: wetMix2 => filter.wetMix2 = wetMix2, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.wetMix2, (target, value) => target.wetMix2 = value, to, duration) + .SetReference(filter); public static Tween TweenWetMix3(this AudioChorusFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.wetMix3, - setter: wetMix3 => filter.wetMix3 = wetMix3, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.wetMix3, (target, value) => target.wetMix3 = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs b/Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs index 55b1a52..2aaf0d6 100644 --- a/Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class AudioDistortionFilterTweens { public static Tween TweenDistortionLevel(this AudioDistortionFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.distortionLevel, - setter: distortionLevel => filter.distortionLevel = distortionLevel, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.distortionLevel, (target, value) => target.distortionLevel = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioEchoFilterTweens.cs b/Runtime/Extensions/Audio/AudioEchoFilterTweens.cs index 215a12f..d83c3d7 100644 --- a/Runtime/Extensions/Audio/AudioEchoFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioEchoFilterTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class AudioEchoFilterTweens { public static Tween TweenDelay(this AudioEchoFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.delay, - setter: delay => filter.delay = delay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.delay, (target, value) => target.delay = value, to, duration) + .SetReference(filter); public static Tween TweenDecayRatio(this AudioEchoFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.decayRatio, - setter: decayRatio => filter.decayRatio = decayRatio, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.decayRatio, (target, value) => target.decayRatio = value, to, duration) + .SetReference(filter); public static Tween TweenDryMix(this AudioEchoFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.dryMix, - setter: dryMix => filter.dryMix = dryMix, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.dryMix, (target, value) => target.dryMix = value, to, duration) + .SetReference(filter); public static Tween TweenWetMix(this AudioEchoFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.wetMix, - setter: wetMix => filter.wetMix = wetMix, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.wetMix, (target, value) => target.wetMix = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs b/Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs index 1742d10..c4f6154 100644 --- a/Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class AudioHighPassFilterTweens { public static Tween TweenCutoffFrequency(this AudioHighPassFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.cutoffFrequency, - setter: cutoffFrequency => filter.cutoffFrequency = cutoffFrequency, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.cutoffFrequency, (target, value) => target.cutoffFrequency = value, to, duration) + .SetReference(filter); public static Tween TweenHighpassResonanceQ(this AudioHighPassFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.highpassResonanceQ, - setter: highpassResonanceQ => filter.highpassResonanceQ = highpassResonanceQ, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.highpassResonanceQ, (target, value) => target.highpassResonanceQ = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioListenerTweens.cs b/Runtime/Extensions/Audio/AudioListenerTweens.cs index 22d5ba6..2adafcf 100644 --- a/Runtime/Extensions/Audio/AudioListenerTweens.cs +++ b/Runtime/Extensions/Audio/AudioListenerTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class AudioListenerTweens { public static Tween TweenVolume(this AudioListener listener, float to, float duration) => - Tweening.To(getter: () => AudioListener.volume, - setter: volume => AudioListener.volume = volume, - to, duration).SetTarget(listener); - + Tweening.To(listener, (source) => AudioListener.volume, (source, value) => AudioListener.volume = value, to, duration) + .SetReference(listener); } } diff --git a/Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs b/Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs index d090fe4..d959dac 100644 --- a/Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class AudioLowPassFilterTweens { public static Tween TweenCutoffFrequency(this AudioLowPassFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.cutoffFrequency, - setter: cutoffFrequency => filter.cutoffFrequency = cutoffFrequency, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.cutoffFrequency, (target, value) => target.cutoffFrequency = value, to, duration) + .SetReference(filter); public static Tween TweenLowpassResonanceQ(this AudioLowPassFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.lowpassResonanceQ, - setter: lowpassResonanceQ => filter.lowpassResonanceQ = lowpassResonanceQ, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.lowpassResonanceQ, (target, value) => target.lowpassResonanceQ = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioReverbFilterTweens.cs b/Runtime/Extensions/Audio/AudioReverbFilterTweens.cs index 1fb1d26..1e9531e 100644 --- a/Runtime/Extensions/Audio/AudioReverbFilterTweens.cs +++ b/Runtime/Extensions/Audio/AudioReverbFilterTweens.cs @@ -5,75 +5,60 @@ namespace Zigurous.Tweening public static class AudioReverbFilterTweens { public static Tween TweenDensity(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.density, - setter: density => filter.density = density, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.density, (target, value) => target.density = value, to, duration) + .SetReference(filter); public static Tween TweenDiffusion(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.diffusion, - setter: diffusion => filter.diffusion = diffusion, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.diffusion, (target, value) => target.diffusion = value, to, duration) + .SetReference(filter); public static Tween TweenReverbDelay(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.reverbDelay, - setter: reverbDelay => filter.reverbDelay = reverbDelay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reverbDelay, (target, value) => target.reverbDelay = value, to, duration) + .SetReference(filter); public static Tween TweenReverbLevel(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.reverbLevel, - setter: reverbLevel => filter.reverbLevel = reverbLevel, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reverbLevel, (target, value) => target.reverbLevel = value, to, duration) + .SetReference(filter); public static Tween TweenReflectionsDelay(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.reflectionsDelay, - setter: reflectionsDelay => filter.reflectionsDelay = reflectionsDelay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reflectionsDelay, (target, value) => target.reflectionsDelay = value, to, duration) + .SetReference(filter); public static Tween TweenReflectionsLevel(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.reflectionsLevel, - setter: reflectionsLevel => filter.reflectionsLevel = reflectionsLevel, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reflectionsLevel, (target, value) => target.reflectionsLevel = value, to, duration) + .SetReference(filter); public static Tween TweenDecayHFRatio(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.decayHFRatio, - setter: decayHFRatio => filter.decayHFRatio = decayHFRatio, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.decayHFRatio, (target, value) => target.decayHFRatio = value, to, duration) + .SetReference(filter); public static Tween TweenDecayTime(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.decayTime, - setter: decayTime => filter.decayTime = decayTime, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.decayTime, (target, value) => target.decayTime = value, to, duration) + .SetReference(filter); public static Tween TweenRoom(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.room, - setter: room => filter.room = room, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.room, (target, value) => target.room = value, to, duration) + .SetReference(filter); public static Tween TweenRoomHF(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.roomHF, - setter: roomHF => filter.roomHF = roomHF, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.roomHF, (target, value) => target.roomHF = value, to, duration) + .SetReference(filter); public static Tween TweenRoomLF(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.roomLF, - setter: roomLF => filter.roomLF = roomLF, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.roomLF, (target, value) => target.roomLF = value, to, duration) + .SetReference(filter); public static Tween TweenDryLevel(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.dryLevel, - setter: dryLevel => filter.dryLevel = dryLevel, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.dryLevel, (target, value) => target.dryLevel = value, to, duration) + .SetReference(filter); public static Tween TweenHFReference(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.hfReference, - setter: hfReference => filter.hfReference = hfReference, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.hfReference, (target, value) => target.hfReference = value, to, duration) + .SetReference(filter); public static Tween TweenLFReference(this AudioReverbFilter filter, float to, float duration) => - Tweening.To(getter: () => filter.lfReference, - setter: lfReference => filter.lfReference = lfReference, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.lfReference, (target, value) => target.lfReference = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioReverbZoneTweens.cs b/Runtime/Extensions/Audio/AudioReverbZoneTweens.cs index 322dd52..d3ede30 100644 --- a/Runtime/Extensions/Audio/AudioReverbZoneTweens.cs +++ b/Runtime/Extensions/Audio/AudioReverbZoneTweens.cs @@ -5,55 +5,44 @@ namespace Zigurous.Tweening public static class AudioReverbZoneTweens { public static Tween TweenMaxDistance(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.maxDistance, - setter: maxDistance => filter.maxDistance = maxDistance, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.maxDistance, (target, value) => target.maxDistance = value, to, duration) + .SetReference(filter); public static Tween TweenMinDistance(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.minDistance, - setter: minDistance => filter.minDistance = minDistance, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.minDistance, (target, value) => target.minDistance = value, to, duration) + .SetReference(filter); public static Tween TweenDiffusion(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.diffusion, - setter: diffusion => filter.diffusion = diffusion, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.diffusion, (target, value) => target.diffusion = value, to, duration) + .SetReference(filter); public static Tween TweenDensity(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.density, - setter: density => filter.density = density, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.density, (target, value) => target.density = value, to, duration) + .SetReference(filter); public static Tween TweenReverbDelay(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.reverbDelay, - setter: reverbDelay => filter.reverbDelay = reverbDelay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reverbDelay, (target, value) => target.reverbDelay = value, to, duration) + .SetReference(filter); public static Tween TweenReflectionsDelay(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.reflectionsDelay, - setter: reflectionsDelay => filter.reflectionsDelay = reflectionsDelay, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.reflectionsDelay, (target, value) => target.reflectionsDelay = value, to, duration) + .SetReference(filter); public static Tween TweenDecayHFRatio(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.decayHFRatio, - setter: decayHFRatio => filter.decayHFRatio = decayHFRatio, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.decayHFRatio, (target, value) => target.decayHFRatio = value, to, duration) + .SetReference(filter); public static Tween TweenDecayTime(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.decayTime, - setter: decayTime => filter.decayTime = decayTime, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.decayTime, (target, value) => target.decayTime = value, to, duration) + .SetReference(filter); public static Tween TweenHFReference(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.HFReference, - setter: HFReference => filter.HFReference = HFReference, - to, duration).SetTarget(filter); + Tweening.To(filter, (target) => target.HFReference, (target, value) => target.HFReference = value, to, duration) + .SetReference(filter); public static Tween TweenLFReference(this AudioReverbZone filter, float to, float duration) => - Tweening.To(getter: () => filter.LFReference, - setter: LFReference => filter.LFReference = LFReference, - to, duration).SetTarget(filter); - + Tweening.To(filter, (target) => target.LFReference, (target, value) => target.LFReference = value, to, duration) + .SetReference(filter); } } diff --git a/Runtime/Extensions/Audio/AudioSourceTweens.cs b/Runtime/Extensions/Audio/AudioSourceTweens.cs index 755992f..58c1344 100644 --- a/Runtime/Extensions/Audio/AudioSourceTweens.cs +++ b/Runtime/Extensions/Audio/AudioSourceTweens.cs @@ -4,56 +4,45 @@ namespace Zigurous.Tweening { public static class AudioSourceTweens { - public static Tween TweenTime(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.time, - setter: time => source.time = time, - to, duration).SetTarget(source); - - public static Tween TweenPitch(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.pitch, - setter: pitch => source.pitch = pitch, - to, duration).SetTarget(source); - - public static Tween TweenVolume(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.volume, - setter: volume => source.volume = volume, - to, duration).SetTarget(source); - - public static Tween TweenPanStereo(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.panStereo, - setter: panStereo => source.panStereo = panStereo, - to, duration).SetTarget(source); - - public static Tween TweenSpatialBlend(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.spatialBlend, - setter: spatialBlend => source.spatialBlend = spatialBlend, - to, duration).SetTarget(source); - - public static Tween TweenReverbZoneMix(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.reverbZoneMix, - setter: reverbZoneMix => source.reverbZoneMix = reverbZoneMix, - to, duration).SetTarget(source); - - public static Tween TweenDopplerLevel(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.dopplerLevel, - setter: dopplerLevel => source.dopplerLevel = dopplerLevel, - to, duration).SetTarget(source); - - public static Tween TweenSpread(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.spread, - setter: spread => source.spread = spread, - to, duration).SetTarget(source); - - public static Tween TweenMinDistance(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.minDistance, - setter: minDistance => source.minDistance = minDistance, - to, duration).SetTarget(source); - - public static Tween TweenMaxDistance(this AudioSource source, float to, float duration) => - Tweening.To(getter: () => source.maxDistance, - setter: maxDistance => source.maxDistance = maxDistance, - to, duration).SetTarget(source); + public static Tween TweenTime(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.time, (target, value) => target.time = value, to, duration) + .SetReference(audioSource); + public static Tween TweenPitch(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.pitch, (target, value) => target.pitch = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenVolume(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.volume, (target, value) => target.volume = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenPanStereo(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.panStereo, (target, value) => target.panStereo = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenSpatialBlend(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.spatialBlend, (target, value) => target.spatialBlend = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenReverbZoneMix(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.reverbZoneMix, (target, value) => target.reverbZoneMix = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenDopplerLevel(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.dopplerLevel, (target, value) => target.dopplerLevel = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenSpread(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.spread, (target, value) => target.spread = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenMinDistance(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.minDistance, (target, value) => target.minDistance = value, to, duration) + .SetReference(audioSource); + + public static Tween TweenMaxDistance(this AudioSource audioSource, float to, float duration) => + Tweening.To(audioSource, (target) => target.maxDistance, (target, value) => target.maxDistance = value, to, duration) + .SetReference(audioSource); } } diff --git a/Runtime/Extensions/Misc/AimConstraintTweens.cs b/Runtime/Extensions/Misc/AimConstraintTweens.cs index d506e0f..9433885 100644 --- a/Runtime/Extensions/Misc/AimConstraintTweens.cs +++ b/Runtime/Extensions/Misc/AimConstraintTweens.cs @@ -6,35 +6,28 @@ namespace Zigurous.Tweening public static class AimConstraintTweens { public static Tween TweenWeight(this AimConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenUpVector(this AimConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.upVector, - setter: upVector => constraint.upVector = upVector, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.upVector, (target, value) => target.upVector = value, to, duration) + .SetReference(constraint); public static Tween TweenWorldUpVector(this AimConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.worldUpVector, - setter: worldUpVector => constraint.worldUpVector = worldUpVector, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.worldUpVector, (target, value) => target.worldUpVector = value, to, duration) + .SetReference(constraint); public static Tween TweenAimVector(this AimConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.aimVector, - setter: aimVector => constraint.aimVector = aimVector, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.aimVector, (target, value) => target.aimVector = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationOffset(this AimConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationOffset, - setter: rotationOffset => constraint.rotationOffset = rotationOffset, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.rotationOffset, (target, value) => target.rotationOffset = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationAtRest(this AimConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationAtRest, - setter: rotationAtRest => constraint.rotationAtRest = rotationAtRest, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.rotationAtRest, (target, value) => target.rotationAtRest = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/GridTweens.cs b/Runtime/Extensions/Misc/GridTweens.cs index 4814673..1e14b0c 100644 --- a/Runtime/Extensions/Misc/GridTweens.cs +++ b/Runtime/Extensions/Misc/GridTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class GridTweens { public static Tween TweenCellSize(this Grid grid, Vector3 to, float duration) => - Tweening.To(getter: () => grid.cellSize, - setter: cellSize => grid.cellSize = cellSize, - to, duration).SetTarget(grid); + Tweening.To(grid, (target) => target.cellSize, (target, value) => target.cellSize = value, to, duration) + .SetReference(grid); public static Tween TweenCellGap(this Grid grid, Vector3 to, float duration) => - Tweening.To(getter: () => grid.cellGap, - setter: cellGap => grid.cellGap = cellGap, - to, duration).SetTarget(grid); - + Tweening.To(grid, (target) => target.cellGap, (target, value) => target.cellGap = value, to, duration) + .SetReference(grid); } } diff --git a/Runtime/Extensions/Misc/LookAtConstraintTweens.cs b/Runtime/Extensions/Misc/LookAtConstraintTweens.cs index d36066a..b765b3b 100644 --- a/Runtime/Extensions/Misc/LookAtConstraintTweens.cs +++ b/Runtime/Extensions/Misc/LookAtConstraintTweens.cs @@ -6,25 +6,20 @@ namespace Zigurous.Tweening public static class LookAtConstraintTweens { public static Tween TweenWeight(this LookAtConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenRoll(this LookAtConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.roll, - setter: roll => constraint.roll = roll, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.roll, (target, value) => target.roll = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationOffset(this LookAtConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationOffset, - setter: rotationOffset => constraint.rotationOffset = rotationOffset, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.rotationOffset, (target, value) => target.rotationOffset = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationAtRest(this LookAtConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationAtRest, - setter: rotationAtRest => constraint.rotationAtRest = rotationAtRest, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.rotationAtRest, (target, value) => target.rotationAtRest = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/ParentConstraintTweens.cs b/Runtime/Extensions/Misc/ParentConstraintTweens.cs index b89c53d..b8cbad1 100644 --- a/Runtime/Extensions/Misc/ParentConstraintTweens.cs +++ b/Runtime/Extensions/Misc/ParentConstraintTweens.cs @@ -6,20 +6,16 @@ namespace Zigurous.Tweening public static class ParentConstraintTweens { public static Tween TweenWeight(this ParentConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationAtRest(this ParentConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationAtRest, - setter: rotationAtRest => constraint.rotationAtRest = rotationAtRest, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.rotationAtRest, (target, value) => target.rotationAtRest = value, to, duration) + .SetReference(constraint); public static Tween TweenTranslationAtRest(this ParentConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.translationAtRest, - setter: translationAtRest => constraint.translationAtRest = translationAtRest, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.translationAtRest, (target, value) => target.translationAtRest = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/PositionConstraintTweens.cs b/Runtime/Extensions/Misc/PositionConstraintTweens.cs index 93bd121..e3d4769 100644 --- a/Runtime/Extensions/Misc/PositionConstraintTweens.cs +++ b/Runtime/Extensions/Misc/PositionConstraintTweens.cs @@ -6,20 +6,16 @@ namespace Zigurous.Tweening public static class PositionConstraintTweens { public static Tween TweenWeight(this PositionConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenTranslationAtRest(this PositionConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.translationAtRest, - setter: translationAtRest => constraint.translationAtRest = translationAtRest, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.translationAtRest, (target, value) => target.translationAtRest = value, to, duration) + .SetReference(constraint); public static Tween TweenTranslationOffset(this PositionConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.translationOffset, - setter: translationOffset => constraint.translationOffset = translationOffset, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.translationOffset, (target, value) => target.translationOffset = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/RectOffsetTweens.cs b/Runtime/Extensions/Misc/RectOffsetTweens.cs index dbbf610..cd1cf40 100644 --- a/Runtime/Extensions/Misc/RectOffsetTweens.cs +++ b/Runtime/Extensions/Misc/RectOffsetTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class RectOffsetTweens { public static Tween TweenLeft(this RectOffset offset, int to, float duration) => - Tweening.To(getter: () => offset.left, - setter: left => offset.left = left, - to, duration).SetId(offset.GetHashCode()); + Tweening.To(offset, (target) => target.left, (target, value) => target.left = value, to, duration) + .SetId(offset.GetHashCode()); public static Tween TweenRight(this RectOffset offset, int to, float duration) => - Tweening.To(getter: () => offset.right, - setter: right => offset.right = right, - to, duration).SetId(offset.GetHashCode()); + Tweening.To(offset, (target) => target.right, (target, value) => target.right = value, to, duration) + .SetId(offset.GetHashCode()); public static Tween TweenTop(this RectOffset offset, int to, float duration) => - Tweening.To(getter: () => offset.top, - setter: top => offset.top = top, - to, duration).SetId(offset.GetHashCode()); + Tweening.To(offset, (target) => target.top, (target, value) => target.top = value, to, duration) + .SetId(offset.GetHashCode()); public static Tween TweenBottom(this RectOffset offset, int to, float duration) => - Tweening.To(getter: () => offset.bottom, - setter: bottom => offset.bottom = bottom, - to, duration).SetId(offset.GetHashCode()); - + Tweening.To(offset, (target) => target.bottom, (target, value) => target.bottom = value, to, duration) + .SetId(offset.GetHashCode()); } } diff --git a/Runtime/Extensions/Misc/RotationConstraintTweens.cs b/Runtime/Extensions/Misc/RotationConstraintTweens.cs index 7ec36d2..adef49f 100644 --- a/Runtime/Extensions/Misc/RotationConstraintTweens.cs +++ b/Runtime/Extensions/Misc/RotationConstraintTweens.cs @@ -6,20 +6,16 @@ namespace Zigurous.Tweening public static class RotationConstraintTweens { public static Tween TweenWeight(this RotationConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationAtRest(this RotationConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationAtRest, - setter: rotationAtRest => constraint.rotationAtRest = rotationAtRest, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.rotationAtRest, (target, value) => target.rotationAtRest = value, to, duration) + .SetReference(constraint); public static Tween TweenRotationOffset(this RotationConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.rotationOffset, - setter: rotationOffset => constraint.rotationOffset = rotationOffset, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.rotationOffset, (target, value) => target.rotationOffset = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/ScaleConstraintTweens.cs b/Runtime/Extensions/Misc/ScaleConstraintTweens.cs index 1cda2e7..9088295 100644 --- a/Runtime/Extensions/Misc/ScaleConstraintTweens.cs +++ b/Runtime/Extensions/Misc/ScaleConstraintTweens.cs @@ -6,20 +6,16 @@ namespace Zigurous.Tweening public static class ScaleConstraintTweens { public static Tween TweenWeight(this ScaleConstraint constraint, float to, float duration) => - Tweening.To(getter: () => constraint.weight, - setter: weight => constraint.weight = weight, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.weight, (target, value) => target.weight = value, to, duration) + .SetReference(constraint); public static Tween TweenScaleAtRest(this ScaleConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.scaleAtRest, - setter: scaleAtRest => constraint.scaleAtRest = scaleAtRest, - to, duration).SetTarget(constraint); + Tweening.To(constraint, (target) => target.scaleAtRest, (target, value) => target.scaleAtRest = value, to, duration) + .SetReference(constraint); public static Tween TweenScaleOffset(this ScaleConstraint constraint, Vector3 to, float duration) => - Tweening.To(getter: () => constraint.scaleOffset, - setter: scaleOffset => constraint.scaleOffset = scaleOffset, - to, duration).SetTarget(constraint); - + Tweening.To(constraint, (target) => target.scaleOffset, (target, value) => target.scaleOffset = value, to, duration) + .SetReference(constraint); } } diff --git a/Runtime/Extensions/Misc/TransformTweens.cs b/Runtime/Extensions/Misc/TransformTweens.cs index 2e4494f..d972e09 100644 --- a/Runtime/Extensions/Misc/TransformTweens.cs +++ b/Runtime/Extensions/Misc/TransformTweens.cs @@ -5,74 +5,60 @@ namespace Zigurous.Tweening public static class TransformTweens { public static Tween TweenPosition(this Transform transform, Vector3 to, float duration) => - Tweening.To(getter: () => transform.position, - setter: position => transform.position = position, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.position, (target, value) => target.position = value, to, duration) + .SetReference(transform); public static Tween TweenPositionX(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.position.x, - setter: x => transform.position = new Vector3(x, transform.position.y, transform.position.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.position.x, (target, value) => target.position = new Vector3(value, target.position.y, target.position.z), to, duration) + .SetReference(transform); public static Tween TweenPositionY(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.position.y, - setter: y => transform.position = new Vector3(transform.position.x, y, transform.position.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.position.y, (target, value) => target.position = new Vector3(target.position.x, value, target.position.z), to, duration) + .SetReference(transform); public static Tween TweenPositionZ(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.position.z, - setter: z => transform.position = new Vector3(transform.position.x, transform.position.y, z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.position.z, (target, value) => target.position = new Vector3(target.position.x, target.position.y, value), to, duration) + .SetReference(transform); public static Tween TweenLocalPosition(this Transform transform, Vector3 to, float duration) => - Tweening.To(getter: () => transform.localPosition, - setter: position => transform.localPosition = position, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localPosition, (target, value) => target.localPosition = value, to, duration) + .SetReference(transform); public static Tween TweenLocalPositionX(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localPosition.x, - setter: x => transform.localPosition = new Vector3(x, transform.localPosition.y, transform.localPosition.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localPosition.x, (target, value) => target.localPosition = new Vector3(value, target.localPosition.y, target.localPosition.z), to, duration) + .SetReference(transform); public static Tween TweenLocalPositionY(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localPosition.y, - setter: y => transform.localPosition = new Vector3(transform.localPosition.x, y, transform.localPosition.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localPosition.y, (target, value) => target.localPosition = new Vector3(target.localPosition.x, value, target.localPosition.z), to, duration) + .SetReference(transform); public static Tween TweenLocalPositionZ(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localPosition.z, - setter: z => transform.localPosition = new Vector3(transform.localPosition.x, transform.localPosition.y, z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localPosition.z, (target, value) => target.localPosition = new Vector3(target.localPosition.x, target.localPosition.y, value), to, duration) + .SetReference(transform); public static Tween TweenScale(this Transform transform, Vector3 to, float duration) => - Tweening.To(getter: () => transform.localScale, - setter: scale => transform.localScale = scale, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localScale, (target, value) => target.localScale = value, to, duration) + .SetReference(transform); public static Tween TweenScaleX(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localScale.x, - setter: x => transform.localScale = new Vector3(x, transform.localScale.y, transform.localScale.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localScale.x, (target, value) => target.localScale = new Vector3(value, target.localScale.y, target.localScale.z), to, duration) + .SetReference(transform); public static Tween TweenScaleY(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localScale.y, - setter: y => transform.localScale = new Vector3(transform.localScale.x, y, transform.localScale.z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localScale.y, (target, value) => target.localScale = new Vector3(target.localScale.x, value, target.localScale.z), to, duration) + .SetReference(transform); public static Tween TweenScaleZ(this Transform transform, float to, float duration) => - Tweening.To(getter: () => transform.localScale.z, - setter: z => transform.localScale = new Vector3(transform.localScale.x, transform.localScale.y, z), - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localScale.z, (target, value) => target.localScale = new Vector3(target.localScale.x, target.localScale.y, value), to, duration) + .SetReference(transform); public static Tween TweenRotation(this Transform transform, Quaternion to, float duration) => - Tweening.To(getter: () => transform.rotation, - setter: rotation => transform.rotation = rotation, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.rotation, (target, value) => target.rotation = value, to, duration) + .SetReference(transform); public static Tween TweenLocalRotation(this Transform transform, Quaternion to, float duration) => - Tweening.To(getter: () => transform.localRotation, - setter: rotation => transform.localRotation = rotation, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.localRotation, (target, value) => target.localRotation = value, to, duration) + .SetReference(transform); public static Tween TweenEulerAngles(this Transform transform, Vector3 to, float duration) => TweenRotation(transform, Quaternion.Euler(to), duration); @@ -97,7 +83,6 @@ public static Tween TweenLocalEulerAnglesY(this Transform transform, float to, f public static Tween TweenLocalEulerAnglesZ(this Transform transform, float to, float duration) => TweenLocalRotation(transform, Quaternion.Euler(transform.localEulerAngles.x, transform.localEulerAngles.y, to), duration); - } } diff --git a/Runtime/Extensions/Navigation/NavMeshAgentTweens.cs b/Runtime/Extensions/Navigation/NavMeshAgentTweens.cs index 57ea45f..0a5b210 100644 --- a/Runtime/Extensions/Navigation/NavMeshAgentTweens.cs +++ b/Runtime/Extensions/Navigation/NavMeshAgentTweens.cs @@ -6,55 +6,44 @@ namespace Zigurous.Tweening public static class NavMeshAgentTweens { public static Tween TweenSpeed(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.speed, - setter: speed => agent.speed = speed, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.speed, (target, value) => target.speed = value, to, duration) + .SetReference(agent); public static Tween TweenAngularSpeed(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.angularSpeed, - setter: angularSpeed => agent.angularSpeed = angularSpeed, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.angularSpeed, (target, value) => target.angularSpeed = value, to, duration) + .SetReference(agent); public static Tween TweenAcceleration(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.acceleration, - setter: acceleration => agent.acceleration = acceleration, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.acceleration, (target, value) => target.acceleration = value, to, duration) + .SetReference(agent); public static Tween TweenRadius(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.radius, - setter: radius => agent.radius = radius, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(agent); public static Tween TweenHeight(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.height, - setter: height => agent.height = height, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.height, (target, value) => target.height = value, to, duration) + .SetReference(agent); public static Tween TweenBaseOffset(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.baseOffset, - setter: baseOffset => agent.baseOffset = baseOffset, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.baseOffset, (target, value) => target.baseOffset = value, to, duration) + .SetReference(agent); public static Tween TweenNextPosition(this NavMeshAgent agent, Vector3 to, float duration) => - Tweening.To(getter: () => agent.nextPosition, - setter: nextPosition => agent.nextPosition = nextPosition, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.nextPosition, (target, value) => target.nextPosition = value, to, duration) + .SetReference(agent); public static Tween TweenDestination(this NavMeshAgent agent, Vector3 to, float duration) => - Tweening.To(getter: () => agent.destination, - setter: destination => agent.destination = destination, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.destination, (target, value) => target.destination = value, to, duration) + .SetReference(agent); public static Tween TweenVelocity(this NavMeshAgent agent, Vector3 to, float duration) => - Tweening.To(getter: () => agent.velocity, - setter: velocity => agent.velocity = velocity, - to, duration).SetTarget(agent); + Tweening.To(agent, (target) => target.velocity, (target, value) => target.velocity = value, to, duration) + .SetReference(agent); public static Tween TweenStoppingDistance(this NavMeshAgent agent, float to, float duration) => - Tweening.To(getter: () => agent.stoppingDistance, - setter: stoppingDistance => agent.stoppingDistance = stoppingDistance, - to, duration).SetTarget(agent); - + Tweening.To(agent, (target) => target.stoppingDistance, (target, value) => target.stoppingDistance = value, to, duration) + .SetReference(agent); } } diff --git a/Runtime/Extensions/Navigation/NavMeshObstacleTweens.cs b/Runtime/Extensions/Navigation/NavMeshObstacleTweens.cs index 01bf08b..eda74c2 100644 --- a/Runtime/Extensions/Navigation/NavMeshObstacleTweens.cs +++ b/Runtime/Extensions/Navigation/NavMeshObstacleTweens.cs @@ -6,30 +6,24 @@ namespace Zigurous.Tweening public static class NavMeshObstacleTweens { public static Tween TweenHeight(this NavMeshObstacle obstacle, float to, float duration) => - Tweening.To(getter: () => obstacle.height, - setter: height => obstacle.height = height, - to, duration).SetTarget(obstacle); + Tweening.To(obstacle, (target) => target.height, (target, value) => target.height = value, to, duration) + .SetReference(obstacle); public static Tween TweenRadius(this NavMeshObstacle obstacle, float to, float duration) => - Tweening.To(getter: () => obstacle.radius, - setter: radius => obstacle.radius = radius, - to, duration).SetTarget(obstacle); + Tweening.To(obstacle, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(obstacle); public static Tween TweenSize(this NavMeshObstacle obstacle, Vector3 to, float duration) => - Tweening.To(getter: () => obstacle.size, - setter: size => obstacle.size = size, - to, duration).SetTarget(obstacle); + Tweening.To(obstacle, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(obstacle); public static Tween TweenCenter(this NavMeshObstacle obstacle, Vector3 to, float duration) => - Tweening.To(getter: () => obstacle.center, - setter: center => obstacle.center = center, - to, duration).SetTarget(obstacle); + Tweening.To(obstacle, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(obstacle); public static Tween TweenVelocity(this NavMeshObstacle obstacle, Vector3 to, float duration) => - Tweening.To(getter: () => obstacle.velocity, - setter: velocity => obstacle.velocity = velocity, - to, duration).SetTarget(obstacle); - + Tweening.To(obstacle, (target) => target.velocity, (target, value) => target.velocity = value, to, duration) + .SetReference(obstacle); } } diff --git a/Runtime/Extensions/Physics/BoxColliderTweens.cs b/Runtime/Extensions/Physics/BoxColliderTweens.cs index 8fc0c47..80ed9e9 100644 --- a/Runtime/Extensions/Physics/BoxColliderTweens.cs +++ b/Runtime/Extensions/Physics/BoxColliderTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class BoxColliderTweens { public static Tween TweenCenter(this BoxCollider collider, Vector3 to, float duration) => - Tweening.To(getter: () => collider.center, - setter: center => collider.center = center, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(collider); public static Tween TweenSize(this BoxCollider collider, Vector3 to, float duration) => - Tweening.To(getter: () => collider.size, - setter: size => collider.size = size, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics/CapsuleColliderTweens.cs b/Runtime/Extensions/Physics/CapsuleColliderTweens.cs index ac96fdd..dfc2c5e 100644 --- a/Runtime/Extensions/Physics/CapsuleColliderTweens.cs +++ b/Runtime/Extensions/Physics/CapsuleColliderTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class CapsuleColliderTweens { public static Tween TweenCenter(this CapsuleCollider collider, Vector3 to, float duration) => - Tweening.To(getter: () => collider.center, - setter: center => collider.center = center, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(collider); public static Tween TweenRadius(this CapsuleCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.radius, - setter: radius => collider.radius = radius, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(collider); public static Tween TweenHeight(this CapsuleCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.height, - setter: height => collider.height = height, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.height, (target, value) => target.height = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics/CharacterControllerTweens.cs b/Runtime/Extensions/Physics/CharacterControllerTweens.cs index 32fcc15..f7c0f17 100644 --- a/Runtime/Extensions/Physics/CharacterControllerTweens.cs +++ b/Runtime/Extensions/Physics/CharacterControllerTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class CharacterControllerTweens { public static Tween TweenCenter(this CharacterController character, Vector3 to, float duration) => - Tweening.To(getter: () => character.center, - setter: center => character.center = center, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(character); public static Tween TweenRadius(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.radius, - setter: radius => character.radius = radius, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(character); public static Tween TweenHeight(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.height, - setter: height => character.height = height, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.height, (target, value) => target.height = value, to, duration) + .SetReference(character); public static Tween TweenSlopeLimit(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.slopeLimit, - setter: slopeLimit => character.slopeLimit = slopeLimit, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.slopeLimit, (target, value) => target.slopeLimit = value, to, duration) + .SetReference(character); public static Tween TweenStepOffset(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.stepOffset, - setter: stepOffset => character.stepOffset = stepOffset, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.stepOffset, (target, value) => target.stepOffset = value, to, duration) + .SetReference(character); public static Tween TweenSkinWidth(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.skinWidth, - setter: skinWidth => character.skinWidth = skinWidth, - to, duration).SetTarget(character); + Tweening.To(character, (target) => target.skinWidth, (target, value) => target.skinWidth = value, to, duration) + .SetReference(character); public static Tween TweenMinMoveDistance(this CharacterController character, float to, float duration) => - Tweening.To(getter: () => character.minMoveDistance, - setter: minMoveDistance => character.minMoveDistance = minMoveDistance, - to, duration).SetTarget(character); - + Tweening.To(character, (target) => target.minMoveDistance, (target, value) => target.minMoveDistance = value, to, duration) + .SetReference(character); } } diff --git a/Runtime/Extensions/Physics/CharacterJointTweens.cs b/Runtime/Extensions/Physics/CharacterJointTweens.cs index 953abf1..9af319e 100644 --- a/Runtime/Extensions/Physics/CharacterJointTweens.cs +++ b/Runtime/Extensions/Physics/CharacterJointTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class CharacterJointTweens { public static Tween TweenSwingAxis(this CharacterJoint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.swingAxis, - setter: swingAxis => joint.swingAxis = swingAxis, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.swingAxis, (target, value) => target.swingAxis = value, to, duration) + .SetReference(joint); public static Tween TweenProjectionDistance(this CharacterJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.projectionDistance, - setter: projectionDistance => joint.projectionDistance = projectionDistance, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.projectionDistance, (target, value) => target.projectionDistance = value, to, duration) + .SetReference(joint); public static Tween TweenProjectionAngle(this CharacterJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.projectionAngle, - setter: projectionAngle => joint.projectionAngle = projectionAngle, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.projectionAngle, (target, value) => target.projectionAngle = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics/ClothTweens.cs b/Runtime/Extensions/Physics/ClothTweens.cs index 07d0f77..28150dd 100644 --- a/Runtime/Extensions/Physics/ClothTweens.cs +++ b/Runtime/Extensions/Physics/ClothTweens.cs @@ -5,70 +5,56 @@ namespace Zigurous.Tweening public static class ClothTweens { public static Tween TweenDamping(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.damping, - setter: damping => cloth.damping = damping, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.damping, (target, value) => target.damping = value, to, duration) + .SetReference(cloth); public static Tween TweenFriction(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.friction, - setter: friction => cloth.friction = friction, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.friction, (target, value) => target.friction = value, to, duration) + .SetReference(cloth); public static Tween TweenCollisionMassScale(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.collisionMassScale, - setter: collisionMassScale => cloth.collisionMassScale = collisionMassScale, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.collisionMassScale, (target, value) => target.collisionMassScale = value, to, duration) + .SetReference(cloth); public static Tween TweenWorldVelocityScale(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.worldVelocityScale, - setter: worldVelocityScale => cloth.worldVelocityScale = worldVelocityScale, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.worldVelocityScale, (target, value) => target.worldVelocityScale = value, to, duration) + .SetReference(cloth); public static Tween TweenWorldAccelerationScale(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.worldAccelerationScale, - setter: worldAccelerationScale => cloth.worldAccelerationScale = worldAccelerationScale, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.worldAccelerationScale, (target, value) => target.worldAccelerationScale = value, to, duration) + .SetReference(cloth); public static Tween TweenExternalAcceleration(this Cloth cloth, Vector3 to, float duration) => - Tweening.To(getter: () => cloth.externalAcceleration, - setter: externalAcceleration => cloth.externalAcceleration = externalAcceleration, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.externalAcceleration, (target, value) => target.externalAcceleration = value, to, duration) + .SetReference(cloth); public static Tween TweenRandomAcceleration(this Cloth cloth, Vector3 to, float duration) => - Tweening.To(getter: () => cloth.randomAcceleration, - setter: randomAcceleration => cloth.randomAcceleration = randomAcceleration, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.randomAcceleration, (target, value) => target.randomAcceleration = value, to, duration) + .SetReference(cloth); public static Tween TweenStiffnessFrequency(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.stiffnessFrequency, - setter: stiffnessFrequency => cloth.stiffnessFrequency = stiffnessFrequency, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.stiffnessFrequency, (target, value) => target.stiffnessFrequency = value, to, duration) + .SetReference(cloth); public static Tween TweenSelfCollisionDistance(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.selfCollisionDistance, - setter: selfCollisionDistance => cloth.selfCollisionDistance = selfCollisionDistance, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.selfCollisionDistance, (target, value) => target.selfCollisionDistance = value, to, duration) + .SetReference(cloth); public static Tween TweenSelfCollisionStiffness(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.selfCollisionStiffness, - setter: selfCollisionStiffness => cloth.selfCollisionStiffness = selfCollisionStiffness, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.selfCollisionStiffness, (target, value) => target.selfCollisionStiffness = value, to, duration) + .SetReference(cloth); public static Tween TweenStretchingStiffness(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.stretchingStiffness, - setter: stretchingStiffness => cloth.stretchingStiffness = stretchingStiffness, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.stretchingStiffness, (target, value) => target.stretchingStiffness = value, to, duration) + .SetReference(cloth); public static Tween TweenBendingStiffness(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.bendingStiffness, - setter: bendingStiffness => cloth.bendingStiffness = bendingStiffness, - to, duration).SetTarget(cloth); + Tweening.To(cloth, (target) => target.bendingStiffness, (target, value) => target.bendingStiffness = value, to, duration) + .SetReference(cloth); public static Tween TweenSleepThreshold(this Cloth cloth, float to, float duration) => - Tweening.To(getter: () => cloth.sleepThreshold, - setter: sleepThreshold => cloth.sleepThreshold = sleepThreshold, - to, duration).SetTarget(cloth); - + Tweening.To(cloth, (target) => target.sleepThreshold, (target, value) => target.sleepThreshold = value, to, duration) + .SetReference(cloth); } } diff --git a/Runtime/Extensions/Physics/ColliderTweens.cs b/Runtime/Extensions/Physics/ColliderTweens.cs index 8d7f992..342710a 100644 --- a/Runtime/Extensions/Physics/ColliderTweens.cs +++ b/Runtime/Extensions/Physics/ColliderTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class ColliderTweens { public static Tween TweenContactOffset(this Collider collider, float to, float duration) => - Tweening.To(getter: () => collider.contactOffset, - setter: contactOffset => collider.contactOffset = contactOffset, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.contactOffset, (target, value) => target.contactOffset = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics/ConfigurableJointTweens.cs b/Runtime/Extensions/Physics/ConfigurableJointTweens.cs index 7946a8e..d2048a6 100644 --- a/Runtime/Extensions/Physics/ConfigurableJointTweens.cs +++ b/Runtime/Extensions/Physics/ConfigurableJointTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class ConfigurableJointTweens { public static Tween TweenProjectionAngle(this ConfigurableJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.projectionAngle, - setter: projectionAngle => joint.projectionAngle = projectionAngle, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.projectionAngle, (target, value) => target.projectionAngle = value, to, duration) + .SetReference(joint); public static Tween TweenProjectionDistance(this ConfigurableJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.projectionDistance, - setter: projectionDistance => joint.projectionDistance = projectionDistance, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.projectionDistance, (target, value) => target.projectionDistance = value, to, duration) + .SetReference(joint); public static Tween TweenTargetVelocity(this ConfigurableJoint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.targetVelocity, - setter: targetVelocity => joint.targetVelocity = targetVelocity, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.targetVelocity, (target, value) => target.targetVelocity = value, to, duration) + .SetReference(joint); public static Tween TweenTargetAngularVelocity(this ConfigurableJoint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.targetAngularVelocity, - setter: targetAngularVelocity => joint.targetAngularVelocity = targetAngularVelocity, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.targetAngularVelocity, (target, value) => target.targetAngularVelocity = value, to, duration) + .SetReference(joint); public static Tween TweenTargetPosition(this ConfigurableJoint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.targetPosition, - setter: targetPosition => joint.targetPosition = targetPosition, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.targetPosition, (target, value) => target.targetPosition = value, to, duration) + .SetReference(joint); public static Tween TweenTargetRotation(this ConfigurableJoint joint, Quaternion to, float duration) => - Tweening.To(getter: () => joint.targetRotation, - setter: targetRotation => joint.targetRotation = targetRotation, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.targetRotation, (target, value) => target.targetRotation = value, to, duration) + .SetReference(joint); public static Tween TweenSecondaryAxis(this ConfigurableJoint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.secondaryAxis, - setter: secondaryAxis => joint.secondaryAxis = secondaryAxis, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.secondaryAxis, (target, value) => target.secondaryAxis = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics/ConstantForceTweens.cs b/Runtime/Extensions/Physics/ConstantForceTweens.cs index 16a75ce..0649579 100644 --- a/Runtime/Extensions/Physics/ConstantForceTweens.cs +++ b/Runtime/Extensions/Physics/ConstantForceTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class ConstantForceTweens { public static Tween TweenForce(this ConstantForce constantForce, Vector3 to, float duration) => - Tweening.To(getter: () => constantForce.force, - setter: force => constantForce.force = force, - to, duration).SetTarget(constantForce); + Tweening.To(constantForce, (target) => target.force, (target, value) => target.force = value, to, duration) + .SetReference(constantForce); public static Tween TweenRelativeForce(this ConstantForce constantForce, Vector3 to, float duration) => - Tweening.To(getter: () => constantForce.relativeForce, - setter: relativeForce => constantForce.relativeForce = relativeForce, - to, duration).SetTarget(constantForce); + Tweening.To(constantForce, (target) => target.relativeForce, (target, value) => target.relativeForce = value, to, duration) + .SetReference(constantForce); public static Tween TweenTorque(this ConstantForce constantForce, Vector3 to, float duration) => - Tweening.To(getter: () => constantForce.torque, - setter: torque => constantForce.torque = torque, - to, duration).SetTarget(constantForce); + Tweening.To(constantForce, (target) => target.torque, (target, value) => target.torque = value, to, duration) + .SetReference(constantForce); public static Tween TweenRelativeTorque(this ConstantForce constantForce, Vector3 to, float duration) => - Tweening.To(getter: () => constantForce.relativeTorque, - setter: relativeTorque => constantForce.relativeTorque = relativeTorque, - to, duration).SetTarget(constantForce); - + Tweening.To(constantForce, (target) => target.relativeTorque, (target, value) => target.relativeTorque = value, to, duration) + .SetReference(constantForce); } } diff --git a/Runtime/Extensions/Physics/JointTweens.cs b/Runtime/Extensions/Physics/JointTweens.cs index 234bc61..52e49d4 100644 --- a/Runtime/Extensions/Physics/JointTweens.cs +++ b/Runtime/Extensions/Physics/JointTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class JointTweens { public static Tween TweenAxis(this Joint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.axis, - setter: axis => joint.axis = axis, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.axis, (target, value) => target.axis = value, to, duration) + .SetReference(joint); public static Tween TweenAnchor(this Joint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.anchor, - setter: anchor => joint.anchor = anchor, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.anchor, (target, value) => target.anchor = value, to, duration) + .SetReference(joint); public static Tween TweenConnectedAnchor(this Joint joint, Vector3 to, float duration) => - Tweening.To(getter: () => joint.connectedAnchor, - setter: connectedAnchor => joint.connectedAnchor = connectedAnchor, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.connectedAnchor, (target, value) => target.connectedAnchor = value, to, duration) + .SetReference(joint); public static Tween TweenBreakForce(this Joint joint, float to, float duration) => - Tweening.To(getter: () => joint.breakForce, - setter: breakForce => joint.breakForce = breakForce, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.breakForce, (target, value) => target.breakForce = value, to, duration) + .SetReference(joint); public static Tween TweenBreakTorque(this Joint joint, float to, float duration) => - Tweening.To(getter: () => joint.breakTorque, - setter: breakTorque => joint.breakTorque = breakTorque, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.breakTorque, (target, value) => target.breakTorque = value, to, duration) + .SetReference(joint); public static Tween TweenMassScale(this Joint joint, float to, float duration) => - Tweening.To(getter: () => joint.massScale, - setter: massScale => joint.massScale = massScale, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.massScale, (target, value) => target.massScale = value, to, duration) + .SetReference(joint); public static Tween TweenConnectedMassScale(this Joint joint, float to, float duration) => - Tweening.To(getter: () => joint.connectedMassScale, - setter: connectedMassScale => joint.connectedMassScale = connectedMassScale, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.connectedMassScale, (target, value) => target.connectedMassScale = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics/PhysicMaterialTweens.cs b/Runtime/Extensions/Physics/PhysicMaterialTweens.cs index f6c35f9..029f98b 100644 --- a/Runtime/Extensions/Physics/PhysicMaterialTweens.cs +++ b/Runtime/Extensions/Physics/PhysicMaterialTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class PhysicMaterialTweens { public static Tween TweenBounciness(this PhysicMaterial material, float to, float duration) => - Tweening.To(getter: () => material.bounciness, - setter: bounciness => material.bounciness = bounciness, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.bounciness, (target, value) => target.bounciness = value, to, duration) + .SetReference(material); public static Tween TweenDynamicFriction(this PhysicMaterial material, float to, float duration) => - Tweening.To(getter: () => material.dynamicFriction, - setter: friction => material.dynamicFriction = friction, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.dynamicFriction, (target, value) => target.dynamicFriction = value, to, duration) + .SetReference(material); public static Tween TweenStaticFriction(this PhysicMaterial material, float to, float duration) => - Tweening.To(getter: () => material.staticFriction, - setter: friction => material.staticFriction = friction, - to, duration).SetId(material.GetHashCode()); - + Tweening.To(material, (target) => target.staticFriction, (target, value) => target.staticFriction = value, to, duration) + .SetReference(material); } } diff --git a/Runtime/Extensions/Physics/RigidbodyTweens.cs b/Runtime/Extensions/Physics/RigidbodyTweens.cs index 4f50321..33ab18f 100644 --- a/Runtime/Extensions/Physics/RigidbodyTweens.cs +++ b/Runtime/Extensions/Physics/RigidbodyTweens.cs @@ -5,70 +5,56 @@ namespace Zigurous.Tweening public static class RigidbodyTweens { public static Tween TweenPosition(this Rigidbody rigidbody, Vector3 to, float duration) => - Tweening.To(getter: () => rigidbody.position, - setter: position => rigidbody.position = position, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.position, (target, value) => target.position = value, to, duration) + .SetReference(rigidbody); public static Tween TweenRotation(this Rigidbody rigidbody, Quaternion to, float duration) => - Tweening.To(getter: () => rigidbody.rotation, - setter: rotation => rigidbody.rotation = rotation, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.rotation, (target, value) => target.rotation = value, to, duration) + .SetReference(rigidbody); public static Tween TweenVelocity(this Rigidbody rigidbody, Vector3 to, float duration) => - Tweening.To(getter: () => rigidbody.velocity, - setter: velocity => rigidbody.velocity = velocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.velocity, (target, value) => target.velocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenAngularVelocity(this Rigidbody rigidbody, Vector3 to, float duration) => - Tweening.To(getter: () => rigidbody.angularVelocity, - setter: angularVelocity => rigidbody.angularVelocity = angularVelocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.angularVelocity, (target, value) => target.angularVelocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenMaxAngularVelocity(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.maxAngularVelocity, - setter: maxAngularVelocity => rigidbody.maxAngularVelocity = maxAngularVelocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.maxAngularVelocity, (target, value) => target.maxAngularVelocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenMaxDepenetrationVelocity(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.maxDepenetrationVelocity, - setter: maxDepenetrationVelocity => rigidbody.maxDepenetrationVelocity = maxDepenetrationVelocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.maxDepenetrationVelocity, (target, value) => target.maxDepenetrationVelocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenMass(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.mass, - setter: mass => rigidbody.mass = mass, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.mass, (target, value) => target.mass = value, to, duration) + .SetReference(rigidbody); public static Tween TweenCenterOfMass(this Rigidbody rigidbody, Vector3 to, float duration) => - Tweening.To(getter: () => rigidbody.centerOfMass, - setter: centerOfMass => rigidbody.centerOfMass = centerOfMass, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.centerOfMass, (target, value) => target.centerOfMass = value, to, duration) + .SetReference(rigidbody); public static Tween TweenDrag(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.drag, - setter: drag => rigidbody.drag = drag, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.drag, (target, value) => target.drag = value, to, duration) + .SetReference(rigidbody); public static Tween TweenAngularDrag(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.angularDrag, - setter: angularDrag => rigidbody.angularDrag = angularDrag, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.angularDrag, (target, value) => target.angularDrag = value, to, duration) + .SetReference(rigidbody); public static Tween TweenInertiaTensor(this Rigidbody rigidbody, Vector3 to, float duration) => - Tweening.To(getter: () => rigidbody.inertiaTensor, - setter: inertiaTensor => rigidbody.inertiaTensor = inertiaTensor, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.inertiaTensor, (target, value) => target.inertiaTensor = value, to, duration) + .SetReference(rigidbody); public static Tween TweenInertiaTensorRotation(this Rigidbody rigidbody, Quaternion to, float duration) => - Tweening.To(getter: () => rigidbody.inertiaTensorRotation, - setter: inertiaTensorRotation => rigidbody.inertiaTensorRotation = inertiaTensorRotation, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.inertiaTensorRotation, (target, value) => target.inertiaTensorRotation = value, to, duration) + .SetReference(rigidbody); public static Tween TweenSleepThreshold(this Rigidbody rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.sleepThreshold, - setter: sleepThreshold => rigidbody.sleepThreshold = sleepThreshold, - to, duration).SetTarget(rigidbody); - + Tweening.To(rigidbody, (target) => target.sleepThreshold, (target, value) => target.sleepThreshold = value, to, duration) + .SetReference(rigidbody); } } diff --git a/Runtime/Extensions/Physics/SphereColliderTweens.cs b/Runtime/Extensions/Physics/SphereColliderTweens.cs index 892b6d9..50f67cb 100644 --- a/Runtime/Extensions/Physics/SphereColliderTweens.cs +++ b/Runtime/Extensions/Physics/SphereColliderTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class SphereColliderTweens { public static Tween TweenCenter(this SphereCollider collider, Vector3 to, float duration) => - Tweening.To(getter: () => collider.center, - setter: center => collider.center = center, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(collider); public static Tween TweenRadius(this SphereCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.radius, - setter: radius => collider.radius = radius, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics/SpringJointTweens.cs b/Runtime/Extensions/Physics/SpringJointTweens.cs index da2b2aa..daffdb6 100644 --- a/Runtime/Extensions/Physics/SpringJointTweens.cs +++ b/Runtime/Extensions/Physics/SpringJointTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class SpringJointTweens { public static Tween TweenSpring(this SpringJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.spring, - setter: spring => joint.spring = spring, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.spring, (target, value) => target.spring = value, to, duration) + .SetReference(joint); public static Tween TweenDamper(this SpringJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.damper, - setter: damper => joint.damper = damper, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.damper, (target, value) => target.damper = value, to, duration) + .SetReference(joint); public static Tween TweenMinDistance(this SpringJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.minDistance, - setter: minDistance => joint.minDistance = minDistance, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.minDistance, (target, value) => target.minDistance = value, to, duration) + .SetReference(joint); public static Tween TweenMaxDistance(this SpringJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.maxDistance, - setter: maxDistance => joint.maxDistance = maxDistance, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.maxDistance, (target, value) => target.maxDistance = value, to, duration) + .SetReference(joint); public static Tween TweenTolerance(this SpringJoint joint, float to, float duration) => - Tweening.To(getter: () => joint.tolerance, - setter: tolerance => joint.tolerance = tolerance, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.tolerance, (target, value) => target.tolerance = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics/WheelColliderTweens.cs b/Runtime/Extensions/Physics/WheelColliderTweens.cs index f1bbc36..b58d8ee 100644 --- a/Runtime/Extensions/Physics/WheelColliderTweens.cs +++ b/Runtime/Extensions/Physics/WheelColliderTweens.cs @@ -5,55 +5,44 @@ namespace Zigurous.Tweening public static class WheelColliderTweens { public static Tween TweenForceAppPointDistance(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.forceAppPointDistance, - setter: forceAppPointDistance => collider.forceAppPointDistance = forceAppPointDistance, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.forceAppPointDistance, (target, value) => target.forceAppPointDistance = value, to, duration) + .SetReference(collider); public static Tween TweenSteerAngle(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.steerAngle, - setter: steerAngle => collider.steerAngle = steerAngle, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.steerAngle, (target, value) => target.steerAngle = value, to, duration) + .SetReference(collider); public static Tween TweenBreakTorque(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.brakeTorque, - setter: brakeTorque => collider.brakeTorque = brakeTorque, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.brakeTorque, (target, value) => target.brakeTorque = value, to, duration) + .SetReference(collider); public static Tween TweenMotorTorque(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.motorTorque, - setter: motorTorque => collider.motorTorque = motorTorque, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.motorTorque, (target, value) => target.motorTorque = value, to, duration) + .SetReference(collider); public static Tween TweenWheelDampingRate(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.wheelDampingRate, - setter: wheelDampingRate => collider.wheelDampingRate = wheelDampingRate, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.wheelDampingRate, (target, value) => target.wheelDampingRate = value, to, duration) + .SetReference(collider); public static Tween TweenMass(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.mass, - setter: mass => collider.mass = mass, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.mass, (target, value) => target.mass = value, to, duration) + .SetReference(collider); public static Tween TweenSprungMass(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.sprungMass, - setter: sprungMass => collider.sprungMass = sprungMass, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.sprungMass, (target, value) => target.sprungMass = value, to, duration) + .SetReference(collider); public static Tween TweenSuspensionDistance(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.suspensionDistance, - setter: suspensionDistance => collider.suspensionDistance = suspensionDistance, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.suspensionDistance, (target, value) => target.suspensionDistance = value, to, duration) + .SetReference(collider); public static Tween TweenRadius(this WheelCollider collider, float to, float duration) => - Tweening.To(getter: () => collider.radius, - setter: radius => collider.radius = radius, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(collider); public static Tween TweenCenter(this WheelCollider collider, Vector3 to, float duration) => - Tweening.To(getter: () => collider.center, - setter: center => collider.center = center, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/AnchoredJoint2DTweens.cs b/Runtime/Extensions/Physics2D/AnchoredJoint2DTweens.cs index 17ce1ef..78abb01 100644 --- a/Runtime/Extensions/Physics2D/AnchoredJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/AnchoredJoint2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class AnchoredJoint2DTweens { public static Tween TweenAnchor(this AnchoredJoint2D joint, Vector2 to, float duration) => - Tweening.To(getter: () => joint.anchor, - setter: anchor => joint.anchor = anchor, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.anchor, (target, value) => target.anchor = value, to, duration) + .SetReference(joint); public static Tween TweenConnectedAnchor(this AnchoredJoint2D joint, Vector2 to, float duration) => - Tweening.To(getter: () => joint.connectedAnchor, - setter: connectedAnchor => joint.connectedAnchor = connectedAnchor, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.connectedAnchor, (target, value) => target.connectedAnchor = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/AreaEffector2DTweens.cs b/Runtime/Extensions/Physics2D/AreaEffector2DTweens.cs index a31534b..1895109 100644 --- a/Runtime/Extensions/Physics2D/AreaEffector2DTweens.cs +++ b/Runtime/Extensions/Physics2D/AreaEffector2DTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class AreaEffector2DTweens { public static Tween TweenForceAngle(this AreaEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceAngle, - setter: forceAngle => effector.forceAngle = forceAngle, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.forceAngle, (target, value) => target.forceAngle = value, to, duration) + .SetReference(effector); public static Tween TweenForceMagnitude(this AreaEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceMagnitude, - setter: forceMagnitude => effector.forceMagnitude = forceMagnitude, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.forceMagnitude, (target, value) => target.forceMagnitude = value, to, duration) + .SetReference(effector); public static Tween TweenForceVariation(this AreaEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceVariation, - setter: forceVariation => effector.forceVariation = forceVariation, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.forceVariation, (target, value) => target.forceVariation = value, to, duration) + .SetReference(effector); public static Tween TweenDrag(this AreaEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.drag, - setter: drag => effector.drag = drag, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.drag, (target, value) => target.drag = value, to, duration) + .SetReference(effector); public static Tween TweenAngularDrag(this AreaEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.angularDrag, - setter: angularDrag => effector.angularDrag = angularDrag, - to, duration).SetTarget(effector); - + Tweening.To(effector, (target) => target.angularDrag, (target, value) => target.angularDrag = value, to, duration) + .SetReference(effector); } } diff --git a/Runtime/Extensions/Physics2D/BoxCollider2DTweens.cs b/Runtime/Extensions/Physics2D/BoxCollider2DTweens.cs index 4eeffdf..93173ad 100644 --- a/Runtime/Extensions/Physics2D/BoxCollider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/BoxCollider2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class BoxCollider2DTweens { public static Tween TweenSize(this BoxCollider2D collider, Vector2 to, float duration) => - Tweening.To(getter: () => collider.size, - setter: size => collider.size = size, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(collider); public static Tween TweenEdgeRadius(this BoxCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.edgeRadius, - setter: edgeRadius => collider.edgeRadius = edgeRadius, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.edgeRadius, (target, value) => target.edgeRadius = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/BuoyancyEffector2DTweens.cs b/Runtime/Extensions/Physics2D/BuoyancyEffector2DTweens.cs index f76cc90..52a2a52 100644 --- a/Runtime/Extensions/Physics2D/BuoyancyEffector2DTweens.cs +++ b/Runtime/Extensions/Physics2D/BuoyancyEffector2DTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class BuoyancyEffector2DTweens { public static Tween TweenSurfaceLevel(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.surfaceLevel, - setter: surfaceLevel => effector.surfaceLevel = surfaceLevel, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.surfaceLevel, (target, value) => target.surfaceLevel = value, to, duration) + .SetReference(effector); public static Tween TweenDensity(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.density, - setter: density => effector.density = density, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.density, (target, value) => target.density = value, to, duration) + .SetReference(effector); public static Tween TweenLinearDrag(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.linearDrag, - setter: linearDrag => effector.linearDrag = linearDrag, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.linearDrag, (target, value) => target.linearDrag = value, to, duration) + .SetReference(effector); public static Tween TweenAngularDrag(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.angularDrag, - setter: angularDrag => effector.angularDrag = angularDrag, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.angularDrag, (target, value) => target.angularDrag = value, to, duration) + .SetReference(effector); public static Tween TweenFlowAngle(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.flowAngle, - setter: flowAngle => effector.flowAngle = flowAngle, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.flowAngle, (target, value) => target.flowAngle = value, to, duration) + .SetReference(effector); public static Tween TweenFlowMagnitude(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.flowMagnitude, - setter: flowMagnitude => effector.flowMagnitude = flowMagnitude, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.flowMagnitude, (target, value) => target.flowMagnitude = value, to, duration) + .SetReference(effector); public static Tween TweenFlowVariation(this BuoyancyEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.flowVariation, - setter: flowVariation => effector.flowVariation = flowVariation, - to, duration).SetTarget(effector); - + Tweening.To(effector, (target) => target.flowVariation, (target, value) => target.flowVariation = value, to, duration) + .SetReference(effector); } } diff --git a/Runtime/Extensions/Physics2D/CapsuleCollider2DTweens.cs b/Runtime/Extensions/Physics2D/CapsuleCollider2DTweens.cs index 4e18f3a..caea7b4 100644 --- a/Runtime/Extensions/Physics2D/CapsuleCollider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/CapsuleCollider2DTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class CapsuleCollider2DTweens { public static Tween TweenSize(this CapsuleCollider2D collider, Vector2 to, float duration) => - Tweening.To(getter: () => collider.size, - setter: size => collider.size = size, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/CircleCollider2DTweens.cs b/Runtime/Extensions/Physics2D/CircleCollider2DTweens.cs index 517c10c..97f5cec 100644 --- a/Runtime/Extensions/Physics2D/CircleCollider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/CircleCollider2DTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class CircleCollider2DTweens { public static Tween TweenRadius(this CircleCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.radius, - setter: radius => collider.radius = radius, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/Collider2DTweens.cs b/Runtime/Extensions/Physics2D/Collider2DTweens.cs index 3a60d2f..3a33849 100644 --- a/Runtime/Extensions/Physics2D/Collider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/Collider2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class Collider2DTweens { public static Tween TweenDensity(this Collider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.density, - setter: density => collider.density = density, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.density, (target, value) => target.density = value, to, duration) + .SetReference(collider); public static Tween TweenOffset(this Collider2D collider, Vector2 to, float duration) => - Tweening.To(getter: () => collider.offset, - setter: offset => collider.offset = offset, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.offset, (target, value) => target.offset = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/CompositeCollider2DTweens.cs b/Runtime/Extensions/Physics2D/CompositeCollider2DTweens.cs index 23bc50c..3a3e22d 100644 --- a/Runtime/Extensions/Physics2D/CompositeCollider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/CompositeCollider2DTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class CompositeCollider2DTweens { public static Tween TweenVertexDistance(this CompositeCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.vertexDistance, - setter: vertexDistance => collider.vertexDistance = vertexDistance, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.vertexDistance, (target, value) => target.vertexDistance = value, to, duration) + .SetReference(collider); public static Tween TweenEdgeRadius(this CompositeCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.edgeRadius, - setter: edgeRadius => collider.edgeRadius = edgeRadius, - to, duration).SetTarget(collider); + Tweening.To(collider, (target) => target.edgeRadius, (target, value) => target.edgeRadius = value, to, duration) + .SetReference(collider); public static Tween TweenOffsetDistance(this CompositeCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.offsetDistance, - setter: offsetDistance => collider.offsetDistance = offsetDistance, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.offsetDistance, (target, value) => target.offsetDistance = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/ConstantForce2DTweens.cs b/Runtime/Extensions/Physics2D/ConstantForce2DTweens.cs index 6f0218b..153307b 100644 --- a/Runtime/Extensions/Physics2D/ConstantForce2DTweens.cs +++ b/Runtime/Extensions/Physics2D/ConstantForce2DTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class ConstantForce2DTweens { public static Tween TweenForce(this ConstantForce2D constantForce, Vector2 to, float duration) => - Tweening.To(getter: () => constantForce.force, - setter: force => constantForce.force = force, - to, duration).SetTarget(constantForce); + Tweening.To(constantForce, (target) => target.force, (target, value) => target.force = value, to, duration) + .SetReference(constantForce); public static Tween TweenRelativeForce(this ConstantForce2D constantForce, Vector2 to, float duration) => - Tweening.To(getter: () => constantForce.relativeForce, - setter: relativeForce => constantForce.relativeForce = relativeForce, - to, duration).SetTarget(constantForce); + Tweening.To(constantForce, (target) => target.relativeForce, (target, value) => target.relativeForce = value, to, duration) + .SetReference(constantForce); public static Tween TweenTorque(this ConstantForce2D constantForce, float to, float duration) => - Tweening.To(getter: () => constantForce.torque, - setter: torque => constantForce.torque = torque, - to, duration).SetTarget(constantForce); - + Tweening.To(constantForce, (target) => target.torque, (target, value) => target.torque = value, to, duration) + .SetReference(constantForce); } } diff --git a/Runtime/Extensions/Physics2D/DistanceJoint2DTweens.cs b/Runtime/Extensions/Physics2D/DistanceJoint2DTweens.cs index 617b7c0..02f3f5a 100644 --- a/Runtime/Extensions/Physics2D/DistanceJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/DistanceJoint2DTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class DistanceJoint2DTweens { public static Tween TweenDistance(this DistanceJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.distance, - setter: distance => joint.distance = distance, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.distance, (target, value) => target.distance = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/EdgeCollider2DTweens.cs b/Runtime/Extensions/Physics2D/EdgeCollider2DTweens.cs index 1ae0134..5807d0e 100644 --- a/Runtime/Extensions/Physics2D/EdgeCollider2DTweens.cs +++ b/Runtime/Extensions/Physics2D/EdgeCollider2DTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class EdgeCollider2DTweens { public static Tween TweenEdgeRadius(this EdgeCollider2D collider, float to, float duration) => - Tweening.To(getter: () => collider.edgeRadius, - setter: edgeRadius => collider.edgeRadius = edgeRadius, - to, duration).SetTarget(collider); - + Tweening.To(collider, (target) => target.edgeRadius, (target, value) => target.edgeRadius = value, to, duration) + .SetReference(collider); } } diff --git a/Runtime/Extensions/Physics2D/FixedJoint2DTweens.cs b/Runtime/Extensions/Physics2D/FixedJoint2DTweens.cs index a6af2f7..a9f574c 100644 --- a/Runtime/Extensions/Physics2D/FixedJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/FixedJoint2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class FixedJoint2DTweens { public static Tween TweenDampingRatio(this FixedJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.dampingRatio, - setter: dampingRatio => joint.dampingRatio = dampingRatio, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.dampingRatio, (target, value) => target.dampingRatio = value, to, duration) + .SetReference(joint); public static Tween TweenFrequency(this FixedJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.frequency, - setter: frequency => joint.frequency = frequency, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.frequency, (target, value) => target.frequency = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/FrictionJoint2DTweens.cs b/Runtime/Extensions/Physics2D/FrictionJoint2DTweens.cs index ff0cfe4..e93c3dc 100644 --- a/Runtime/Extensions/Physics2D/FrictionJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/FrictionJoint2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class FrictionJoint2DTweens { public static Tween TweenMaxForce(this FrictionJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.maxForce, - setter: maxForce => joint.maxForce = maxForce, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.maxForce, (target, value) => target.maxForce = value, to, duration) + .SetReference(joint); public static Tween TweenMaxTorque(this FrictionJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.maxTorque, - setter: maxTorque => joint.maxTorque = maxTorque, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.maxTorque, (target, value) => target.maxTorque = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/Joint2DTweens.cs b/Runtime/Extensions/Physics2D/Joint2DTweens.cs index a5b9bde..3e1163c 100644 --- a/Runtime/Extensions/Physics2D/Joint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/Joint2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class Joint2DTweens { public static Tween TweenBreakForce(this Joint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.breakForce, - setter: breakForce => joint.breakForce = breakForce, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.breakForce, (target, value) => target.breakForce = value, to, duration) + .SetReference(joint); public static Tween TweenBreakTorque(this Joint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.breakTorque, - setter: breakTorque => joint.breakTorque = breakTorque, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.breakTorque, (target, value) => target.breakTorque = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/PhysicsMaterial2DTweens.cs b/Runtime/Extensions/Physics2D/PhysicsMaterial2DTweens.cs index 67eb9c2..1ada992 100644 --- a/Runtime/Extensions/Physics2D/PhysicsMaterial2DTweens.cs +++ b/Runtime/Extensions/Physics2D/PhysicsMaterial2DTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class PhysicsMaterial2DTweens { public static Tween TweenBounciness(this PhysicsMaterial2D material, float to, float duration) => - Tweening.To(getter: () => material.bounciness, - setter: bounciness => material.bounciness = bounciness, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.bounciness, (target, value) => target.bounciness = value, to, duration) + .SetReference(material); public static Tween TweenFriction(this PhysicsMaterial2D material, float to, float duration) => - Tweening.To(getter: () => material.friction, - setter: friction => material.friction = friction, - to, duration).SetId(material.GetHashCode()); - + Tweening.To(material, (target) => target.friction, (target, value) => target.friction = value, to, duration) + .SetReference(material); } } diff --git a/Runtime/Extensions/Physics2D/PlatformEffector2DTweens.cs b/Runtime/Extensions/Physics2D/PlatformEffector2DTweens.cs index 2072133..46fe396 100644 --- a/Runtime/Extensions/Physics2D/PlatformEffector2DTweens.cs +++ b/Runtime/Extensions/Physics2D/PlatformEffector2DTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class PlatformEffector2DTweens { public static Tween TweenSurfaceArc(this PlatformEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.surfaceArc, - setter: surfaceArc => effector.surfaceArc = surfaceArc, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.surfaceArc, (target, value) => target.surfaceArc = value, to, duration) + .SetReference(effector); public static Tween TweenSideArc(this PlatformEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.sideArc, - setter: sideArc => effector.sideArc = sideArc, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.sideArc, (target, value) => target.sideArc = value, to, duration) + .SetReference(effector); public static Tween TweenRotationalOffset(this PlatformEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.rotationalOffset, - setter: rotationalOffset => effector.rotationalOffset = rotationalOffset, - to, duration).SetTarget(effector); - + Tweening.To(effector, (target) => target.rotationalOffset, (target, value) => target.rotationalOffset = value, to, duration) + .SetReference(effector); } } diff --git a/Runtime/Extensions/Physics2D/PointEffector2DTweens.cs b/Runtime/Extensions/Physics2D/PointEffector2DTweens.cs index 6a8a9aa..d5e3dc5 100644 --- a/Runtime/Extensions/Physics2D/PointEffector2DTweens.cs +++ b/Runtime/Extensions/Physics2D/PointEffector2DTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class PointEffector2DTweens { public static Tween TweenDrag(this PointEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.drag, - setter: drag => effector.drag = drag, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.drag, (target, value) => target.drag = value, to, duration) + .SetReference(effector); public static Tween TweenAngularDrag(this PointEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.angularDrag, - setter: angularDrag => effector.angularDrag = angularDrag, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.angularDrag, (target, value) => target.angularDrag = value, to, duration) + .SetReference(effector); public static Tween TweenForceMagnitude(this PointEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceMagnitude, - setter: forceMagnitude => effector.forceMagnitude = forceMagnitude, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.forceMagnitude, (target, value) => target.forceMagnitude = value, to, duration) + .SetReference(effector); public static Tween TweenForceVariation(this PointEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceVariation, - setter: forceVariation => effector.forceVariation = forceVariation, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.forceVariation, (target, value) => target.forceVariation = value, to, duration) + .SetReference(effector); public static Tween TweenDistanceScale(this PointEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.distanceScale, - setter: distanceScale => effector.distanceScale = distanceScale, - to, duration).SetTarget(effector); - + Tweening.To(effector, (target) => target.distanceScale, (target, value) => target.distanceScale = value, to, duration) + .SetReference(effector); } } diff --git a/Runtime/Extensions/Physics2D/RelativeJoint2DTweens.cs b/Runtime/Extensions/Physics2D/RelativeJoint2DTweens.cs index b17f37c..0b3321e 100644 --- a/Runtime/Extensions/Physics2D/RelativeJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/RelativeJoint2DTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class RelativeJoint2DTweens { public static Tween TweenMaxForce(this RelativeJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.maxForce, - setter: maxForce => joint.maxForce = maxForce, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.maxForce, (target, value) => target.maxForce = value, to, duration) + .SetReference(joint); public static Tween TweenMaxTorque(this RelativeJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.maxTorque, - setter: maxTorque => joint.maxTorque = maxTorque, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.maxTorque, (target, value) => target.maxTorque = value, to, duration) + .SetReference(joint); public static Tween TweenCorrectionScale(this RelativeJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.correctionScale, - setter: correctionScale => joint.correctionScale = correctionScale, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.correctionScale, (target, value) => target.correctionScale = value, to, duration) + .SetReference(joint); public static Tween TweenLinearOffset(this RelativeJoint2D joint, Vector2 to, float duration) => - Tweening.To(getter: () => joint.linearOffset, - setter: linearOffset => joint.linearOffset = linearOffset, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.linearOffset, (target, value) => target.linearOffset = value, to, duration) + .SetReference(joint); public static Tween TweenAngularOffset(this RelativeJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.angularOffset, - setter: angularOffset => joint.angularOffset = angularOffset, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.angularOffset, (target, value) => target.angularOffset = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/Rigidbody2DTweens.cs b/Runtime/Extensions/Physics2D/Rigidbody2DTweens.cs index 8c46cd5..2583377 100644 --- a/Runtime/Extensions/Physics2D/Rigidbody2DTweens.cs +++ b/Runtime/Extensions/Physics2D/Rigidbody2DTweens.cs @@ -5,55 +5,44 @@ namespace Zigurous.Tweening public static class Rigidbody2DTweens { public static Tween TweenPosition(this Rigidbody2D rigidbody, Vector2 to, float duration) => - Tweening.To(getter: () => rigidbody.position, - setter: position => rigidbody.position = position, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.position, (target, value) => target.position = value, to, duration) + .SetReference(rigidbody); public static Tween TweenRotation(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.rotation, - setter: rotation => rigidbody.rotation = rotation, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.rotation, (target, value) => target.rotation = value, to, duration) + .SetReference(rigidbody); public static Tween TweenVelocity(this Rigidbody2D rigidbody, Vector2 to, float duration) => - Tweening.To(getter: () => rigidbody.velocity, - setter: velocity => rigidbody.velocity = velocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.velocity, (target, value) => target.velocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenAngularVelocity(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.angularVelocity, - setter: angularVelocity => rigidbody.angularVelocity = angularVelocity, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.angularVelocity, (target, value) => target.angularVelocity = value, to, duration) + .SetReference(rigidbody); public static Tween TweenMass(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.mass, - setter: mass => rigidbody.mass = mass, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.mass, (target, value) => target.mass = value, to, duration) + .SetReference(rigidbody); public static Tween TweenCenterOfMass(this Rigidbody2D rigidbody, Vector2 to, float duration) => - Tweening.To(getter: () => rigidbody.centerOfMass, - setter: centerOfMass => rigidbody.centerOfMass = centerOfMass, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.centerOfMass, (target, value) => target.centerOfMass = value, to, duration) + .SetReference(rigidbody); public static Tween TweenDrag(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.drag, - setter: drag => rigidbody.drag = drag, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.drag, (target, value) => target.drag = value, to, duration) + .SetReference(rigidbody); public static Tween TweenAngularDrag(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.angularDrag, - setter: angularDrag => rigidbody.angularDrag = angularDrag, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.angularDrag, (target, value) => target.angularDrag = value, to, duration) + .SetReference(rigidbody); public static Tween TweenInertia(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.inertia, - setter: inertia => rigidbody.inertia = inertia, - to, duration).SetTarget(rigidbody); + Tweening.To(rigidbody, (target) => target.inertia, (target, value) => target.inertia = value, to, duration) + .SetReference(rigidbody); public static Tween TweenGravityScale(this Rigidbody2D rigidbody, float to, float duration) => - Tweening.To(getter: () => rigidbody.gravityScale, - setter: gravityScale => rigidbody.gravityScale = gravityScale, - to, duration).SetTarget(rigidbody); - + Tweening.To(rigidbody, (target) => target.gravityScale, (target, value) => target.gravityScale = value, to, duration) + .SetReference(rigidbody); } } diff --git a/Runtime/Extensions/Physics2D/SliderJoint2DTweens.cs b/Runtime/Extensions/Physics2D/SliderJoint2DTweens.cs index e2ec77f..46a465e 100644 --- a/Runtime/Extensions/Physics2D/SliderJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/SliderJoint2DTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class SliderJoint2DTweens { public static Tween TweenAngle(this SliderJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.angle, - setter: angle => joint.angle = angle, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.angle, (target, value) => target.angle = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/SpringJoint2DTweens.cs b/Runtime/Extensions/Physics2D/SpringJoint2DTweens.cs index 7a68a27..b0812e6 100644 --- a/Runtime/Extensions/Physics2D/SpringJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/SpringJoint2DTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class SpringJoint2DTweens { public static Tween TweenDistance(this SpringJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.distance, - setter: distance => joint.distance = distance, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.distance, (target, value) => target.distance = value, to, duration) + .SetReference(joint); public static Tween TweenDampingRatio(this SpringJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.dampingRatio, - setter: dampingRatio => joint.dampingRatio = dampingRatio, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.dampingRatio, (target, value) => target.dampingRatio = value, to, duration) + .SetReference(joint); public static Tween TweenFrequency(this SpringJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.frequency, - setter: frequency => joint.frequency = frequency, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.frequency, (target, value) => target.frequency = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Physics2D/SurfaceEffector2DTweens.cs b/Runtime/Extensions/Physics2D/SurfaceEffector2DTweens.cs index bd96bfe..d578754 100644 --- a/Runtime/Extensions/Physics2D/SurfaceEffector2DTweens.cs +++ b/Runtime/Extensions/Physics2D/SurfaceEffector2DTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class SurfaceEffector2DTweens { public static Tween TweenSpeed(this SurfaceEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.speed, - setter: speed => effector.speed = speed, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.speed, (target, value) => target.speed = value, to, duration) + .SetReference(effector); public static Tween TweenSpeedVariation(this SurfaceEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.speedVariation, - setter: speedVariation => effector.speedVariation = speedVariation, - to, duration).SetTarget(effector); + Tweening.To(effector, (target) => target.speedVariation, (target, value) => target.speedVariation = value, to, duration) + .SetReference(effector); public static Tween TweenForceScale(this SurfaceEffector2D effector, float to, float duration) => - Tweening.To(getter: () => effector.forceScale, - setter: forceScale => effector.forceScale = forceScale, - to, duration).SetTarget(effector); - + Tweening.To(effector, (target) => target.forceScale, (target, value) => target.forceScale = value, to, duration) + .SetReference(effector); } } diff --git a/Runtime/Extensions/Physics2D/TargetJoint2DTweens.cs b/Runtime/Extensions/Physics2D/TargetJoint2DTweens.cs index faa57c2..f1d708e 100644 --- a/Runtime/Extensions/Physics2D/TargetJoint2DTweens.cs +++ b/Runtime/Extensions/Physics2D/TargetJoint2DTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class TargetJoint2DTweens { public static Tween TweenAnchor(this TargetJoint2D joint, Vector2 to, float duration) => - Tweening.To(getter: () => joint.anchor, - setter: anchor => joint.anchor = anchor, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.anchor, (target, value) => target.anchor = value, to, duration) + .SetReference(joint); public static Tween TweenTarget(this TargetJoint2D joint, Vector2 to, float duration) => - Tweening.To(getter: () => joint.target, - setter: target => joint.target = target, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.target, (target, value) => target.target = value, to, duration) + .SetReference(joint); public static Tween TweenMaxForce(this TargetJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.maxForce, - setter: maxForce => joint.maxForce = maxForce, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.maxForce, (target, value) => target.maxForce = value, to, duration) + .SetReference(joint); public static Tween TweenDampingRatio(this TargetJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.dampingRatio, - setter: dampingRatio => joint.dampingRatio = dampingRatio, - to, duration).SetTarget(joint); + Tweening.To(joint, (target) => target.dampingRatio, (target, value) => target.dampingRatio = value, to, duration) + .SetReference(joint); public static Tween TweenFrequency(this TargetJoint2D joint, float to, float duration) => - Tweening.To(getter: () => joint.frequency, - setter: frequency => joint.frequency = frequency, - to, duration).SetTarget(joint); - + Tweening.To(joint, (target) => target.frequency, (target, value) => target.frequency = value, to, duration) + .SetReference(joint); } } diff --git a/Runtime/Extensions/Rendering/AnimatorTweens.cs b/Runtime/Extensions/Rendering/AnimatorTweens.cs index e0e7f21..2c560c3 100644 --- a/Runtime/Extensions/Rendering/AnimatorTweens.cs +++ b/Runtime/Extensions/Rendering/AnimatorTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class AnimatorTweens { public static Tween TweenSpeed(this Animator animator, float to, float duration) => - Tweening.To(getter: () => animator.speed, - setter: speed => animator.speed = speed, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.speed, (target, value) => target.speed = value, to, duration) + .SetReference(animator); public static Tween TweenPlaybackTime(this Animator animator, float to, float duration) => - Tweening.To(getter: () => animator.playbackTime, - setter: playbackTime => animator.playbackTime = playbackTime, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.playbackTime, (target, value) => target.playbackTime = value, to, duration) + .SetReference(animator); public static Tween TweenBodyRotation(this Animator animator, Quaternion to, float duration) => - Tweening.To(getter: () => animator.bodyRotation, - setter: bodyRotation => animator.bodyRotation = bodyRotation, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.bodyRotation, (target, value) => target.bodyRotation = value, to, duration) + .SetReference(animator); public static Tween TweenBodyPosition(this Animator animator, Vector3 to, float duration) => - Tweening.To(getter: () => animator.bodyPosition, - setter: bodyPosition => animator.bodyPosition = bodyPosition, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.bodyPosition, (target, value) => target.bodyPosition = value, to, duration) + .SetReference(animator); public static Tween TweenRootRotation(this Animator animator, Quaternion to, float duration) => - Tweening.To(getter: () => animator.rootRotation, - setter: rootRotation => animator.rootRotation = rootRotation, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.rootRotation, (target, value) => target.rootRotation = value, to, duration) + .SetReference(animator); public static Tween TweenRootPosition(this Animator animator, Vector3 to, float duration) => - Tweening.To(getter: () => animator.rootPosition, - setter: rootPosition => animator.rootPosition = rootPosition, - to, duration).SetTarget(animator); + Tweening.To(animator, (target) => target.rootPosition, (target, value) => target.rootPosition = value, to, duration) + .SetReference(animator); public static Tween TweenFeetPivotActive(this Animator animator, float to, float duration) => - Tweening.To(getter: () => animator.feetPivotActive, - setter: feetPivotActive => animator.feetPivotActive = feetPivotActive, - to, duration).SetTarget(animator); - + Tweening.To(animator, (target) => target.feetPivotActive, (target, value) => target.feetPivotActive = value, to, duration) + .SetReference(animator); } } diff --git a/Runtime/Extensions/Rendering/CameraTweens.cs b/Runtime/Extensions/Rendering/CameraTweens.cs index 2aeccef..992b971 100644 --- a/Runtime/Extensions/Rendering/CameraTweens.cs +++ b/Runtime/Extensions/Rendering/CameraTweens.cs @@ -5,75 +5,60 @@ namespace Zigurous.Tweening public static class CameraTweens { public static Tween TweenBackgroundColor(this Camera camera, Color to, float duration) => - Tweening.To(getter: () => camera.backgroundColor, - setter: backgroundColor => camera.backgroundColor = backgroundColor, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.backgroundColor, (target, value) => target.backgroundColor = value, to, duration) + .SetReference(camera); public static Tween TweenAspectRatio(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.aspect, - setter: aspect => camera.aspect = aspect, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.aspect, (target, value) => target.aspect = value, to, duration) + .SetReference(camera); public static Tween TweenFieldOfView(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.fieldOfView, - setter: fieldOfView => camera.fieldOfView = fieldOfView, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.fieldOfView, (target, value) => target.fieldOfView = value, to, duration) + .SetReference(camera); public static Tween TweenNearClipPlane(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.nearClipPlane, - setter: nearClipPlane => camera.nearClipPlane = nearClipPlane, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.nearClipPlane, (target, value) => target.nearClipPlane = value, to, duration) + .SetReference(camera); public static Tween TweenFarClipPlane(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.farClipPlane, - setter: farClipPlane => camera.farClipPlane = farClipPlane, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.farClipPlane, (target, value) => target.farClipPlane = value, to, duration) + .SetReference(camera); public static Tween TweenOrthographicSize(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.orthographicSize, - setter: orthographicSize => camera.orthographicSize = orthographicSize, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.orthographicSize, (target, value) => target.orthographicSize = value, to, duration) + .SetReference(camera); public static Tween TweenSensorSize(this Camera camera, Vector2 to, float duration) => - Tweening.To(getter: () => camera.sensorSize, - setter: sensorSize => camera.sensorSize = sensorSize, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.sensorSize, (target, value) => target.sensorSize = value, to, duration) + .SetReference(camera); public static Tween TweenFocalLength(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.focalLength, - setter: focalLength => camera.focalLength = focalLength, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.focalLength, (target, value) => target.focalLength = value, to, duration) + .SetReference(camera); public static Tween TweenStereoConvergence(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.stereoConvergence, - setter: stereoConvergence => camera.stereoConvergence = stereoConvergence, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.stereoConvergence, (target, value) => target.stereoConvergence = value, to, duration) + .SetReference(camera); public static Tween TweenStereoSeparation(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.stereoSeparation, - setter: stereoSeparation => camera.stereoSeparation = stereoSeparation, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.stereoSeparation, (target, value) => target.stereoSeparation = value, to, duration) + .SetReference(camera); public static Tween TweenLensShift(this Camera camera, Vector2 to, float duration) => - Tweening.To(getter: () => camera.lensShift, - setter: lensShift => camera.lensShift = lensShift, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.lensShift, (target, value) => target.lensShift = value, to, duration) + .SetReference(camera); public static Tween TweenRect(this Camera camera, Rect to, float duration) => - Tweening.To(getter: () => camera.rect, - setter: rect => camera.rect = rect, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.rect, (target, value) => target.rect = value, to, duration) + .SetReference(camera); public static Tween TweenPixelRect(this Camera camera, Rect to, float duration) => - Tweening.To(getter: () => camera.pixelRect, - setter: pixelRect => camera.pixelRect = pixelRect, - to, duration).SetTarget(camera); + Tweening.To(camera, (target) => target.pixelRect, (target, value) => target.pixelRect = value, to, duration) + .SetReference(camera); public static Tween TweenDepth(this Camera camera, float to, float duration) => - Tweening.To(getter: () => camera.depth, - setter: depth => camera.depth = depth, - to, duration).SetTarget(camera); - + Tweening.To(camera, (target) => target.depth, (target, value) => target.depth = value, to, duration) + .SetReference(camera); } } diff --git a/Runtime/Extensions/Rendering/LensFlareTweens.cs b/Runtime/Extensions/Rendering/LensFlareTweens.cs index 38859b0..eed0e2d 100644 --- a/Runtime/Extensions/Rendering/LensFlareTweens.cs +++ b/Runtime/Extensions/Rendering/LensFlareTweens.cs @@ -5,20 +5,16 @@ namespace Zigurous.Tweening public static class LensFlareTweens { public static Tween TweenColor(this LensFlare lensFlare, Color to, float duration) => - Tweening.To(getter: () => lensFlare.color, - setter: color => lensFlare.color = color, - to, duration).SetTarget(lensFlare); + Tweening.To(lensFlare, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(lensFlare); public static Tween TweenBrightness(this LensFlare lensFlare, float to, float duration) => - Tweening.To(getter: () => lensFlare.brightness, - setter: brightness => lensFlare.brightness = brightness, - to, duration).SetTarget(lensFlare); + Tweening.To(lensFlare, (target) => target.brightness, (target, value) => target.brightness = value, to, duration) + .SetReference(lensFlare); public static Tween TweenFadeSpeed(this LensFlare lensFlare, float to, float duration) => - Tweening.To(getter: () => lensFlare.fadeSpeed, - setter: fadeSpeed => lensFlare.fadeSpeed = fadeSpeed, - to, duration).SetTarget(lensFlare); - + Tweening.To(lensFlare, (target) => target.fadeSpeed, (target, value) => target.fadeSpeed = value, to, duration) + .SetReference(lensFlare); } } diff --git a/Runtime/Extensions/Rendering/LightTweens.cs b/Runtime/Extensions/Rendering/LightTweens.cs index 3679103..96c32be 100644 --- a/Runtime/Extensions/Rendering/LightTweens.cs +++ b/Runtime/Extensions/Rendering/LightTweens.cs @@ -5,70 +5,56 @@ namespace Zigurous.Tweening public static class LightTweens { public static Tween TweenColor(this Light light, Color to, float duration) => - Tweening.To(getter: () => light.color, - setter: color => light.color = color, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(light); public static Tween TweenColorTemperature(this Light light, float to, float duration) => - Tweening.To(getter: () => light.colorTemperature, - setter: colorTemperature => light.colorTemperature = colorTemperature, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.colorTemperature, (target, value) => target.colorTemperature = value, to, duration) + .SetReference(light); public static Tween TweenIntensity(this Light light, float to, float duration) => - Tweening.To(getter: () => light.intensity, - setter: intensity => light.intensity = intensity, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.intensity, (target, value) => target.intensity = value, to, duration) + .SetReference(light); public static Tween TweenBounceIntensity(this Light light, float to, float duration) => - Tweening.To(getter: () => light.bounceIntensity, - setter: bounceIntensity => light.bounceIntensity = bounceIntensity, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.bounceIntensity, (target, value) => target.bounceIntensity = value, to, duration) + .SetReference(light); public static Tween TweenRange(this Light light, float to, float duration) => - Tweening.To(getter: () => light.range, - setter: range => light.range = range, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.range, (target, value) => target.range = value, to, duration) + .SetReference(light); public static Tween TweenShadowStrength(this Light light, float to, float duration) => - Tweening.To(getter: () => light.shadowStrength, - setter: shadowStrength => light.shadowStrength = shadowStrength, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.shadowStrength, (target, value) => target.shadowStrength = value, to, duration) + .SetReference(light); public static Tween TweenShadowBias(this Light light, float to, float duration) => - Tweening.To(getter: () => light.shadowBias, - setter: shadowBias => light.shadowBias = shadowBias, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.shadowBias, (target, value) => target.shadowBias = value, to, duration) + .SetReference(light); public static Tween TweenShadowNormalBias(this Light light, float to, float duration) => - Tweening.To(getter: () => light.shadowNormalBias, - setter: shadowNormalBias => light.shadowNormalBias = shadowNormalBias, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.shadowNormalBias, (target, value) => target.shadowNormalBias = value, to, duration) + .SetReference(light); public static Tween TweenShadowNearPlane(this Light light, float to, float duration) => - Tweening.To(getter: () => light.shadowNearPlane, - setter: shadowNearPlane => light.shadowNearPlane = shadowNearPlane, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.shadowNearPlane, (target, value) => target.shadowNearPlane = value, to, duration) + .SetReference(light); public static Tween TweenSpotAngle(this Light light, float to, float duration) => - Tweening.To(getter: () => light.spotAngle, - setter: spotAngle => light.spotAngle = spotAngle, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.spotAngle, (target, value) => target.spotAngle = value, to, duration) + .SetReference(light); public static Tween TweenInnerSpotAngle(this Light light, float to, float duration) => - Tweening.To(getter: () => light.innerSpotAngle, - setter: innerSpotAngle => light.innerSpotAngle = innerSpotAngle, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.innerSpotAngle, (target, value) => target.innerSpotAngle = value, to, duration) + .SetReference(light); public static Tween TweenCookieSize(this Light light, float to, float duration) => - Tweening.To(getter: () => light.cookieSize, - setter: cookieSize => light.cookieSize = cookieSize, - to, duration).SetTarget(light); + Tweening.To(light, (target) => target.cookieSize, (target, value) => target.cookieSize = value, to, duration) + .SetReference(light); public static Tween TweenBoundingSphereOverride(this Light light, Vector4 to, float duration) => - Tweening.To(getter: () => light.boundingSphereOverride, - setter: boundingSphereOverride => light.boundingSphereOverride = boundingSphereOverride, - to, duration).SetTarget(light); - + Tweening.To(light, (target) => target.boundingSphereOverride, (target, value) => target.boundingSphereOverride = value, to, duration) + .SetReference(light); } } diff --git a/Runtime/Extensions/Rendering/LineRendererTweens.cs b/Runtime/Extensions/Rendering/LineRendererTweens.cs index 9f01dc0..4e14fe5 100644 --- a/Runtime/Extensions/Rendering/LineRendererTweens.cs +++ b/Runtime/Extensions/Rendering/LineRendererTweens.cs @@ -5,35 +5,28 @@ namespace Zigurous.Tweening public static class LineRendererTweens { public static Tween TweenStartColor(this LineRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.startColor, - setter: startColor => renderer.startColor = startColor, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.startColor, (target, value) => target.startColor = value, to, duration) + .SetReference(renderer); public static Tween TweenEndColor(this LineRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.endColor, - setter: endColor => renderer.endColor = endColor, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.endColor, (target, value) => target.endColor = value, to, duration) + .SetReference(renderer); public static Tween TweenStartWidth(this LineRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.startWidth, - setter: startWidth => renderer.startWidth = startWidth, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.startWidth, (target, value) => target.startWidth = value, to, duration) + .SetReference(renderer); public static Tween TweenEndWidth(this LineRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.endWidth, - setter: endWidth => renderer.endWidth = endWidth, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.endWidth, (target, value) => target.endWidth = value, to, duration) + .SetReference(renderer); public static Tween TweenWidthMultiplier(this LineRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.widthMultiplier, - setter: widthMultiplier => renderer.widthMultiplier = widthMultiplier, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.widthMultiplier, (target, value) => target.widthMultiplier = value, to, duration) + .SetReference(renderer); public static Tween TweenShadowBias(this LineRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.shadowBias, - setter: shadowBias => renderer.shadowBias = shadowBias, - to, duration).SetTarget(renderer); - + Tweening.To(renderer, (target) => target.shadowBias, (target, value) => target.shadowBias = value, to, duration) + .SetReference(renderer); } } diff --git a/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs b/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs new file mode 100644 index 0000000..65c9bf1 --- /dev/null +++ b/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs @@ -0,0 +1,72 @@ +using UnityEngine; + +namespace Zigurous.Tweening +{ + public static class MaterialPropertyBlockTweens + { + public static Tween TweenColor(this MaterialPropertyBlock propertyBlock, int nameID, Color to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(nameID), (target, value) => target.SetColor(nameID, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenColor(this MaterialPropertyBlock propertyBlock, string name, Color to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(name), (target, value) => target.SetColor(name, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenRed(this MaterialPropertyBlock propertyBlock, int nameID, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(nameID).r, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithRed(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenRed(this MaterialPropertyBlock propertyBlock, string name, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(name).r, (target, value) => target.SetColor(name, target.GetColor(name).WithRed(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenGreen(this MaterialPropertyBlock propertyBlock, int nameID, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(nameID).g, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithGreen(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenGreen(this MaterialPropertyBlock propertyBlock, string name, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(name).g, (target, value) => target.SetColor(name, target.GetColor(name).WithGreen(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenBlue(this MaterialPropertyBlock propertyBlock, int nameID, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(nameID).b, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithBlue(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenBlue(this MaterialPropertyBlock propertyBlock, string name, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(name).b, (target, value) => target.SetColor(name, target.GetColor(name).WithBlue(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenAlpha(this MaterialPropertyBlock propertyBlock, int nameID, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(nameID).a, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithAlpha(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenAlpha(this MaterialPropertyBlock propertyBlock, string name, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetColor(name).a, (target, value) => target.SetColor(name, target.GetColor(name).WithAlpha(value)), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenVector(this MaterialPropertyBlock propertyBlock, int nameID, Vector4 to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetVector(nameID), (target, value) => target.SetVector(nameID, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenVector(this MaterialPropertyBlock propertyBlock, string name, Vector4 to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetVector(name), (target, value) => target.SetVector(name, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenFloat(this MaterialPropertyBlock propertyBlock, int nameID, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetFloat(nameID), (target, value) => target.SetFloat(nameID, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenFloat(this MaterialPropertyBlock propertyBlock, string name, float to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetFloat(name), (target, value) => target.SetFloat(name, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenInt(this MaterialPropertyBlock propertyBlock, int nameID, int to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetInt(nameID), (target, value) => target.SetInt(nameID, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + + public static Tween TweenInt(this MaterialPropertyBlock propertyBlock, string name, int to, float duration) => + Tweening.To(propertyBlock, (target) => target.GetInt(name), (target, value) => target.SetInt(name, value), to, duration) + .SetId(propertyBlock.GetHashCode()); + } + +} diff --git a/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs.meta b/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs.meta new file mode 100644 index 0000000..df4e7c5 --- /dev/null +++ b/Runtime/Extensions/Rendering/MaterialPropertyBlockTweens.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eb852c19ded4d96479888dab393c579e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Extensions/Rendering/MaterialTweens.cs b/Runtime/Extensions/Rendering/MaterialTweens.cs index 67bfcf1..454aa5c 100644 --- a/Runtime/Extensions/Rendering/MaterialTweens.cs +++ b/Runtime/Extensions/Rendering/MaterialTweens.cs @@ -5,85 +5,104 @@ namespace Zigurous.Tweening public static class MaterialTweens { public static Tween TweenColor(this Material material, Color to, float duration) => - Tweening.To(getter: () => material.color, - setter: color => material.color = color, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(material); - public static Tween TweenColor(this Material material, int nameId, Color to, float duration) => - Tweening.To(getter: () => material.GetColor(nameId), - setter: color => material.SetColor(nameId, color), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenColor(this Material material, int nameID, Color to, float duration) => + Tweening.To(material, (target) => target.GetColor(nameID), (target, value) => target.SetColor(nameID, value), to, duration) + .SetReference(material); public static Tween TweenColor(this Material material, string name, Color to, float duration) => - Tweening.To(getter: () => material.GetColor(name), - setter: color => material.SetColor(name, color), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.GetColor(name), (target, value) => target.SetColor(name, value), to, duration) + .SetReference(material); + + public static Tween TweenRed(this Material material, float to, float duration) => + Tweening.To(material, (target) => target.color.r, (target, value) => target.color = target.color.WithRed(value), to, duration) + .SetReference(material); + + public static Tween TweenRed(this Material material, int nameID, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(nameID).r, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithRed(value)), to, duration) + .SetReference(material); + + public static Tween TweenRed(this Material material, string name, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(name).r, (target, value) => target.SetColor(name, target.GetColor(name).WithRed(value)), to, duration) + .SetReference(material); + + public static Tween TweenGreen(this Material material, float to, float duration) => + Tweening.To(material, (target) => target.color.g, (target, value) => target.color = target.color.WithGreen(value), to, duration) + .SetReference(material); + + public static Tween TweenGreen(this Material material, int nameID, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(nameID).g, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithGreen(value)), to, duration) + .SetReference(material); + + public static Tween TweenGreen(this Material material, string name, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(name).g, (target, value) => target.SetColor(name, target.GetColor(name).WithGreen(value)), to, duration) + .SetReference(material); + + public static Tween TweenBlue(this Material material, float to, float duration) => + Tweening.To(material, (target) => target.color.b, (target, value) => target.color = target.color.WithBlue(value), to, duration) + .SetReference(material); + + public static Tween TweenBlue(this Material material, int nameID, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(nameID).b, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithBlue(value)), to, duration) + .SetReference(material); + + public static Tween TweenBlue(this Material material, string name, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(name).b, (target, value) => target.SetColor(name, target.GetColor(name).WithBlue(value)), to, duration) + .SetReference(material); public static Tween TweenAlpha(this Material material, float to, float duration) => - Tweening.To(getter: () => material.color.a, - setter: alpha => material.color = new Color(material.color.r, material.color.g, material.color.b, alpha), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.color.a, (target, value) => target.color = target.color.WithAlpha(value), to, duration) + .SetReference(material); - public static Tween TweenAlpha(this Material material, int nameId, float to, float duration) => - Tweening.To(getter: () => material.GetColor(nameId).a, - setter: alpha => material.SetColor(nameId, new Color(material.color.r, material.color.g, material.color.b, alpha)), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenAlpha(this Material material, int nameID, float to, float duration) => + Tweening.To(material, (target) => target.GetColor(nameID).a, (target, value) => target.SetColor(nameID, target.GetColor(nameID).WithAlpha(value)), to, duration) + .SetReference(material); public static Tween TweenAlpha(this Material material, string name, float to, float duration) => - Tweening.To(getter: () => material.GetColor(name).a, - setter: alpha => material.SetColor(name, new Color(material.color.r, material.color.g, material.color.b, alpha)), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.GetColor(name).a, (target, value) => target.SetColor(name, target.GetColor(name).WithAlpha(value)), to, duration) + .SetReference(material); - public static Tween TweenFloat(this Material material, int nameId, float to, float duration) => - Tweening.To(getter: () => material.GetFloat(nameId), - setter: value => material.SetFloat(nameId, value), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenFloat(this Material material, int nameID, float to, float duration) => + Tweening.To(material, (target) => target.GetFloat(nameID), (target, value) => target.SetFloat(nameID, value), to, duration) + .SetReference(material); public static Tween TweenFloat(this Material material, string name, float to, float duration) => - Tweening.To(getter: () => material.GetFloat(name), - setter: value => material.SetFloat(name, value), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.GetFloat(name), (target, value) => target.SetFloat(name, value), to, duration) + .SetReference(material); - public static Tween TweenInt(this Material material, int nameId, int to, float duration) => - Tweening.To(getter: () => material.GetInt(nameId), - setter: value => material.SetInt(nameId, value), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenInt(this Material material, int nameID, int to, float duration) => + Tweening.To(material, (target) => target.GetInt(nameID), (target, value) => target.SetInt(nameID, value), to, duration) + .SetReference(material); public static Tween TweenInt(this Material material, string name, int to, float duration) => - Tweening.To(getter: () => material.GetInt(name), - setter: value => material.SetInt(name, value), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.GetInt(name), (target, value) => target.SetInt(name, value), to, duration) + .SetReference(material); public static Tween TweenMainTextureOffset(this Material material, Vector2 to, float duration) => - Tweening.To(getter: () => material.mainTextureOffset, - setter: mainTextureOffset => material.mainTextureOffset = mainTextureOffset, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.mainTextureOffset, (target, value) => target.mainTextureOffset = value, to, duration) + .SetReference(material); public static Tween TweenMainTextureScale(this Material material, Vector2 to, float duration) => - Tweening.To(getter: () => material.mainTextureScale, - setter: mainTextureScale => material.mainTextureScale = mainTextureScale, - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.mainTextureScale, (target, value) => target.mainTextureScale = value, to, duration) + .SetReference(material); - public static Tween TweenTextureOffset(this Material material, int nameId, Vector2 to, float duration) => - Tweening.To(getter: () => material.GetTextureOffset(nameId), - setter: value => material.SetTextureOffset(nameId, value), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenTextureOffset(this Material material, int nameID, Vector2 to, float duration) => + Tweening.To(material, (target) => target.GetTextureOffset(nameID), (target, value) => target.SetTextureOffset(nameID, value), to, duration) + .SetReference(material); public static Tween TweenTextureOffset(this Material material, string name, Vector2 to, float duration) => - Tweening.To(getter: () => material.GetTextureOffset(name), - setter: value => material.SetTextureOffset(name, value), - to, duration).SetId(material.GetHashCode()); + Tweening.To(material, (target) => target.GetTextureOffset(name), (target, value) => target.SetTextureOffset(name, value), to, duration) + .SetReference(material); - public static Tween TweenTextureScale(this Material material, int nameId, Vector2 to, float duration) => - Tweening.To(getter: () => material.GetTextureScale(nameId), - setter: value => material.SetTextureScale(nameId, value), - to, duration).SetId(material.GetHashCode()); + public static Tween TweenTextureScale(this Material material, int nameID, Vector2 to, float duration) => + Tweening.To(material, (target) => target.GetTextureScale(nameID), (target, value) => target.SetTextureScale(nameID, value), to, duration) + .SetReference(material); public static Tween TweenTextureScale(this Material material, string name, Vector2 to, float duration) => - Tweening.To(getter: () => material.GetTextureScale(name), - setter: value => material.SetTextureScale(name, value), - to, duration).SetId(material.GetHashCode()); - + Tweening.To(material, (target) => target.GetTextureScale(name), (target, value) => target.SetTextureScale(name, value), to, duration) + .SetReference(material); } } diff --git a/Runtime/Extensions/Rendering/OcclusionAreaTweens.cs b/Runtime/Extensions/Rendering/OcclusionAreaTweens.cs index 1a4de74..eb3d474 100644 --- a/Runtime/Extensions/Rendering/OcclusionAreaTweens.cs +++ b/Runtime/Extensions/Rendering/OcclusionAreaTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class OcclusionAreaTweens { public static Tween TweenCenter(this OcclusionArea area, Vector3 to, float duration) => - Tweening.To(getter: () => area.center, - setter: center => area.center = center, - to, duration).SetTarget(area); + Tweening.To(area, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(area); public static Tween TweenSize(this OcclusionArea area, Vector3 to, float duration) => - Tweening.To(getter: () => area.size, - setter: size => area.size = size, - to, duration).SetTarget(area); - + Tweening.To(area, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(area); } } diff --git a/Runtime/Extensions/Rendering/ParticleSystemForceFieldTweens.cs b/Runtime/Extensions/Rendering/ParticleSystemForceFieldTweens.cs index 00fb377..4b2e4ea 100644 --- a/Runtime/Extensions/Rendering/ParticleSystemForceFieldTweens.cs +++ b/Runtime/Extensions/Rendering/ParticleSystemForceFieldTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class ParticleSystemForceFieldTweens { public static Tween TweenRotationRandomness(this ParticleSystemForceField forceField, Vector2 to, float duration) => - Tweening.To(getter: () => forceField.rotationRandomness, - setter: rotationRandomness => forceField.rotationRandomness = rotationRandomness, - to, duration).SetTarget(forceField); + Tweening.To(forceField, (target) => target.rotationRandomness, (target, value) => target.rotationRandomness = value, to, duration) + .SetReference(forceField); public static Tween TweenGravityFocus(this ParticleSystemForceField forceField, float to, float duration) => - Tweening.To(getter: () => forceField.gravityFocus, - setter: gravityFocus => forceField.gravityFocus = gravityFocus, - to, duration).SetTarget(forceField); + Tweening.To(forceField, (target) => target.gravityFocus, (target, value) => target.gravityFocus = value, to, duration) + .SetReference(forceField); public static Tween TweenLength(this ParticleSystemForceField forceField, float to, float duration) => - Tweening.To(getter: () => forceField.length, - setter: length => forceField.length = length, - to, duration).SetTarget(forceField); + Tweening.To(forceField, (target) => target.length, (target, value) => target.length = value, to, duration) + .SetReference(forceField); public static Tween TweenStartRange(this ParticleSystemForceField forceField, float to, float duration) => - Tweening.To(getter: () => forceField.startRange, - setter: startRange => forceField.startRange = startRange, - to, duration).SetTarget(forceField); + Tweening.To(forceField, (target) => target.startRange, (target, value) => target.startRange = value, to, duration) + .SetReference(forceField); public static Tween TweenEndRange(this ParticleSystemForceField forceField, float to, float duration) => - Tweening.To(getter: () => forceField.endRange, - setter: endRange => forceField.endRange = endRange, - to, duration).SetTarget(forceField); - + Tweening.To(forceField, (target) => target.endRange, (target, value) => target.endRange = value, to, duration) + .SetReference(forceField); } } diff --git a/Runtime/Extensions/Rendering/ParticleSystemTweens.cs b/Runtime/Extensions/Rendering/ParticleSystemTweens.cs index 0d4fc1a..90f332d 100644 --- a/Runtime/Extensions/Rendering/ParticleSystemTweens.cs +++ b/Runtime/Extensions/Rendering/ParticleSystemTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class ParticleSystemTweens { public static Tween TweenTime(this ParticleSystem particleSystem, float to, float duration) => - Tweening.To(getter: () => particleSystem.time, - setter: time => particleSystem.time = time, - to, duration).SetTarget(particleSystem); - + Tweening.To(particleSystem, (target) => target.time, (target, value) => target.time = value, to, duration) + .SetReference(particleSystem); } } diff --git a/Runtime/Extensions/Rendering/ProjectorTweens.cs b/Runtime/Extensions/Rendering/ProjectorTweens.cs index b06f1a6..3866280 100644 --- a/Runtime/Extensions/Rendering/ProjectorTweens.cs +++ b/Runtime/Extensions/Rendering/ProjectorTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class ProjectorTweens { public static Tween TweenNearClipPlane(this Projector projector, float to, float duration) => - Tweening.To(getter: () => projector.nearClipPlane, - setter: nearClipPlane => projector.nearClipPlane = nearClipPlane, - to, duration).SetTarget(projector); + Tweening.To(projector, (target) => target.nearClipPlane, (target, value) => target.nearClipPlane = value, to, duration) + .SetReference(projector); public static Tween TweenFarClipPlane(this Projector projector, float to, float duration) => - Tweening.To(getter: () => projector.farClipPlane, - setter: farClipPlane => projector.farClipPlane = farClipPlane, - to, duration).SetTarget(projector); + Tweening.To(projector, (target) => target.farClipPlane, (target, value) => target.farClipPlane = value, to, duration) + .SetReference(projector); public static Tween TweenFieldOfView(this Projector projector, float to, float duration) => - Tweening.To(getter: () => projector.fieldOfView, - setter: fieldOfView => projector.fieldOfView = fieldOfView, - to, duration).SetTarget(projector); + Tweening.To(projector, (target) => target.fieldOfView, (target, value) => target.fieldOfView = value, to, duration) + .SetReference(projector); public static Tween TweenAspectRatio(this Projector projector, float to, float duration) => - Tweening.To(getter: () => projector.aspectRatio, - setter: aspectRatio => projector.aspectRatio = aspectRatio, - to, duration).SetTarget(projector); + Tweening.To(projector, (target) => target.aspectRatio, (target, value) => target.aspectRatio = value, to, duration) + .SetReference(projector); public static Tween TweenOrthographicSize(this Projector projector, float to, float duration) => - Tweening.To(getter: () => projector.orthographicSize, - setter: orthographicSize => projector.orthographicSize = orthographicSize, - to, duration).SetTarget(projector); - + Tweening.To(projector, (target) => target.orthographicSize, (target, value) => target.orthographicSize = value, to, duration) + .SetReference(projector); } } diff --git a/Runtime/Extensions/Rendering/ReflectionProbeTweens.cs b/Runtime/Extensions/Rendering/ReflectionProbeTweens.cs index 1ec21ae..cdfd357 100644 --- a/Runtime/Extensions/Rendering/ReflectionProbeTweens.cs +++ b/Runtime/Extensions/Rendering/ReflectionProbeTweens.cs @@ -5,45 +5,36 @@ namespace Zigurous.Tweening public static class ReflectionProbeTweens { public static Tween TweenCenter(this ReflectionProbe probe, Vector3 to, float duration) => - Tweening.To(getter: () => probe.center, - setter: center => probe.center = center, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.center, (target, value) => target.center = value, to, duration) + .SetReference(probe); public static Tween TweenSize(this ReflectionProbe probe, Vector3 to, float duration) => - Tweening.To(getter: () => probe.size, - setter: size => probe.size = size, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(probe); public static Tween TweenIntensity(this ReflectionProbe probe, float to, float duration) => - Tweening.To(getter: () => probe.intensity, - setter: intensity => probe.intensity = intensity, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.intensity, (target, value) => target.intensity = value, to, duration) + .SetReference(probe); public static Tween TweenFarClipPlane(this ReflectionProbe probe, float to, float duration) => - Tweening.To(getter: () => probe.farClipPlane, - setter: farClipPlane => probe.farClipPlane = farClipPlane, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.farClipPlane, (target, value) => target.farClipPlane = value, to, duration) + .SetReference(probe); public static Tween TweenNearClipPlane(this ReflectionProbe probe, float to, float duration) => - Tweening.To(getter: () => probe.nearClipPlane, - setter: nearClipPlane => probe.nearClipPlane = nearClipPlane, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.nearClipPlane, (target, value) => target.nearClipPlane = value, to, duration) + .SetReference(probe); public static Tween TweenBlendDistance(this ReflectionProbe probe, float to, float duration) => - Tweening.To(getter: () => probe.blendDistance, - setter: blendDistance => probe.blendDistance = blendDistance, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.blendDistance, (target, value) => target.blendDistance = value, to, duration) + .SetReference(probe); public static Tween TweenShadowDistance(this ReflectionProbe probe, float to, float duration) => - Tweening.To(getter: () => probe.shadowDistance, - setter: shadowDistance => probe.shadowDistance = shadowDistance, - to, duration).SetTarget(probe); + Tweening.To(probe, (target) => target.shadowDistance, (target, value) => target.shadowDistance = value, to, duration) + .SetReference(probe); public static Tween TweenBackgroundColor(this ReflectionProbe probe, Color to, float duration) => - Tweening.To(getter: () => probe.backgroundColor, - setter: backgroundColor => probe.backgroundColor = backgroundColor, - to, duration).SetTarget(probe); - + Tweening.To(probe, (target) => target.backgroundColor, (target, value) => target.backgroundColor = value, to, duration) + .SetReference(probe); } } diff --git a/Runtime/Extensions/Rendering/SpriteMaskTweens.cs b/Runtime/Extensions/Rendering/SpriteMaskTweens.cs index bf82e31..6e17619 100644 --- a/Runtime/Extensions/Rendering/SpriteMaskTweens.cs +++ b/Runtime/Extensions/Rendering/SpriteMaskTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class SpriteMaskTweens { public static Tween TweenAlphaCutoff(this SpriteMask mask, float to, float duration) => - Tweening.To(getter: () => mask.alphaCutoff, - setter: alphaCutoff => mask.alphaCutoff = alphaCutoff, - to, duration).SetTarget(mask); - + Tweening.To(mask, (target) => target.alphaCutoff, (target, value) => target.alphaCutoff = value, to, duration) + .SetReference(mask); } } diff --git a/Runtime/Extensions/Rendering/SpriteRendererTweens.cs b/Runtime/Extensions/Rendering/SpriteRendererTweens.cs index 99c13d5..8972a1f 100644 --- a/Runtime/Extensions/Rendering/SpriteRendererTweens.cs +++ b/Runtime/Extensions/Rendering/SpriteRendererTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class SpriteRendererTweens { public static Tween TweenColor(this SpriteRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.color, - setter: color => renderer.color = color, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(renderer); public static Tween TweenAlpha(this SpriteRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.color.a, - setter: alpha => renderer.color = new Color(renderer.color.r, renderer.color.g, renderer.color.b, alpha), - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.color.a, (target, value) => target.color = new Color(target.color.r, target.color.g, target.color.b, value), to, duration) + .SetReference(renderer); public static Tween TweenSize(this SpriteRenderer renderer, Vector2 to, float duration) => - Tweening.To(getter: () => renderer.size, - setter: size => renderer.size = size, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(renderer); public static Tween TweenAdaptiveModeThreshold(this SpriteRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.adaptiveModeThreshold, - setter: adaptiveModeThreshold => renderer.adaptiveModeThreshold = adaptiveModeThreshold, - to, duration).SetTarget(renderer); - + Tweening.To(renderer, (target) => target.adaptiveModeThreshold, (target, value) => target.adaptiveModeThreshold = value, to, duration) + .SetReference(renderer); } } diff --git a/Runtime/Extensions/Rendering/SpriteShapeRendererTweens.cs b/Runtime/Extensions/Rendering/SpriteShapeRendererTweens.cs index 6a89dfa..90781a7 100644 --- a/Runtime/Extensions/Rendering/SpriteShapeRendererTweens.cs +++ b/Runtime/Extensions/Rendering/SpriteShapeRendererTweens.cs @@ -6,15 +6,12 @@ namespace Zigurous.Tweening public static class SpriteShapeRendererTweens { public static Tween TweenColor(this SpriteShapeRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.color, - setter: color => renderer.color = color, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(renderer); public static Tween TweenAlpha(this SpriteShapeRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.color.a, - setter: alpha => renderer.color = new Color(renderer.color.r, renderer.color.g, renderer.color.b, alpha), - to, duration).SetTarget(renderer); - + Tweening.To(renderer, (target) => target.color.a, (target, value) => target.color = new Color(target.color.r, target.color.g, target.color.b, value), to, duration) + .SetReference(renderer); } } diff --git a/Runtime/Extensions/Rendering/TilemapTweens.cs b/Runtime/Extensions/Rendering/TilemapTweens.cs index 121b71b..a5253a2 100644 --- a/Runtime/Extensions/Rendering/TilemapTweens.cs +++ b/Runtime/Extensions/Rendering/TilemapTweens.cs @@ -6,30 +6,24 @@ namespace Zigurous.Tweening public static class TilemapTweens { public static Tween TweenColor(this Tilemap tilemap, Color to, float duration) => - Tweening.To(getter: () => tilemap.color, - setter: color => tilemap.color = color, - to, duration).SetTarget(tilemap); + Tweening.To(tilemap, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(tilemap); public static Tween TweenOrigin(this Tilemap tilemap, Vector3Int to, float duration) => - Tweening.To(getter: () => tilemap.origin, - setter: origin => tilemap.origin = origin, - to, duration).SetTarget(tilemap); + Tweening.To(tilemap, (target) => target.origin, (target, value) => target.origin = value, to, duration) + .SetReference(tilemap); public static Tween TweenSize(this Tilemap tilemap, Vector3Int to, float duration) => - Tweening.To(getter: () => tilemap.size, - setter: size => tilemap.size = size, - to, duration).SetTarget(tilemap); + Tweening.To(tilemap, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(tilemap); public static Tween TweenTileAnchor(this Tilemap tilemap, Vector3 to, float duration) => - Tweening.To(getter: () => tilemap.tileAnchor, - setter: tileAnchor => tilemap.tileAnchor = tileAnchor, - to, duration).SetTarget(tilemap); + Tweening.To(tilemap, (target) => target.tileAnchor, (target, value) => target.tileAnchor = value, to, duration) + .SetReference(tilemap); public static Tween TweenAnimationFrameRate(this Tilemap tilemap, float to, float duration) => - Tweening.To(getter: () => tilemap.animationFrameRate, - setter: animationFrameRate => tilemap.animationFrameRate = animationFrameRate, - to, duration).SetTarget(tilemap); - + Tweening.To(tilemap, (target) => target.animationFrameRate, (target, value) => target.animationFrameRate = value, to, duration) + .SetReference(tilemap); } } diff --git a/Runtime/Extensions/Rendering/TrailRendererTweens.cs b/Runtime/Extensions/Rendering/TrailRendererTweens.cs index a2a8003..60a35f6 100644 --- a/Runtime/Extensions/Rendering/TrailRendererTweens.cs +++ b/Runtime/Extensions/Rendering/TrailRendererTweens.cs @@ -5,45 +5,36 @@ namespace Zigurous.Tweening public static class TrailRendererTweens { public static Tween TweenTime(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.time, - setter: time => renderer.time = time, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.time, (target, value) => target.time = value, to, duration) + .SetReference(renderer); public static Tween TweenStartColor(this TrailRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.startColor, - setter: startColor => renderer.startColor = startColor, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.startColor, (target, value) => target.startColor = value, to, duration) + .SetReference(renderer); public static Tween TweenEndColor(this TrailRenderer renderer, Color to, float duration) => - Tweening.To(getter: () => renderer.endColor, - setter: endColor => renderer.endColor = endColor, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.endColor, (target, value) => target.endColor = value, to, duration) + .SetReference(renderer); public static Tween TweenStartWidth(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.startWidth, - setter: startWidth => renderer.startWidth = startWidth, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.startWidth, (target, value) => target.startWidth = value, to, duration) + .SetReference(renderer); public static Tween TweenEndWidth(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.endWidth, - setter: endWidth => renderer.endWidth = endWidth, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.endWidth, (target, value) => target.endWidth = value, to, duration) + .SetReference(renderer); public static Tween TweenWidthMultiplier(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.widthMultiplier, - setter: widthMultiplier => renderer.widthMultiplier = widthMultiplier, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.widthMultiplier, (target, value) => target.widthMultiplier = value, to, duration) + .SetReference(renderer); public static Tween TweenShadowBias(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.shadowBias, - setter: shadowBias => renderer.shadowBias = shadowBias, - to, duration).SetTarget(renderer); + Tweening.To(renderer, (target) => target.shadowBias, (target, value) => target.shadowBias = value, to, duration) + .SetReference(renderer); public static Tween TweenMinVertexDistance(this TrailRenderer renderer, float to, float duration) => - Tweening.To(getter: () => renderer.minVertexDistance, - setter: minVertexDistance => renderer.minVertexDistance = minVertexDistance, - to, duration).SetTarget(renderer); - + Tweening.To(renderer, (target) => target.minVertexDistance, (target, value) => target.minVertexDistance = value, to, duration) + .SetReference(renderer); } } diff --git a/Runtime/Extensions/Rendering/VideoPlayerTweens.cs b/Runtime/Extensions/Rendering/VideoPlayerTweens.cs index b45e9a0..0975b18 100644 --- a/Runtime/Extensions/Rendering/VideoPlayerTweens.cs +++ b/Runtime/Extensions/Rendering/VideoPlayerTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class VideoPlayerTweens { public static Tween TweenFrame(this VideoPlayer videoPlayer, long to, float duration) => - Tweening.To(getter: () => videoPlayer.frame, - setter: frame => videoPlayer.frame = frame, - to, duration).SetTarget(videoPlayer); + Tweening.To(videoPlayer, (target) => target.frame, (target, value) => target.frame = value, to, duration) + .SetReference(videoPlayer); public static Tween TweenTime(this VideoPlayer videoPlayer, double to, float duration) => - Tweening.To(getter: () => videoPlayer.time, - setter: time => videoPlayer.time = time, - to, duration).SetTarget(videoPlayer); + Tweening.To(videoPlayer, (target) => target.time, (target, value) => target.time = value, to, duration) + .SetReference(videoPlayer); public static Tween TweenPlaybackSpeed(this VideoPlayer videoPlayer, float to, float duration) => - Tweening.To(getter: () => videoPlayer.playbackSpeed, - setter: playbackSpeed => videoPlayer.playbackSpeed = playbackSpeed, - to, duration).SetTarget(videoPlayer); + Tweening.To(videoPlayer, (target) => target.playbackSpeed, (target, value) => target.playbackSpeed = value, to, duration) + .SetReference(videoPlayer); public static Tween TweenExternalReferenceTime(this VideoPlayer videoPlayer, double to, float duration) => - Tweening.To(getter: () => videoPlayer.externalReferenceTime, - setter: externalReferenceTime => videoPlayer.externalReferenceTime = externalReferenceTime, - to, duration).SetTarget(videoPlayer); + Tweening.To(videoPlayer, (target) => target.externalReferenceTime, (target, value) => target.externalReferenceTime = value, to, duration) + .SetReference(videoPlayer); public static Tween TweenTargetCameraAlpha(this VideoPlayer videoPlayer, float to, float duration) => - Tweening.To(getter: () => videoPlayer.targetCameraAlpha, - setter: targetCameraAlpha => videoPlayer.targetCameraAlpha = targetCameraAlpha, - to, duration).SetTarget(videoPlayer); - + Tweening.To(videoPlayer, (target) => target.targetCameraAlpha, (target, value) => target.targetCameraAlpha = value, to, duration) + .SetReference(videoPlayer); } } diff --git a/Runtime/Extensions/Rendering/WindZoneTweens.cs b/Runtime/Extensions/Rendering/WindZoneTweens.cs index 2461a00..2a674d0 100644 --- a/Runtime/Extensions/Rendering/WindZoneTweens.cs +++ b/Runtime/Extensions/Rendering/WindZoneTweens.cs @@ -5,30 +5,24 @@ namespace Zigurous.Tweening public static class WindZoneTweens { public static Tween TweenRadius(this WindZone windZone, float to, float duration) => - Tweening.To(getter: () => windZone.radius, - setter: radius => windZone.radius = radius, - to, duration).SetTarget(windZone); + Tweening.To(windZone, (target) => target.radius, (target, value) => target.radius = value, to, duration) + .SetReference(windZone); public static Tween TweenWindMain(this WindZone windZone, float to, float duration) => - Tweening.To(getter: () => windZone.windMain, - setter: windMain => windZone.windMain = windMain, - to, duration).SetTarget(windZone); + Tweening.To(windZone, (target) => target.windMain, (target, value) => target.windMain = value, to, duration) + .SetReference(windZone); public static Tween TweenWindTurbulence(this WindZone windZone, float to, float duration) => - Tweening.To(getter: () => windZone.windTurbulence, - setter: windTurbulence => windZone.windTurbulence = windTurbulence, - to, duration).SetTarget(windZone); + Tweening.To(windZone, (target) => target.windTurbulence, (target, value) => target.windTurbulence = value, to, duration) + .SetReference(windZone); public static Tween TweenWindPulseMagnitude(this WindZone windZone, float to, float duration) => - Tweening.To(getter: () => windZone.windPulseMagnitude, - setter: windPulseMagnitude => windZone.windPulseMagnitude = windPulseMagnitude, - to, duration).SetTarget(windZone); + Tweening.To(windZone, (target) => target.windPulseMagnitude, (target, value) => target.windPulseMagnitude = value, to, duration) + .SetReference(windZone); public static Tween TweenWindPulseFrequency(this WindZone windZone, float to, float duration) => - Tweening.To(getter: () => windZone.windPulseFrequency, - setter: windPulseFrequency => windZone.windPulseFrequency = windPulseFrequency, - to, duration).SetTarget(windZone); - + Tweening.To(windZone, (target) => target.windPulseFrequency, (target, value) => target.windPulseFrequency = value, to, duration) + .SetReference(windZone); } } diff --git a/Runtime/Extensions/UI/AspectRatioFitterTweens.cs b/Runtime/Extensions/UI/AspectRatioFitterTweens.cs index 714e540..1067095 100644 --- a/Runtime/Extensions/UI/AspectRatioFitterTweens.cs +++ b/Runtime/Extensions/UI/AspectRatioFitterTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class AspectRatioFitterTweens { public static Tween TweenAspectRatio(this AspectRatioFitter fitter, float to, float duration) => - Tweening.To(getter: () => fitter.aspectRatio, - setter: aspectRatio => fitter.aspectRatio = aspectRatio, - to, duration).SetTarget(fitter); - + Tweening.To(fitter, (target) => target.aspectRatio, (target, value) => target.aspectRatio = value, to, duration) + .SetReference(fitter); } } diff --git a/Runtime/Extensions/UI/CanvasGroupTweens.cs b/Runtime/Extensions/UI/CanvasGroupTweens.cs index 86c50d4..c4666be 100644 --- a/Runtime/Extensions/UI/CanvasGroupTweens.cs +++ b/Runtime/Extensions/UI/CanvasGroupTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class CanvasGroupTweens { public static Tween TweenAlpha(this CanvasGroup canvasGroup, float to, float duration) => - Tweening.To(getter: () => canvasGroup.alpha, - setter: alpha => canvasGroup.alpha = alpha, - to, duration).SetTarget(canvasGroup); - + Tweening.To(canvasGroup, (target) => target.alpha, (target, value) => target.alpha = value, to, duration) + .SetReference(canvasGroup); } } diff --git a/Runtime/Extensions/UI/CanvasScalerTweens.cs b/Runtime/Extensions/UI/CanvasScalerTweens.cs index 3c41d58..489505c 100644 --- a/Runtime/Extensions/UI/CanvasScalerTweens.cs +++ b/Runtime/Extensions/UI/CanvasScalerTweens.cs @@ -6,40 +6,32 @@ namespace Zigurous.Tweening public static class CanvasScalerTweens { public static Tween TweenScaleFactor(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.scaleFactor, - setter: scaleFactor => scaler.scaleFactor = scaleFactor, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.scaleFactor, (target, value) => target.scaleFactor = value, to, duration) + .SetReference(scaler); public static Tween TweenReferenceResolution(this CanvasScaler scaler, Vector2 to, float duration) => - Tweening.To(getter: () => scaler.referenceResolution, - setter: referenceResolution => scaler.referenceResolution = referenceResolution, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.referenceResolution, (target, value) => target.referenceResolution = value, to, duration) + .SetReference(scaler); public static Tween TweenMatchWidthOrHeight(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.matchWidthOrHeight, - setter: matchWidthOrHeight => scaler.matchWidthOrHeight = matchWidthOrHeight, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.matchWidthOrHeight, (target, value) => target.matchWidthOrHeight = value, to, duration) + .SetReference(scaler); public static Tween TweenDefaultSpriteDPI(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.defaultSpriteDPI, - setter: defaultSpriteDPI => scaler.defaultSpriteDPI = defaultSpriteDPI, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.defaultSpriteDPI, (target, value) => target.defaultSpriteDPI = value, to, duration) + .SetReference(scaler); public static Tween TweenFallbackScreenDPI(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.fallbackScreenDPI, - setter: fallbackScreenDPI => scaler.fallbackScreenDPI = fallbackScreenDPI, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.fallbackScreenDPI, (target, value) => target.fallbackScreenDPI = value, to, duration) + .SetReference(scaler); public static Tween TweenDynamicPixelsPerUnit(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.dynamicPixelsPerUnit, - setter: dynamicPixelsPerUnit => scaler.dynamicPixelsPerUnit = dynamicPixelsPerUnit, - to, duration).SetTarget(scaler); + Tweening.To(scaler, (target) => target.dynamicPixelsPerUnit, (target, value) => target.dynamicPixelsPerUnit = value, to, duration) + .SetReference(scaler); public static Tween TweenReferencePixelsPerUnit(this CanvasScaler scaler, float to, float duration) => - Tweening.To(getter: () => scaler.referencePixelsPerUnit, - setter: referencePixelsPerUnit => scaler.referencePixelsPerUnit = referencePixelsPerUnit, - to, duration).SetTarget(scaler); - + Tweening.To(scaler, (target) => target.referencePixelsPerUnit, (target, value) => target.referencePixelsPerUnit = value, to, duration) + .SetReference(scaler); } } diff --git a/Runtime/Extensions/UI/CanvasTweens.cs b/Runtime/Extensions/UI/CanvasTweens.cs index a2612f8..5f0a676 100644 --- a/Runtime/Extensions/UI/CanvasTweens.cs +++ b/Runtime/Extensions/UI/CanvasTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class CanvasTweens { public static Tween TweenScaleFactor(this Canvas canvas, float to, float duration) => - Tweening.To(getter: () => canvas.scaleFactor, - setter: scaleFactor => canvas.scaleFactor = scaleFactor, - to, duration).SetTarget(canvas); + Tweening.To(canvas, (target) => target.scaleFactor, (target, value) => target.scaleFactor = value, to, duration) + .SetReference(canvas); public static Tween TweenPlaneDistance(this Canvas canvas, float to, float duration) => - Tweening.To(getter: () => canvas.planeDistance, - setter: planeDistance => canvas.planeDistance = planeDistance, - to, duration).SetTarget(canvas); + Tweening.To(canvas, (target) => target.planeDistance, (target, value) => target.planeDistance = value, to, duration) + .SetReference(canvas); public static Tween TweenReferencePixelsPerUnit(this Canvas canvas, float to, float duration) => - Tweening.To(getter: () => canvas.referencePixelsPerUnit, - setter: referencePixelsPerUnit => canvas.referencePixelsPerUnit = referencePixelsPerUnit, - to, duration).SetTarget(canvas); + Tweening.To(canvas, (target) => target.referencePixelsPerUnit, (target, value) => target.referencePixelsPerUnit = value, to, duration) + .SetReference(canvas); public static Tween TweenNormalizedSortingGridSize(this Canvas canvas, float to, float duration) => - Tweening.To(getter: () => canvas.normalizedSortingGridSize, - setter: normalizedSortingGridSize => canvas.normalizedSortingGridSize = normalizedSortingGridSize, - to, duration).SetTarget(canvas); - + Tweening.To(canvas, (target) => target.normalizedSortingGridSize, (target, value) => target.normalizedSortingGridSize = value, to, duration) + .SetReference(canvas); } } diff --git a/Runtime/Extensions/UI/GraphicTweens.cs b/Runtime/Extensions/UI/GraphicTweens.cs index 81f62a0..0d9ce9c 100644 --- a/Runtime/Extensions/UI/GraphicTweens.cs +++ b/Runtime/Extensions/UI/GraphicTweens.cs @@ -6,15 +6,12 @@ namespace Zigurous.Tweening public static class GraphicTweens { public static Tween TweenColor(this Graphic graphic, Color to, float duration) => - Tweening.To(getter: () => graphic.color, - setter: color => graphic.color = color, - to, duration).SetTarget(graphic); + Tweening.To(graphic, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(graphic); public static Tween TweenAlpha(this Graphic graphic, float to, float duration) => - Tweening.To(getter: () => graphic.color.a, - setter: alpha => graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, alpha), - to, duration).SetTarget(graphic); - + Tweening.To(graphic, (target) => target.color.a, (target, value) => target.color = new Color(target.color.r, target.color.g, target.color.b, value), to, duration) + .SetReference(graphic); } } diff --git a/Runtime/Extensions/UI/GridLayoutGroupTweens.cs b/Runtime/Extensions/UI/GridLayoutGroupTweens.cs index 2f95207..acb9a22 100644 --- a/Runtime/Extensions/UI/GridLayoutGroupTweens.cs +++ b/Runtime/Extensions/UI/GridLayoutGroupTweens.cs @@ -6,15 +6,12 @@ namespace Zigurous.Tweening public static class GridLayoutGroupTweens { public static Tween TweenSpacing(this GridLayoutGroup layoutGroup, Vector2 to, float duration) => - Tweening.To(getter: () => layoutGroup.spacing, - setter: spacing => layoutGroup.spacing = spacing, - to, duration).SetTarget(layoutGroup); + Tweening.To(layoutGroup, (target) => target.spacing, (target, value) => target.spacing = value, to, duration) + .SetReference(layoutGroup); public static Tween TweenCellSize(this GridLayoutGroup layoutGroup, Vector2 to, float duration) => - Tweening.To(getter: () => layoutGroup.cellSize, - setter: cellSize => layoutGroup.cellSize = cellSize, - to, duration).SetTarget(layoutGroup); - + Tweening.To(layoutGroup, (target) => target.cellSize, (target, value) => target.cellSize = value, to, duration) + .SetReference(layoutGroup); } } diff --git a/Runtime/Extensions/UI/HorizontalOrVerticalLayoutGroupTweens.cs b/Runtime/Extensions/UI/HorizontalOrVerticalLayoutGroupTweens.cs index 8873aa3..6a6bf65 100644 --- a/Runtime/Extensions/UI/HorizontalOrVerticalLayoutGroupTweens.cs +++ b/Runtime/Extensions/UI/HorizontalOrVerticalLayoutGroupTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class HorizontalOrVerticalLayoutGroupTweens { public static Tween TweenSpacing(this HorizontalOrVerticalLayoutGroup layoutGroup, float to, float duration) => - Tweening.To(getter: () => layoutGroup.spacing, - setter: spacing => layoutGroup.spacing = spacing, - to, duration).SetTarget(layoutGroup); - + Tweening.To(layoutGroup, (target) => target.spacing, (target, value) => target.spacing = value, to, duration) + .SetReference(layoutGroup); } } diff --git a/Runtime/Extensions/UI/RectMask2DTweens.cs b/Runtime/Extensions/UI/RectMask2DTweens.cs index f66370f..d7cbf98 100644 --- a/Runtime/Extensions/UI/RectMask2DTweens.cs +++ b/Runtime/Extensions/UI/RectMask2DTweens.cs @@ -6,15 +6,12 @@ namespace Zigurous.Tweening public static class RectMask2DTweens { public static Tween TweenPadding(this RectMask2D mask, Vector4 to, float duration) => - Tweening.To(getter: () => mask.padding, - setter: padding => mask.padding = padding, - to, duration).SetTarget(mask); + Tweening.To(mask, (target) => target.padding, (target, value) => target.padding = value, to, duration) + .SetReference(mask); public static Tween TweenSoftness(this RectMask2D mask, Vector2Int to, float duration) => - Tweening.To(getter: () => mask.softness, - setter: softness => mask.softness = softness, - to, duration).SetTarget(mask); - + Tweening.To(mask, (target) => target.softness, (target, value) => target.softness = value, to, duration) + .SetReference(mask); } } diff --git a/Runtime/Extensions/UI/RectTransformTweens.cs b/Runtime/Extensions/UI/RectTransformTweens.cs index 3cb1605..b2d2e65 100644 --- a/Runtime/Extensions/UI/RectTransformTweens.cs +++ b/Runtime/Extensions/UI/RectTransformTweens.cs @@ -5,45 +5,36 @@ namespace Zigurous.Tweening public static class RectTransformTweens { public static Tween TweenAnchoredPosition(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.anchoredPosition, - setter: anchoredPosition => transform.anchoredPosition = anchoredPosition, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.anchoredPosition, (target, value) => target.anchoredPosition = value, to, duration) + .SetReference(transform); public static Tween TweenAnchoredPosition3D(this RectTransform transform, Vector3 to, float duration) => - Tweening.To(getter: () => transform.anchoredPosition3D, - setter: anchoredPosition3D => transform.anchoredPosition3D = anchoredPosition3D, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.anchoredPosition3D, (target, value) => target.anchoredPosition3D = value, to, duration) + .SetReference(transform); public static Tween TweenAnchorMin(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.anchorMin, - setter: anchorMin => transform.anchorMin = anchorMin, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.anchorMin, (target, value) => target.anchorMin = value, to, duration) + .SetReference(transform); public static Tween TweenAnchorMax(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.anchorMax, - setter: anchorMax => transform.anchorMax = anchorMax, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.anchorMax, (target, value) => target.anchorMax = value, to, duration) + .SetReference(transform); public static Tween TweenOffsetMin(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.offsetMin, - setter: offsetMin => transform.offsetMin = offsetMin, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.offsetMin, (target, value) => target.offsetMin = value, to, duration) + .SetReference(transform); public static Tween TweenOffsetMax(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.offsetMax, - setter: offsetMax => transform.offsetMax = offsetMax, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.offsetMax, (target, value) => target.offsetMax = value, to, duration) + .SetReference(transform); public static Tween TweenPivot(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.pivot, - setter: pivot => transform.pivot = pivot, - to, duration).SetTarget(transform); + Tweening.To(transform, (target) => target.pivot, (target, value) => target.pivot = value, to, duration) + .SetReference(transform); public static Tween TweenSizeDelta(this RectTransform transform, Vector2 to, float duration) => - Tweening.To(getter: () => transform.sizeDelta, - setter: sizeDelta => transform.sizeDelta = sizeDelta, - to, duration).SetTarget(transform); - + Tweening.To(transform, (target) => target.sizeDelta, (target, value) => target.sizeDelta = value, to, duration) + .SetReference(transform); } } diff --git a/Runtime/Extensions/UI/ScrollRectTweens.cs b/Runtime/Extensions/UI/ScrollRectTweens.cs index 27cb7e8..8eb2a62 100644 --- a/Runtime/Extensions/UI/ScrollRectTweens.cs +++ b/Runtime/Extensions/UI/ScrollRectTweens.cs @@ -6,50 +6,40 @@ namespace Zigurous.Tweening public static class ScrollRectTweens { public static Tween TweenElasticity(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.elasticity, - setter: elasticity => scrollRect.elasticity = elasticity, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.elasticity, (target, value) => target.elasticity = value, to, duration) + .SetReference(scrollRect); public static Tween TweenDecelerationRate(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.decelerationRate, - setter: decelerationRate => scrollRect.decelerationRate = decelerationRate, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.decelerationRate, (target, value) => target.decelerationRate = value, to, duration) + .SetReference(scrollRect); public static Tween TweenScrollSensitivity(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.scrollSensitivity, - setter: scrollSensitivity => scrollRect.scrollSensitivity = scrollSensitivity, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.scrollSensitivity, (target, value) => target.scrollSensitivity = value, to, duration) + .SetReference(scrollRect); public static Tween TweenVelocity(this ScrollRect scrollRect, Vector2 to, float duration) => - Tweening.To(getter: () => scrollRect.velocity, - setter: velocity => scrollRect.velocity = velocity, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.velocity, (target, value) => target.velocity = value, to, duration) + .SetReference(scrollRect); public static Tween TweenNormalizedPosition(this ScrollRect scrollRect, Vector2 to, float duration) => - Tweening.To(getter: () => scrollRect.normalizedPosition, - setter: normalizedPosition => scrollRect.normalizedPosition = normalizedPosition, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.normalizedPosition, (target, value) => target.normalizedPosition = value, to, duration) + .SetReference(scrollRect); public static Tween TweenHorizontalNormalizedPosition(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.horizontalNormalizedPosition, - setter: position => scrollRect.horizontalNormalizedPosition = position, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.horizontalNormalizedPosition, (target, value) => target.horizontalNormalizedPosition = value, to, duration) + .SetReference(scrollRect); public static Tween TweenVerticalNormalizedPosition(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.verticalNormalizedPosition, - setter: position => scrollRect.verticalNormalizedPosition = position, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.verticalNormalizedPosition, (target, value) => target.verticalNormalizedPosition = value, to, duration) + .SetReference(scrollRect); public static Tween TweenHorizontalScrollbarSpacing(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.horizontalScrollbarSpacing, - setter: spacing => scrollRect.horizontalScrollbarSpacing = spacing, - to, duration).SetTarget(scrollRect); + Tweening.To(scrollRect, (target) => target.horizontalScrollbarSpacing, (target, value) => target.horizontalScrollbarSpacing = value, to, duration) + .SetReference(scrollRect); public static Tween TweenVerticalScrollbarSpacing(this ScrollRect scrollRect, float to, float duration) => - Tweening.To(getter: () => scrollRect.verticalScrollbarSpacing, - setter: spacing => scrollRect.verticalScrollbarSpacing = spacing, - to, duration).SetTarget(scrollRect); - + Tweening.To(scrollRect, (target) => target.verticalScrollbarSpacing, (target, value) => target.verticalScrollbarSpacing = value, to, duration) + .SetReference(scrollRect); } } diff --git a/Runtime/Extensions/UI/ScrollbarTweens.cs b/Runtime/Extensions/UI/ScrollbarTweens.cs index 028a902..cb436b8 100644 --- a/Runtime/Extensions/UI/ScrollbarTweens.cs +++ b/Runtime/Extensions/UI/ScrollbarTweens.cs @@ -5,15 +5,12 @@ namespace Zigurous.Tweening public static class ScrollbarTweens { public static Tween TweenValue(this Scrollbar scrollbar, float to, float duration) => - Tweening.To(getter: () => scrollbar.value, - setter: value => scrollbar.value = value, - to, duration).SetTarget(scrollbar); + Tweening.To(scrollbar, (target) => target.value, (target, value) => target.value = value, to, duration) + .SetReference(scrollbar); public static Tween TweenSize(this Scrollbar scrollbar, float to, float duration) => - Tweening.To(getter: () => scrollbar.size, - setter: size => scrollbar.size = size, - to, duration).SetTarget(scrollbar); - + Tweening.To(scrollbar, (target) => target.size, (target, value) => target.size = value, to, duration) + .SetReference(scrollbar); } } diff --git a/Runtime/Extensions/UI/ShadowTweens.cs b/Runtime/Extensions/UI/ShadowTweens.cs index 880c0b6..7519125 100644 --- a/Runtime/Extensions/UI/ShadowTweens.cs +++ b/Runtime/Extensions/UI/ShadowTweens.cs @@ -5,16 +5,17 @@ namespace Zigurous.Tweening { public static class ShadowTweens { - public static Tween TweenEffectColor(this Shadow shadow, Color to, float duration) => - Tweening.To(getter: () => shadow.effectColor, - setter: effectColor => shadow.effectColor = effectColor, - to, duration).SetTarget(shadow); + public static Tween TweenColor(this Shadow shadow, Color to, float duration) => + Tweening.To(shadow, (target) => target.effectColor, (target, value) => target.effectColor = value, to, duration) + .SetReference(shadow); - public static Tween TweenEffectDistance(this Shadow shadow, Vector2 to, float duration) => - Tweening.To(getter: () => shadow.effectDistance, - setter: effectDistance => shadow.effectDistance = effectDistance, - to, duration).SetTarget(shadow); + public static Tween TweenAlpha(this Shadow shadow, float to, float duration) => + Tweening.To(shadow, (target) => target.effectColor.a, (target, value) => target.effectColor = new Color(target.effectColor.r, target.effectColor.g, target.effectColor.b, value), to, duration) + .SetReference(shadow); + public static Tween TweenDistance(this Shadow shadow, Vector2 to, float duration) => + Tweening.To(shadow, (target) => target.effectDistance, (target, value) => target.effectDistance = value, to, duration) + .SetReference(shadow); } } diff --git a/Runtime/Extensions/UI/SliderTweens.cs b/Runtime/Extensions/UI/SliderTweens.cs index 5c99549..5749b57 100644 --- a/Runtime/Extensions/UI/SliderTweens.cs +++ b/Runtime/Extensions/UI/SliderTweens.cs @@ -5,25 +5,20 @@ namespace Zigurous.Tweening public static class SliderTweens { public static Tween TweenValue(this Slider slider, float to, float duration) => - Tweening.To(getter: () => slider.value, - setter: value => slider.value = value, - to, duration).SetTarget(slider); + Tweening.To(slider, (target) => target.value, (target, value) => target.value = value, to, duration) + .SetReference(slider); public static Tween TweenNormalizedValue(this Slider slider, float to, float duration) => - Tweening.To(getter: () => slider.normalizedValue, - setter: normalizedValue => slider.normalizedValue = normalizedValue, - to, duration).SetTarget(slider); + Tweening.To(slider, (target) => target.normalizedValue, (target, value) => target.normalizedValue = value, to, duration) + .SetReference(slider); public static Tween TweenMinValue(this Slider slider, float to, float duration) => - Tweening.To(getter: () => slider.minValue, - setter: minValue => slider.minValue = minValue, - to, duration).SetTarget(slider); + Tweening.To(slider, (target) => target.minValue, (target, value) => target.minValue = value, to, duration) + .SetReference(slider); public static Tween TweenMaxValue(this Slider slider, float to, float duration) => - Tweening.To(getter: () => slider.maxValue, - setter: maxValue => slider.maxValue = maxValue, - to, duration).SetTarget(slider); - + Tweening.To(slider, (target) => target.maxValue, (target, value) => target.maxValue = value, to, duration) + .SetReference(slider); } } diff --git a/Runtime/Extensions/UI/TextMeshTweens.cs b/Runtime/Extensions/UI/TextMeshTweens.cs index 03c5acc..1121ebe 100644 --- a/Runtime/Extensions/UI/TextMeshTweens.cs +++ b/Runtime/Extensions/UI/TextMeshTweens.cs @@ -5,40 +5,32 @@ namespace Zigurous.Tweening public static class TextMeshTweens { public static Tween TweenColor(this TextMesh textMesh, Color to, float duration) => - Tweening.To(getter: () => textMesh.color, - setter: color => textMesh.color = color, - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.color, (target, value) => target.color = value, to, duration) + .SetReference(textMesh); public static Tween TweenAlpha(this TextMesh textMesh, float to, float duration) => - Tweening.To(getter: () => textMesh.color.a, - setter: alpha => textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, alpha), - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.color.a, (target, value) => target.color = new Color(target.color.r, target.color.g, target.color.b, value), to, duration) + .SetReference(textMesh); public static Tween TweenFontSize(this TextMesh textMesh, int to, float duration) => - Tweening.To(getter: () => textMesh.fontSize, - setter: fontSize => textMesh.fontSize = fontSize, - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.fontSize, (target, value) => target.fontSize = value, to, duration) + .SetReference(textMesh); public static Tween TweenOffsetZ(this TextMesh textMesh, float to, float duration) => - Tweening.To(getter: () => textMesh.offsetZ, - setter: offsetZ => textMesh.offsetZ = offsetZ, - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.offsetZ, (target, value) => target.offsetZ = value, to, duration) + .SetReference(textMesh); public static Tween TweenCharacterSize(this TextMesh textMesh, float to, float duration) => - Tweening.To(getter: () => textMesh.characterSize, - setter: characterSize => textMesh.characterSize = characterSize, - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.characterSize, (target, value) => target.characterSize = value, to, duration) + .SetReference(textMesh); public static Tween TweenLineSpacing(this TextMesh textMesh, float to, float duration) => - Tweening.To(getter: () => textMesh.lineSpacing, - setter: lineSpacing => textMesh.lineSpacing = lineSpacing, - to, duration).SetTarget(textMesh); + Tweening.To(textMesh, (target) => target.lineSpacing, (target, value) => target.lineSpacing = value, to, duration) + .SetReference(textMesh); public static Tween TweenTabSize(this TextMesh textMesh, float to, float duration) => - Tweening.To(getter: () => textMesh.tabSize, - setter: tabSize => textMesh.tabSize = tabSize, - to, duration).SetTarget(textMesh); - + Tweening.To(textMesh, (target) => target.tabSize, (target, value) => target.tabSize = value, to, duration) + .SetReference(textMesh); } } diff --git a/Runtime/Extensions/UI/TextTweens.cs b/Runtime/Extensions/UI/TextTweens.cs index bb4a1a9..688aa43 100644 --- a/Runtime/Extensions/UI/TextTweens.cs +++ b/Runtime/Extensions/UI/TextTweens.cs @@ -5,10 +5,8 @@ namespace Zigurous.Tweening public static class TextTweens { public static Tween TweenFontSize(this Text text, int to, float duration) => - Tweening.To(getter: () => text.fontSize, - setter: fontSize => text.fontSize = fontSize, - to, duration).SetTarget(text); - + Tweening.To(text, (target) => target.fontSize, (target, value) => target.fontSize = value, to, duration) + .SetReference(text); } } diff --git a/Runtime/ITweenEventHandler.cs b/Runtime/ITweenEventHandler.cs new file mode 100644 index 0000000..42366f0 --- /dev/null +++ b/Runtime/ITweenEventHandler.cs @@ -0,0 +1,46 @@ +namespace Zigurous.Tweening +{ + /// + /// A type that responds to tween lifecycle events. + /// + public interface ITweenEventHandler + { + /// + /// An event invoked every time the tween is updated, i.e., any time the + /// parameter being animated is changed. + /// + /// The tween that invoked the event. + void OnTweenUpdate(Tween tween); + + /// + /// An event invoked when the tween is started. + /// + /// The tween that invoked the event. + void OnTweenStart(Tween tween); + + /// + /// An event invoked when the tween is stopped. + /// + /// The tween that invoked the event. + void OnTweenStop(Tween tween); + + /// + /// An event invoked when the tween is looped. + /// + /// The tween that invoked the event. + void OnTweenLoop(Tween tween); + + /// + /// An event invoked when the tween is completed. + /// + /// The tween that invoked the event. + void OnTweenComplete(Tween tween); + + /// + /// An event invoked when the tween is killed. + /// + /// The tween that invoked the event. + void OnTweenKill(Tween tween); + } + +} diff --git a/Runtime/ITweenEventHandler.cs.meta b/Runtime/ITweenEventHandler.cs.meta new file mode 100644 index 0000000..e8cd905 --- /dev/null +++ b/Runtime/ITweenEventHandler.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 023846bfd8af34743afd4f4f27045458 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Interpolation.cs b/Runtime/Interpolation.cs index 93c17fd..7afd4b4 100644 --- a/Runtime/Interpolation.cs +++ b/Runtime/Interpolation.cs @@ -7,6 +7,20 @@ namespace Zigurous.Tweening /// public static class Interpolation { + internal static readonly Interpolater _float = Lerp; + internal static readonly Interpolater _double = Lerp; + internal static readonly Interpolater _int = Lerp; + internal static readonly Interpolater _long = Lerp; + internal static readonly Interpolater _short = Lerp; + internal static readonly Interpolater _Vector2 = Lerp; + internal static readonly Interpolater _Vector2Int = Lerp; + internal static readonly Interpolater _Vector3 = Lerp; + internal static readonly Interpolater _Vector3Int = Lerp; + internal static readonly Interpolater _Vector4 = Lerp; + internal static readonly Interpolater _Quaternion = Lerp; + internal static readonly Interpolater _Rect = Lerp; + internal static readonly Interpolater _Color = Lerp; + /// /// Linearly interpolates between and /// by . @@ -18,8 +32,8 @@ public static class Interpolation /// The interpolated value between the start and end value. public static float Lerp(float a, float b, float t, bool snapping = false) { - float value = Mathf.Lerp(a, b, t); - return snapping ? (int)value : value; + float value = a + (b - a) * t; + return snapping ? Mathf.Round(value) : value; } /// @@ -33,8 +47,8 @@ public static float Lerp(float a, float b, float t, bool snapping = false) /// The interpolated value between the start and end value. public static double Lerp(double a, double b, float t, bool snapping = false) { - double value = Mathf.Lerp((float)a, (float)b, t); - return snapping ? (int)value : value; + double value = a + (b - a) * t; + return snapping ? System.Math.Round(value) : value; } /// @@ -48,7 +62,7 @@ public static double Lerp(double a, double b, float t, bool snapping = false) /// The interpolated value between the start and end value. public static int Lerp(int a, int b, float t, bool snapping = false) { - return (int)Mathf.Lerp(a, b, t); + return (int)Lerp((float)a, (float)b, t, snapping); } /// @@ -62,8 +76,21 @@ public static int Lerp(int a, int b, float t, bool snapping = false) /// The interpolated value between the start and end value. public static long Lerp(long a, long b, float t, bool snapping = false) { - long value = (long)Mathf.Lerp(a, b, t); - return snapping ? (int)value : value; + return (long)Lerp((double)a, (double)b, t, snapping); + } + + /// + /// Linearly interpolates between and + /// by . + /// + /// The start value. + /// The end value. + /// The interpolation value between the start and end value. + /// Snaps the interpolated value to the nearest whole number. + /// The interpolated value between the start and end value. + public static short Lerp(short a, short b, float t, bool snapping = false) + { + return (short)Lerp((float)a, (float)b, t, snapping); } /// @@ -93,8 +120,8 @@ public static Vector2 Lerp(Vector2 a, Vector2 b, float t, bool snapping = false) public static Vector2Int Lerp(Vector2Int a, Vector2Int b, float t, bool snapping = false) { return new Vector2Int( - (int)Mathf.Lerp(a.x, b.x, t), - (int)Mathf.Lerp(a.y, b.y, t)); + Lerp(a.x, b.x, t, snapping), + Lerp(a.y, b.y, t, snapping)); } /// @@ -124,9 +151,9 @@ public static Vector3 Lerp(Vector3 a, Vector3 b, float t, bool snapping = false) public static Vector3Int Lerp(Vector3Int a, Vector3Int b, float t, bool snapping = false) { return new Vector3Int( - (int)Mathf.Lerp(a.x, b.x, t), - (int)Mathf.Lerp(a.y, b.y, t), - (int)Mathf.Lerp(a.z, b.z, t)); + Lerp(a.x, b.x, t, snapping), + Lerp(a.y, b.y, t, snapping), + Lerp(a.z, b.z, t, snapping)); } /// @@ -197,7 +224,7 @@ public static Color Lerp(Color a, Color b, float t, bool snapping = false) /// The value snapped to the nearest whole number. internal static Vector2 Snap(Vector2 value) { - return new Vector2(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y)); + return new Vector2(Mathf.Round(value.x), Mathf.Round(value.y)); } /// @@ -207,7 +234,7 @@ internal static Vector2 Snap(Vector2 value) /// The value snapped to the nearest whole number. internal static Vector3 Snap(Vector3 value) { - return new Vector3(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y), Mathf.RoundToInt(value.z)); + return new Vector3(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z)); } /// @@ -217,7 +244,7 @@ internal static Vector3 Snap(Vector3 value) /// The value snapped to the nearest whole number. internal static Vector4 Snap(Vector4 value) { - return new Vector4(Mathf.RoundToInt(value.x), Mathf.RoundToInt(value.y), Mathf.RoundToInt(value.z), Mathf.RoundToInt(value.w)); + return new Vector4(Mathf.Round(value.x), Mathf.Round(value.y), Mathf.Round(value.z), Mathf.Round(value.w)); } /// diff --git a/Runtime/PropertyChaining.cs b/Runtime/PropertyChaining.cs index fa82cd0..8cb7483 100644 --- a/Runtime/PropertyChaining.cs +++ b/Runtime/PropertyChaining.cs @@ -1,5 +1,3 @@ -using UnityEngine; - namespace Zigurous.Tweening { /// @@ -10,38 +8,133 @@ namespace Zigurous.Tweening public static class PropertyChaining { /// - /// Sets the id of the tween to the target component so the tween can be - /// retrieved and destroyed based on that target. + /// Sets the target object of the tween. + /// + /// The type of object being tweened. + /// The type of parameter being tweened. + /// The tween to assign the target to. + /// The target object to tween. + /// The tween itself to allow for chaining. + public static Tweener SetTarget(this Tweener tween, T target) + { + if (tween != null) + { + tween.target = target; + + if (target is UnityEngine.Component component) { + SetReference(tween, component); + } else if (target is UnityEngine.GameObject gameObject) { + SetReference(tween, gameObject); + } else if (target is UnityEngine.Object obj) { + SetReference(tween, obj); + } + } + + return tween; + } + + /// + /// Sets the getter function of the tween. + /// + /// The type of object being tweened. + /// The type of parameter being tweened. + /// The tween to assign the getter to. + /// The getter function to set. + /// The tween itself to allow for chaining. + public static Tweener SetGetter(this Tweener tween, TweenGetter getter) + { + if (tween != null) { + tween.getter = getter; + } + + return tween; + } + + /// + /// Sets the setter function of the tween. + /// + /// The type of object being tweened. + /// The type of parameter being tweened. + /// The tween to assign the setter to. + /// The setter function to set. + /// The tween itself to allow for chaining. + public static Tweener SetSetter(this Tweener tween, TweenSetter setter) + { + if (tween != null) { + tween.setter = setter; + } + + return tween; + } + + /// + /// Sets the end value of the tween. + /// + /// The type of object being tweened. + /// The type of parameter being tweened. + /// The tween to assign the setter to. + /// The end value to set. + /// The tween itself to allow for chaining. + public static Tweener SetEndValue(this Tweener tween, U endValue) + { + if (tween != null) { + tween.endValue = endValue; + } + + return tween; + } + + /// + /// Sets the id and scene index of the tween to the reference component + /// so the tween can be retrieved and destroyed based on that component. /// /// The type of the tween. - /// The tween to assign the value to. - /// The target component. + /// The tween to assign the reference to. + /// The reference component. /// The tween itself to allow for chaining. - public static T SetTarget(this T tween, Component target) where T: Tween + public static T SetReference(this T tween, UnityEngine.Component reference) where T : Tween { - if (tween != null && target != null) + if (tween != null && reference != null) { - tween.id = target.GetHashCode(); - tween.sceneIndex = target.gameObject.scene.buildIndex; + tween.id = reference.GetInstanceID(); + tween.sceneIndex = reference.gameObject.scene.buildIndex; } return tween; } /// - /// Sets the id of the tween to the target game object so the tween can - /// be retrieved and destroyed based on that game object. + /// Sets the id and scene index of the tween to the reference game + /// object so the tween can be retrieved and destroyed based on that + /// game object. /// /// The type of the tween. - /// The tween to assign the value to. - /// The target component. + /// The tween to assign the reference to. + /// The reference game object. /// The tween itself to allow for chaining. - public static T SetTarget(this T tween, GameObject target) where T: Tween + public static T SetReference(this T tween, UnityEngine.GameObject reference) where T : Tween { - if (tween != null && target != null) + if (tween != null && reference != null) { - tween.id = target.GetHashCode(); - tween.sceneIndex = target.scene.buildIndex; + tween.id = reference.GetInstanceID(); + tween.sceneIndex = reference.scene.buildIndex; + } + + return tween; + } + + /// + /// Sets the id and scene index of the tween to the reference object so + /// the tween can be retrieved and destroyed based on that object. + /// + /// The type of the tween. + /// The tween to assign the reference to. + /// The reference object. + /// The tween itself to allow for chaining. + public static T SetReference(this T tween, UnityEngine.Object reference) where T : Tween + { + if (tween != null && reference != null) { + tween.id = reference.GetInstanceID(); } return tween; @@ -51,10 +144,10 @@ public static T SetTarget(this T tween, GameObject target) where T: Tween /// Sets the id of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the id to. /// The id to set. /// The tween itself to allow for chaining. - public static T SetId(this T tween, int id) where T: Tween + public static T SetId(this T tween, int id) where T : Tween { if (tween != null) { tween.id = id; @@ -67,10 +160,10 @@ public static T SetId(this T tween, int id) where T: Tween /// Sets the scene index of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the scene index to. /// The scene index to set. /// The tween itself to allow for chaining. - public static T SetSceneIndex(this T tween, int index) where T: Tween + public static T SetSceneIndex(this T tween, int index) where T : Tween { if (tween != null) { tween.sceneIndex = index; @@ -83,10 +176,10 @@ public static T SetSceneIndex(this T tween, int index) where T: Tween /// Sets the ease of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the ease to. /// The ease to set. /// The tween itself to allow for chaining. - public static T SetEase(this T tween, Ease ease) where T: Tween + public static T SetEase(this T tween, Ease ease) where T : Tween { if (tween != null) { tween.ease = ease; @@ -99,10 +192,10 @@ public static T SetEase(this T tween, Ease ease) where T: Tween /// Sets the duration of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the duration to. /// The duration to set. /// The tween itself to allow for chaining. - public static T SetDuration(this T tween, float duration) where T: Tween + public static T SetDuration(this T tween, float duration) where T : Tween { if (tween != null) { tween.duration = duration; @@ -115,10 +208,10 @@ public static T SetDuration(this T tween, float duration) where T: Tween /// Sets the delay of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the delay to. /// The delay to set. /// The tween itself to allow for chaining. - public static T SetDelay(this T tween, float delay) where T: Tween + public static T SetDelay(this T tween, float delay) where T : Tween { if (tween != null) { tween.delay = delay; @@ -131,11 +224,11 @@ public static T SetDelay(this T tween, float delay) where T: Tween /// Sets the number of loops of the tween to the given value. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to loop. /// The number of loops to set. /// The type of loop style to set. /// The tween itself to allow for chaining. - public static T SetLoops(this T tween, int loops, LoopType loopType = LoopType.Restart) where T: Tween + public static T SetLoops(this T tween, int loops, LoopType loopType = LoopType.Restart) where T : Tween { if (tween != null) { @@ -150,10 +243,10 @@ public static T SetLoops(this T tween, int loops, LoopType loopType = LoopTyp /// Sets the tween to play in reverse. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to reverse. /// True if the tween is to be played in reverse. /// The tween itself to allow for chaining. - public static T SetReversed(this T tween, bool reversed = true) where T: Tween + public static T SetReversed(this T tween, bool reversed = true) where T : Tween { if (tween != null) { tween.reversed = reversed; @@ -166,10 +259,10 @@ public static T SetReversed(this T tween, bool reversed = true) where T: Twee /// Sets the tween to snap interpolated values to whole numbers. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to enable snapping on. /// True if interpolated values should be snapped to whole numbers. /// The tween itself to allow for chaining. - public static T SetSnapping(this T tween, bool snapping = true) where T: Tween + public static T SetSnapping(this T tween, bool snapping = true) where T : Tween { if (tween != null) { tween.snapping = snapping; @@ -182,10 +275,10 @@ public static T SetSnapping(this T tween, bool snapping = true) where T: Twee /// Sets the tween to be recycled after being completed. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to recycle. /// True if the tween is to be recycled. /// The tween itself to allow for chaining. - public static T SetRecyclable(this T tween, bool recyclable) where T: Tween + public static T SetRecyclable(this T tween, bool recyclable = true) where T : Tween { if (tween != null) { tween.recyclable = recyclable; @@ -198,10 +291,10 @@ public static T SetRecyclable(this T tween, bool recyclable) where T: Tween /// Sets the tween to auto start after being initialized. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to auto start. /// True if the tween is to be started automatically. /// The tween itself to allow for chaining. - public static T SetAutoStart(this T tween, bool autoStart) where T: Tween + public static T SetAutoStart(this T tween, bool autoStart = true) where T : Tween { if (tween != null) { tween.autoStart = autoStart; @@ -214,10 +307,10 @@ public static T SetAutoStart(this T tween, bool autoStart) where T: Tween /// Sets the tween to auto kill after being completed. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to auto kill. /// True if the tween is to be killed automatically. /// The tween itself to allow for chaining. - public static T SetAutoKill(this T tween, bool autoKill) where T: Tween + public static T SetAutoKill(this T tween, bool autoKill = true) where T : Tween { if (tween != null) { tween.autoKill = autoKill; @@ -226,14 +319,30 @@ public static T SetAutoKill(this T tween, bool autoKill) where T: Tween return tween; } + /// + /// Sets the event handler on the tween. + /// + /// The type of the tween. + /// The tween to assign the event handler to. + /// The event handler to assign. + /// The tween itself to allow for chaining. + public static T SetEventHandler(this T tween, ITweenEventHandler eventHandler) where T : Tween + { + if (tween != null) { + tween.eventHandler = eventHandler; + } + + return tween; + } + /// /// Sets the callback to invoke when the tween is updated. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnUpdate(this T tween, TweenCallback callback) where T: Tween + public static T OnUpdate(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onUpdate += callback; @@ -246,10 +355,10 @@ public static T OnUpdate(this T tween, TweenCallback callback) where T: Tween /// Sets the callback to invoke when the tween is started. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnStart(this T tween, TweenCallback callback) where T: Tween + public static T OnStart(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onStart += callback; @@ -262,10 +371,10 @@ public static T OnStart(this T tween, TweenCallback callback) where T: Tween /// Sets the callback to invoke when the tween is stopped. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnStop(this T tween, TweenCallback callback) where T: Tween + public static T OnStop(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onStop += callback; @@ -278,10 +387,10 @@ public static T OnStop(this T tween, TweenCallback callback) where T: Tween /// Sets the callback to invoke when the tween is looped. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnLoop(this T tween, TweenCallback callback) where T: Tween + public static T OnLoop(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onLoop += callback; @@ -294,10 +403,10 @@ public static T OnLoop(this T tween, TweenCallback callback) where T: Tween /// Sets the callback to invoke when the tween is completed. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnComplete(this T tween, TweenCallback callback) where T: Tween + public static T OnComplete(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onComplete += callback; @@ -310,10 +419,10 @@ public static T OnComplete(this T tween, TweenCallback callback) where T: Twe /// Sets the callback to invoke when the tween is killed. /// /// The type of the tween. - /// The tween to assign the value to. + /// The tween to assign the callback to. /// The callback to invoke. /// The tween itself to allow for chaining. - public static T OnKill(this T tween, TweenCallback callback) where T: Tween + public static T OnKill(this T tween, TweenCallback callback) where T : Tween { if (tween != null) { tween.onKill += callback; diff --git a/Runtime/Sequence.cs b/Runtime/Sequence.cs index 0302898..74090c3 100644 --- a/Runtime/Sequence.cs +++ b/Runtime/Sequence.cs @@ -11,22 +11,22 @@ public sealed class Sequence : Tween /// /// The index of the current tween in the sequence being played (Read only). /// - public int currentIndex { get; private set; } = -1; + public int CurrentIndex { get; private set; } = -1; /// /// The tweens contained in the sequence (Read only). /// - public List tweens { get; internal set; } = new List(); + public readonly List Tweens = new List(); /// /// The tween in the sequence currently being played (Read only). /// - public Tween activeTween + public Tween ActiveTween { get { - if (currentIndex >= 0 && currentIndex < tweens.Count) { - return tweens[currentIndex]; + if (CurrentIndex >= 0 && CurrentIndex < Tweens.Count) { + return Tweens[CurrentIndex]; } else { return null; } @@ -65,7 +65,7 @@ public override void Animate() /// The sequence itself to allow for chaining. public Sequence Append(Tween tween) { - tweens.Add(Prepare(tween)); + Tweens.Add(Prepare(tween)); return this; } @@ -76,7 +76,7 @@ public Sequence Append(Tween tween) /// The sequence itself to allow for chaining. public Sequence Prepend(Tween tween) { - tweens.Insert(0, Prepare(tween)); + Tweens.Insert(0, Prepare(tween)); return this; } @@ -91,12 +91,12 @@ private Tween Prepare(Tween tween) private void Next() { if (reversed) { - currentIndex--; + CurrentIndex--; } else { - currentIndex++; + CurrentIndex++; } - Tween tween = activeTween; + Tween tween = ActiveTween; if (tween != null) { tween.Play(); @@ -107,9 +107,9 @@ private void Next() protected override bool IsFinished() { if (reversed) { - return currentIndex < 0; + return CurrentIndex < 0; } else { - return currentIndex >= tweens.Count; + return CurrentIndex >= Tweens.Count; } } @@ -117,12 +117,12 @@ protected override bool IsFinished() protected override void OnStart() { if (reversed) { - currentIndex = tweens.Count - 1; + CurrentIndex = Tweens.Count - 1; } else { - currentIndex = 0; + CurrentIndex = 0; } - Tween tween = activeTween; + Tween tween = ActiveTween; if (tween != null) { tween.Play(); @@ -132,7 +132,7 @@ protected override void OnStart() /// protected override void OnStop() { - Tween tween = activeTween; + Tween tween = ActiveTween; if (tween != null) { tween.Stop(); @@ -142,7 +142,7 @@ protected override void OnStop() /// protected override void OnResume() { - Tween tween = activeTween; + Tween tween = ActiveTween; if (tween != null) { tween.Play(); @@ -152,13 +152,13 @@ protected override void OnResume() /// protected override void OnLoop() { - foreach (Tween tween in tweens) + foreach (Tween tween in Tweens) { if (loopType == LoopType.PingPong || loopType == LoopType.PingPongWithDelay) { tween.reversed = !tween.reversed; } - tween.elapsed = 0f; + tween.Elapsed = 0f; tween.Animate(); } } @@ -166,7 +166,7 @@ protected override void OnLoop() /// protected override void OnComplete() { - foreach (Tween tween in tweens) + foreach (Tween tween in Tweens) { if (tween != null) { tween.Complete(); @@ -177,22 +177,22 @@ protected override void OnComplete() /// protected override void OnKill() { - foreach (Tween tween in tweens) + foreach (Tween tween in Tweens) { if (tween != null) { tween.Kill(); } } - tweens.Clear(); - currentIndex = -1; + Tweens.Clear(); + CurrentIndex = -1; } /// protected override void OnReset() { - tweens.Clear(); - currentIndex = -1; + Tweens.Clear(); + CurrentIndex = -1; } } diff --git a/Runtime/Tween.cs b/Runtime/Tween.cs index 9c02ca1..b766c82 100644 --- a/Runtime/Tween.cs +++ b/Runtime/Tween.cs @@ -1,6 +1,4 @@ -using UnityEngine.SceneManagement; - -namespace Zigurous.Tweening +namespace Zigurous.Tweening { /// /// The base class of every tween. @@ -55,27 +53,27 @@ internal enum Flag /// /// The animation state of the tween. /// - public TweenState state { get; internal set; } = TweenState.Ready; + public TweenState State { get; internal set; } = TweenState.Ready; /// /// Whether the tween is playing. /// - public bool IsPlaying => state == TweenState.Playing; + public bool IsPlaying => State == TweenState.Playing; /// /// Whether the tween is stopped. /// - public bool IsStopped => state == TweenState.Stopped; + public bool IsStopped => State == TweenState.Stopped; /// /// Whether the tween is complete. /// - public bool IsComplete => state == TweenState.Complete; + public bool IsComplete => State == TweenState.Complete; /// /// Whether the tween is killed. /// - public bool IsKilled => state == TweenState.Killed; + public bool IsKilled => State == TweenState.Killed; /// /// The easing function type used by the tween to animate values. @@ -90,12 +88,12 @@ internal enum Flag /// /// The amount of seconds that have elapsed since the tween started. /// - public float elapsed { get; internal set; } + public float Elapsed { get; internal set; } /// /// The tween's percentage of completion. /// - public float PercentComplete => UnityEngine.Mathf.Clamp01(elapsed / duration); + public float PercentComplete => duration > 0f ? UnityEngine.Mathf.Clamp01(Elapsed / duration) : 1f; /// /// The amount of seconds the tween waits before playing after being @@ -107,14 +105,14 @@ internal enum Flag /// The amount of seconds that have elapsed during the tween's delayed /// state, when applicable. /// - public float delayElapsed { get; internal set; } + public float DelayElapsed { get; internal set; } /// /// Whether the tween is currently in a delayed state, i.e., the tween /// has been started but the elapsed time has not exceeded the delay /// duration. /// - public bool IsDelayed => delayElapsed < delay; + public bool IsDelayed => DelayElapsed < delay; /// /// The number of times the tween loops. A value of -1 will loop the @@ -130,12 +128,12 @@ internal enum Flag /// /// The number of times the tween has completed. /// - public int iterations { get; internal set; } + public int Iterations { get; internal set; } /// /// The configuration flags set on the tween. /// - internal Flag flags = 0; + private Flag Flags = 0; /// /// Animates from the end value to the start value as opposed to @@ -184,35 +182,40 @@ public bool autoKill } /// - /// The callback invoked every time the tween is updated, i.e., any time - /// the parameter being animated is changed. + /// An event handler that responds to lifecycle events of the tween. /// - public TweenCallback onUpdate; + public ITweenEventHandler eventHandler; /// - /// The callback invoked when the tween is started. + /// An event invoked every time the tween is updated, i.e., any time the + /// parameter being animated is changed. /// - public TweenCallback onStart; + public event TweenCallback onUpdate; /// - /// The callback invoked when the tween is stopped. + /// An event invoked when the tween is started. /// - public TweenCallback onStop; + public event TweenCallback onStart; /// - /// The callback invoked when the tween is looped. + /// An event invoked when the tween is stopped. /// - public TweenCallback onLoop; + public event TweenCallback onStop; /// - /// The callback invoked when the tween is completed. + /// An event invoked when the tween is looped. /// - public TweenCallback onComplete; + public event TweenCallback onLoop; /// - /// The callback invoked when the tween is killed. + /// An event invoked when the tween is completed. /// - public TweenCallback onKill; + public event TweenCallback onComplete; + + /// + /// An event invoked when the tween is killed. + /// + public event TweenCallback onKill; /// /// Creates a new tween object. @@ -240,7 +243,7 @@ internal void Update(float deltaTime) { if (!IsPlaying) { - if (state == TweenState.Ready && autoStart) { + if (State == TweenState.Ready && autoStart) { Play(); } return; @@ -248,11 +251,15 @@ internal void Update(float deltaTime) if (!IsDelayed) { - elapsed += deltaTime; + Elapsed += deltaTime; Animate(); OnUpdate(); + if (eventHandler != null) { + eventHandler.OnTweenUpdate(this); + } + if (onUpdate != null) { onUpdate.Invoke(); } @@ -265,12 +272,12 @@ internal void Update(float deltaTime) } else { - delayElapsed += deltaTime; + DelayElapsed += deltaTime; // Start the tween once the delay is complete and only if the // elapsed time is zero which indicates it has never been // updated yet - if (delayElapsed >= delay && elapsed == 0) { + if (DelayElapsed >= delay && Elapsed == 0f) { Start(); } } @@ -282,13 +289,13 @@ internal void Update(float deltaTime) /// public void Play() { - if (!state.CanTransition(TweenState.Playing)) { + if (!State.CanTransition(TweenState.Playing)) { return; } - TweenState previousState = state; + TweenState previousState = State; - state = TweenState.Playing; + State = TweenState.Playing; internalState = InternalTweenState.Active; if (previousState == TweenState.Stopped) @@ -297,8 +304,8 @@ public void Play() } else { - elapsed = 0f; - delayElapsed = 0f; + Elapsed = 0f; + DelayElapsed = 0f; if (!IsDelayed) { Start(); @@ -311,10 +318,14 @@ public void Play() /// private void Start() { - if (iterations > 0) + if (Iterations > 0) { OnLoop(); + if (eventHandler != null) { + eventHandler.OnTweenLoop(this); + } + if (onLoop != null) { onLoop.Invoke(); } @@ -323,8 +334,15 @@ private void Start() OnStart(); Animate(); - if (iterations == 0 && onStart != null) { - onStart.Invoke(); + if (Iterations == 0) + { + if (eventHandler != null) { + eventHandler.OnTweenStart(this); + } + + if (onStart != null) { + onStart.Invoke(); + } } } @@ -333,14 +351,18 @@ private void Start() /// public void Stop() { - if (!state.CanTransition(TweenState.Stopped)) { + if (!State.CanTransition(TweenState.Stopped)) { return; } - state = TweenState.Stopped; + State = TweenState.Stopped; OnStop(); + if (eventHandler != null) { + eventHandler.OnTweenStop(this); + } + if (onStop != null) { onStop.Invoke(); } @@ -352,18 +374,18 @@ public void Stop() /// True if the tween is looped. private bool Loop() { - iterations++; + Iterations++; - if (iterations >= loops && loops != -1) { + if (Iterations >= loops && loops != -1) { return false; } - elapsed = 0f; + Elapsed = 0f; switch (loopType) { case LoopType.RestartWithDelay: - delayElapsed = 0f; + DelayElapsed = 0f; break; case LoopType.PingPong: @@ -372,7 +394,7 @@ private bool Loop() case LoopType.PingPongWithDelay: reversed = !reversed; - delayElapsed = 0f; + DelayElapsed = 0f; break; } @@ -388,17 +410,21 @@ private bool Loop() /// public void Complete() { - if (!state.CanTransition(TweenState.Complete)) { + if (!State.CanTransition(TweenState.Complete)) { return; } - state = TweenState.Complete; - elapsed = duration; - delayElapsed = delay; + State = TweenState.Complete; + Elapsed = duration; + DelayElapsed = delay; Animate(); OnComplete(); + if (eventHandler != null) { + eventHandler.OnTweenComplete(this); + } + if (onComplete != null) { onComplete.Invoke(); } @@ -414,19 +440,24 @@ public void Complete() /// public void Kill() { - if (!state.CanTransition(TweenState.Killed)) { + if (!State.CanTransition(TweenState.Killed)) { return; } - state = TweenState.Killed; + State = TweenState.Killed; internalState = InternalTweenState.Dequeued; OnKill(); + if (eventHandler != null) { + eventHandler.OnTweenKill(this); + } + if (onKill != null) { onKill.Invoke(); } + eventHandler = null; onKill = null; onUpdate = null; onStart = null; @@ -450,28 +481,29 @@ public void Restart() internal void Reset() { id = -1; - sceneIndex = SceneManager.GetActiveScene().buildIndex; + sceneIndex = -1; - state = TweenState.Ready; + State = TweenState.Ready; internalState = InternalTweenState.Queued; ease = Settings.defaultEase; duration = Settings.defaultDuration; - elapsed = 0f; + Elapsed = 0f; delay = Settings.defaultDelay; - delayElapsed = 0f; + DelayElapsed = 0f; loops = 0; loopType = LoopType.Restart; - iterations = 0; + Iterations = 0; - flags = 0; + Flags = 0; reversed = false; snapping = false; autoStart = Settings.autoStart; autoKill = Settings.autoKill; recyclable = Settings.recyclable; + eventHandler = null; onUpdate = null; onStart = null; onStop = null; @@ -484,15 +516,15 @@ internal void Reset() internal bool GetFlag(Flag flag) { - return flags.Has(flag); + return Flags.Has(flag); } internal void SetFlag(Flag flag, bool on) { if (on) { - flags |= flag; + Flags |= flag; } else { - flags &= ~flag; + Flags &= ~flag; } } @@ -500,7 +532,7 @@ internal void SetFlag(Flag flag, bool on) /// Determines if the tween has finished playing. /// /// True if the tween has finished playing. - protected virtual bool IsFinished() => elapsed >= duration; + protected virtual bool IsFinished() => Elapsed >= duration; /// /// Override to handle custom logic when the tween is updated. diff --git a/Runtime/TweenManager.cs b/Runtime/TweenManager.cs index ca02230..fdd3d88 100644 --- a/Runtime/TweenManager.cs +++ b/Runtime/TweenManager.cs @@ -12,7 +12,7 @@ namespace Zigurous.Tweening internal sealed class TweenManager : MonoBehaviour { private static bool isUnloading = false; - private static object lockObject = new object(); + private static readonly object lockObject = new object(); private static volatile TweenManager instance; internal static TweenManager Instance @@ -56,7 +56,7 @@ private void Awake() if (instance == null) { instance = this; - SceneManager.sceneUnloaded += SceneUnloaded; + SceneManager.sceneUnloaded += OnSceneUnloaded; } else { @@ -71,7 +71,7 @@ private void OnDestroy() if (instance == this) { instance = null; - SceneManager.sceneUnloaded -= SceneUnloaded; + SceneManager.sceneUnloaded -= OnSceneUnloaded; } foreach (Tween tween in tweens) { @@ -114,28 +114,28 @@ private void Update() /// /// Recycles or creates a new tween object. /// - internal Tweener BuildTweener() + internal Tweener BuildTweener() { - Tweener tweener = null; + Tweener tweener = null; foreach (Tween tween in tweens) { if (tween.internalState == InternalTweenState.Recycled && tween.type == TweenType.Tweener && - tween.template == typeof(T)) + tween.template == typeof(Tweener)) { - tweener = (Tweener)tween; + tweener = (Tweener)tween; break; } } if (tweener == null) { - tweener = new Tweener(); + tweener = new Tweener(); } else { tweener.Reset(); } - tweener.state = TweenState.Ready; + tweener.State = TweenState.Ready; tweener.internalState = InternalTweenState.Queued; return tweener; @@ -164,7 +164,7 @@ internal Sequence BuildSequence() sequence.Reset(); } - sequence.state = TweenState.Ready; + sequence.State = TweenState.Ready; sequence.internalState = InternalTweenState.Queued; return sequence; @@ -184,7 +184,7 @@ internal void Track(Tween tween) /// /// Kills all tweens that are animating objects on the unloaded scene. /// - private void SceneUnloaded(Scene scene) + private void OnSceneUnloaded(Scene scene) { foreach (Tween tween in tweens) { diff --git a/Runtime/Tweener.cs b/Runtime/Tweener.cs index 2565eb8..4562341 100644 --- a/Runtime/Tweener.cs +++ b/Runtime/Tweener.cs @@ -1,38 +1,44 @@ namespace Zigurous.Tweening { /// - /// A tween that animates a parameter over time from a start value to an end - /// value. + /// A tween that animates a parameter over time on an object from a start + /// value to an end value. /// - /// The type of the parameter to tween. - public class Tweener : Tween + /// The type of object to tween. + /// The type of parameter to tween. + public class Tweener : Tween { /// - /// The function that interpolates values between the tween's start and - /// end value. + /// The object being tweened. /// - public Interpolater interpolater; + public T target; /// /// The function that gets the current value of the parameter being /// tweened. /// - public TweenGetter getter; + public TweenGetter getter; /// /// The function that sets a new value of the parameter being tweened. /// - public TweenSetter setter; + public TweenSetter setter; + + /// + /// The function that interpolates values between the tween's start and + /// end value. + /// + public Interpolater interpolater; /// /// The initial value of the parameter at the start of the tween. /// - public T startValue; + public U startValue; /// /// The desired value of the parameter at the end of the tween. /// - public T endValue; + public U endValue; /// /// Creates a new tweener. @@ -40,7 +46,16 @@ public class Tweener : Tween public Tweener() : base() { type = TweenType.Tweener; - template = typeof(T); + template = typeof(Tweener); + } + + /// + /// Creates a new tweener with the specified target object. + /// + /// The object to tween. + public Tweener(T target) : this() + { + this.SetTarget(target); } /// @@ -57,20 +72,21 @@ public override void Animate() } float time = EaseFunction.lookup[ease](percent); - setter(interpolater(startValue, endValue, time, snapping)); + setter(target, interpolater(startValue, endValue, time, snapping)); } /// protected override void OnStart() { - if (iterations == 0 && getter != null) { - startValue = getter(); + if (Iterations == 0 && getter != null) { + startValue = getter(target); } } /// protected override void OnKill() { + target = default(T); interpolater = null; getter = null; setter = null; @@ -79,6 +95,7 @@ protected override void OnKill() /// protected override void OnReset() { + target = default(T); interpolater = null; getter = null; setter = null; diff --git a/Runtime/Tweening.cs b/Runtime/Tweening.cs index 898fe02..7e35d61 100644 --- a/Runtime/Tweening.cs +++ b/Runtime/Tweening.cs @@ -12,7 +12,7 @@ public static class Tweening /// The number of tweens currently alive. This includes tweens that have /// been recycled and are not currently active (Read only). /// - public static int count + public static int Count { get { @@ -27,7 +27,7 @@ public static int count /// /// The number of tweens that are currently alive and active (Read only). /// - public static int activeCount + public static int ActiveCount { get { @@ -53,167 +53,208 @@ public static int activeCount /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, float endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, float endValue, float duration) => + To(Interpolation._float, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, double endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, double endValue, float duration) => + To(Interpolation._double, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, long endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, int endValue, float duration) => + To(Interpolation._int, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, int endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, long endValue, float duration) => + To(Interpolation._long, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Vector2 endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, short endValue, float duration) => + To(Interpolation._short, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Vector2Int endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Vector2 endValue, float duration) => + To(Interpolation._Vector2, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Vector3 endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Vector2Int endValue, float duration) => + To(Interpolation._Vector2Int, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Vector3Int endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Vector3 endValue, float duration) => + To(Interpolation._Vector3, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Vector4 endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Vector3Int endValue, float duration) => + To(Interpolation._Vector3Int, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Quaternion endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Vector4 endValue, float duration) => + To(Interpolation._Vector4, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Rect endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Quaternion endValue, float duration) => + To(Interpolation._Quaternion, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(TweenGetter getter, TweenSetter setter, Color endValue, float duration) => - To(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Rect endValue, float duration) => + To(Interpolation._Rect, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter to a given end value over /// a set duration. /// - /// The type of the parameter. + /// The type of object to tween. + /// The object to tween. + /// The function that gets the current value of the parameter. + /// The function that sets a new value of the parameter. + /// The end value of the parameter. + /// The duration of the tween. + /// A new tween that animates the parameter. + public static Tween To(T target, TweenGetter getter, TweenSetter setter, Color endValue, float duration) => + To(Interpolation._Color, target, getter, setter, endValue, duration); + + /// + /// Creates a tween that animates a parameter on an object to a given + /// end value over a set duration. + /// + /// The type of object to tween. + /// The type of parameter to tween. /// The function that interpolates values between the start and end value. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween To(Interpolater interpolater, TweenGetter getter, TweenSetter setter, T endValue, float duration) + public static Tween To(Interpolater interpolater, T target, TweenGetter getter, TweenSetter setter, U endValue, float duration) { if (TweenManager.Unloading) { return null; } - Tweener tween = TweenManager.Instance.BuildTweener(); - tween.interpolater = interpolater; + Tweener tween = TweenManager.Instance.BuildTweener(); + tween.target = target; tween.getter = getter; tween.setter = setter; + tween.interpolater = interpolater; tween.endValue = endValue; tween.duration = duration; tween.reversed = false; @@ -225,167 +266,208 @@ public static Tween To(Interpolater interpolater, TweenGetter getter, T /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, float endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, float endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, double endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, double endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, long endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, int endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, int endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, long endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Vector2 endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, short endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Vector2Int endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Vector2 endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Vector3 endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Vector2Int endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Vector3Int endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Vector3 endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Vector4 endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Vector3Int endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Quaternion endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Vector4 endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Rect endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Quaternion endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// + /// The type of object to tween. + /// The object to tween. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(TweenGetter getter, TweenSetter setter, Color endValue, float duration) => - From(Interpolation.Lerp, getter, setter, endValue, duration); + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Rect endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); /// /// Creates a tween that animates a parameter from a given end value to /// the current value over a set duration. /// - /// The type of the parameter. + /// The type of object to tween. + /// The object to tween. + /// The function that gets the current value of the parameter. + /// The function that sets a new value of the parameter. + /// The end value of the parameter. + /// The duration of the tween. + /// A new tween that animates the parameter. + public static Tween From(T target, TweenGetter getter, TweenSetter setter, Color endValue, float duration) => + From(Interpolation.Lerp, target, getter, setter, endValue, duration); + + /// + /// Creates a tween that animates a parameter on an object from a given + /// end value to the current value over a set duration. + /// + /// The type of object to tween. + /// The type of parameter to tween. + /// The object to tween. /// The function that interpolates values between the start and end value. /// The function that gets the current value of the parameter. /// The function that sets a new value of the parameter. /// The end value of the parameter. /// The duration of the tween. /// A new tween that animates the parameter. - public static Tween From(Interpolater interpolater, TweenGetter getter, TweenSetter setter, T endValue, float duration) + public static Tween From(Interpolater interpolater, T target, TweenGetter getter, TweenSetter setter, U endValue, float duration) { if (TweenManager.Unloading) { return null; } - Tweener tween = TweenManager.Instance.BuildTweener(); - tween.interpolater = interpolater; + Tweener tween = TweenManager.Instance.BuildTweener(); + tween.target = target; tween.getter = getter; tween.setter = setter; + tween.interpolater = interpolater; tween.endValue = endValue; tween.duration = duration; tween.reversed = true; @@ -420,7 +502,7 @@ public static Sequence Sequence(params Tween[] tweens) Sequence sequence = TweenManager.Instance.BuildSequence(); if (tweens != null && tweens.Length > 0) { - sequence.tweens.AddRange(tweens); + sequence.Tweens.AddRange(tweens); } return sequence; @@ -467,7 +549,7 @@ public static void Play(int id) /// /// The type of the target object. /// The target object to play the tweens of. - public static void Play(T target) where T: class + public static void Play(T target) where T : class { Play(target.GetHashCode()); } @@ -513,7 +595,7 @@ public static void Stop(int id) /// /// The type of the target object. /// The target object to stop the tweens of. - public static void Stop(T target) where T: class + public static void Stop(T target) where T : class { Stop(target.GetHashCode()); } @@ -559,7 +641,7 @@ public static void Restart(int id) /// /// The type of the target object. /// The target object to restart the tweens of. - public static void Restart(T target) where T: class + public static void Restart(T target) where T : class { Restart(target.GetHashCode()); } @@ -605,7 +687,7 @@ public static void Complete(int id) /// /// The type of the target object. /// The target object to complete the tweens of. - public static void Complete(T target) where T: class + public static void Complete(T target) where T : class { Complete(target.GetHashCode()); } @@ -657,7 +739,7 @@ public static void Kill(int id, bool complete = false) /// The type of the target object. /// The target object to kill the tweens of. /// Whether to complete the tweens before being killed. - public static void KillTweens(this T target, bool complete = false) where T: class + public static void KillTweens(this T target, bool complete = false) where T : class { Kill(target.GetHashCode(), complete); } diff --git a/package.json b/package.json index 24f8d62..f7ce72a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.zigurous.tweening", - "version": "2.6.1", + "version": "3.0.0", "displayName": "Tweening", "description": "The Tweening package provides a system for tweening object properties in Unity. A tween is an animation of a value from a start position to an end position using an easing function, providing a natural sense of motion.\n\nThe system is lightweight, optimized, type-safe, and memory efficient. Hundreds of predefined tweening functions can be called on many common Unity classes, or you can animate anything using generic tweening functions. Tweens can be controlled with many different control methods and various callback functions.", "unity": "2019.4",