Skip to content

Commit 02df49e

Browse files
committed
Refactor tween extensions to remove closures
1 parent ef761db commit 02df49e

File tree

95 files changed

+1032
-1464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

95 files changed

+1032
-1464
lines changed

Runtime/Delegates.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
namespace Zigurous.Tweening
22
{
33
/// <summary>
4-
/// A function delegate that gets the current value of a parameter.
4+
/// A function delegate that gets the current value of a parameter from a
5+
/// source object.
56
/// </summary>
7+
/// <typeparam name="S">The type of the source object.</typeparam>
68
/// <typeparam name="T">The type of the parameter.</typeparam>
9+
/// <param name="source">The source object to get the value from.</param>
710
/// <returns>The current value of the parameter.</returns>
8-
public delegate T TweenGetter<T>();
11+
public delegate T TweenGetter<S,T>(S source);
912

1013
/// <summary>
11-
/// A function delegate that sets a new value of a parameter.
14+
/// A function delegate that sets a new value of a parameter on a source
15+
/// object.
1216
/// </summary>
17+
/// <typeparam name="S">The type of the source object.</typeparam>
1318
/// <typeparam name="T">The type of the parameter.</typeparam>
19+
/// <param name="source">The source object to set the value on.</param>
1420
/// <param name="value">The new value of the parameter.</param>
15-
public delegate void TweenSetter<T>(T value);
21+
public delegate void TweenSetter<S,T>(S source, T value);
1622

1723
/// <summary>
1824
/// A function delegate that can be invoked during various tween events
@@ -31,5 +37,4 @@
3137
/// <param name="snapping">Snaps the interpolated value to the nearest whole number.</param>
3238
/// <returns>The interpolated value between the start and end value.</returns>
3339
public delegate T Interpolater<T>(T a, T b, float t, bool snapping);
34-
3540
}

Runtime/Extensions/Audio/AudioChorusFilterTweens.cs

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,40 +5,32 @@ namespace Zigurous.Tweening
55
public static class AudioChorusFilterTweens
66
{
77
public static Tween TweenDelay(this AudioChorusFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.delay,
9-
setter: delay => filter.delay = delay,
10-
to, duration).SetTarget(filter);
8+
Tweening.To(filter, (source) => source.delay, (source, value) => source.delay = value, to, duration)
9+
.SetTarget(filter);
1110

1211
public static Tween TweenRate(this AudioChorusFilter filter, float to, float duration) =>
13-
Tweening.To(getter: () => filter.rate,
14-
setter: rate => filter.rate = rate,
15-
to, duration).SetTarget(filter);
12+
Tweening.To(filter, (source) => source.rate, (source, value) => source.rate = value, to, duration)
13+
.SetTarget(filter);
1614

1715
public static Tween TweenDepth(this AudioChorusFilter filter, float to, float duration) =>
18-
Tweening.To(getter: () => filter.depth,
19-
setter: depth => filter.depth = depth,
20-
to, duration).SetTarget(filter);
16+
Tweening.To(filter, (source) => source.depth, (source, value) => source.depth = value, to, duration)
17+
.SetTarget(filter);
2118

2219
public static Tween TweenDryMix(this AudioChorusFilter filter, float to, float duration) =>
23-
Tweening.To(getter: () => filter.dryMix,
24-
setter: dryMix => filter.dryMix = dryMix,
25-
to, duration).SetTarget(filter);
20+
Tweening.To(filter, (source) => source.dryMix, (source, value) => source.dryMix = value, to, duration)
21+
.SetTarget(filter);
2622

2723
public static Tween TweenWetMix1(this AudioChorusFilter filter, float to, float duration) =>
28-
Tweening.To(getter: () => filter.wetMix1,
29-
setter: wetMix1 => filter.wetMix1 = wetMix1,
30-
to, duration).SetTarget(filter);
24+
Tweening.To(filter, (source) => source.wetMix1, (source, value) => source.wetMix1 = value, to, duration)
25+
.SetTarget(filter);
3126

3227
public static Tween TweenWetMix2(this AudioChorusFilter filter, float to, float duration) =>
33-
Tweening.To(getter: () => filter.wetMix2,
34-
setter: wetMix2 => filter.wetMix2 = wetMix2,
35-
to, duration).SetTarget(filter);
28+
Tweening.To(filter, (source) => source.wetMix2, (source, value) => source.wetMix2 = value, to, duration)
29+
.SetTarget(filter);
3630

3731
public static Tween TweenWetMix3(this AudioChorusFilter filter, float to, float duration) =>
38-
Tweening.To(getter: () => filter.wetMix3,
39-
setter: wetMix3 => filter.wetMix3 = wetMix3,
40-
to, duration).SetTarget(filter);
41-
32+
Tweening.To(filter, (source) => source.wetMix3, (source, value) => source.wetMix3 = value, to, duration)
33+
.SetTarget(filter);
4234
}
4335

4436
}

Runtime/Extensions/Audio/AudioDistortionFilterTweens.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ namespace Zigurous.Tweening
55
public static class AudioDistortionFilterTweens
66
{
77
public static Tween TweenDistortionLevel(this AudioDistortionFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.distortionLevel,
9-
setter: distortionLevel => filter.distortionLevel = distortionLevel,
10-
to, duration).SetTarget(filter);
11-
8+
Tweening.To(filter, (source) => source.distortionLevel, (source, value) => source.distortionLevel = value, to, duration)
9+
.SetTarget(filter);
1210
}
1311

1412
}

Runtime/Extensions/Audio/AudioEchoFilterTweens.cs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,20 @@ namespace Zigurous.Tweening
55
public static class AudioEchoFilterTweens
66
{
77
public static Tween TweenDelay(this AudioEchoFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.delay,
9-
setter: delay => filter.delay = delay,
10-
to, duration).SetTarget(filter);
8+
Tweening.To(filter, (source) => source.delay, (source, value) => source.delay = value, to, duration)
9+
.SetTarget(filter);
1110

1211
public static Tween TweenDecayRatio(this AudioEchoFilter filter, float to, float duration) =>
13-
Tweening.To(getter: () => filter.decayRatio,
14-
setter: decayRatio => filter.decayRatio = decayRatio,
15-
to, duration).SetTarget(filter);
12+
Tweening.To(filter, (source) => source.decayRatio, (source, value) => source.decayRatio = value, to, duration)
13+
.SetTarget(filter);
1614

1715
public static Tween TweenDryMix(this AudioEchoFilter filter, float to, float duration) =>
18-
Tweening.To(getter: () => filter.dryMix,
19-
setter: dryMix => filter.dryMix = dryMix,
20-
to, duration).SetTarget(filter);
16+
Tweening.To(filter, (source) => source.dryMix, (source, value) => source.dryMix = value, to, duration)
17+
.SetTarget(filter);
2118

2219
public static Tween TweenWetMix(this AudioEchoFilter filter, float to, float duration) =>
23-
Tweening.To(getter: () => filter.wetMix,
24-
setter: wetMix => filter.wetMix = wetMix,
25-
to, duration).SetTarget(filter);
26-
20+
Tweening.To(filter, (source) => source.wetMix, (source, value) => source.wetMix = value, to, duration)
21+
.SetTarget(filter);
2722
}
2823

2924
}

Runtime/Extensions/Audio/AudioHighPassFilterTweens.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Zigurous.Tweening
55
public static class AudioHighPassFilterTweens
66
{
77
public static Tween TweenCutoffFrequency(this AudioHighPassFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.cutoffFrequency,
9-
setter: cutoffFrequency => filter.cutoffFrequency = cutoffFrequency,
10-
to, duration).SetTarget(filter);
8+
Tweening.To(filter, (source) => source.cutoffFrequency, (source, value) => source.cutoffFrequency = value, to, duration)
9+
.SetTarget(filter);
1110

1211
public static Tween TweenHighpassResonanceQ(this AudioHighPassFilter filter, float to, float duration) =>
13-
Tweening.To(getter: () => filter.highpassResonanceQ,
14-
setter: highpassResonanceQ => filter.highpassResonanceQ = highpassResonanceQ,
15-
to, duration).SetTarget(filter);
16-
12+
Tweening.To(filter, (source) => source.highpassResonanceQ, (source, value) => source.highpassResonanceQ = value, to, duration)
13+
.SetTarget(filter);
1714
}
1815

1916
}

Runtime/Extensions/Audio/AudioListenerTweens.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,8 @@ namespace Zigurous.Tweening
55
public static class AudioListenerTweens
66
{
77
public static Tween TweenVolume(this AudioListener listener, float to, float duration) =>
8-
Tweening.To(getter: () => AudioListener.volume,
9-
setter: volume => AudioListener.volume = volume,
10-
to, duration).SetTarget(listener);
11-
8+
Tweening.To(listener, (source) => AudioListener.volume, (source, value) => AudioListener.volume = value, to, duration)
9+
.SetTarget(listener);
1210
}
1311

1412
}

Runtime/Extensions/Audio/AudioLowPassFilterTweens.cs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,12 @@ namespace Zigurous.Tweening
55
public static class AudioLowPassFilterTweens
66
{
77
public static Tween TweenCutoffFrequency(this AudioLowPassFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.cutoffFrequency,
9-
setter: cutoffFrequency => filter.cutoffFrequency = cutoffFrequency,
10-
to, duration).SetTarget(filter);
8+
Tweening.To(filter, (source) => source.cutoffFrequency, (source, value) => source.cutoffFrequency = value, to, duration)
9+
.SetTarget(filter);
1110

1211
public static Tween TweenLowpassResonanceQ(this AudioLowPassFilter filter, float to, float duration) =>
13-
Tweening.To(getter: () => filter.lowpassResonanceQ,
14-
setter: lowpassResonanceQ => filter.lowpassResonanceQ = lowpassResonanceQ,
15-
to, duration).SetTarget(filter);
16-
12+
Tweening.To(filter, (source) => source.lowpassResonanceQ, (source, value) => source.lowpassResonanceQ = value, to, duration)
13+
.SetTarget(filter);
1714
}
1815

1916
}

Runtime/Extensions/Audio/AudioReverbFilterTweens.cs

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -5,75 +5,60 @@ namespace Zigurous.Tweening
55
public static class AudioReverbFilterTweens
66
{
77
public static Tween TweenDensity(this AudioReverbFilter filter, float to, float duration) =>
8-
Tweening.To(getter: () => filter.density,
9-
setter: density => filter.density = density,
10-
to, duration).SetTarget(filter);
8+
Tweening.To(filter, (source) => source.density, (source, value) => source.density = value, to, duration)
9+
.SetTarget(filter);
1110

1211
public static Tween TweenDiffusion(this AudioReverbFilter filter, float to, float duration) =>
13-
Tweening.To(getter: () => filter.diffusion,
14-
setter: diffusion => filter.diffusion = diffusion,
15-
to, duration).SetTarget(filter);
12+
Tweening.To(filter, (source) => source.diffusion, (source, value) => source.diffusion = value, to, duration)
13+
.SetTarget(filter);
1614

1715
public static Tween TweenReverbDelay(this AudioReverbFilter filter, float to, float duration) =>
18-
Tweening.To(getter: () => filter.reverbDelay,
19-
setter: reverbDelay => filter.reverbDelay = reverbDelay,
20-
to, duration).SetTarget(filter);
16+
Tweening.To(filter, (source) => source.reverbDelay, (source, value) => source.reverbDelay = value, to, duration)
17+
.SetTarget(filter);
2118

2219
public static Tween TweenReverbLevel(this AudioReverbFilter filter, float to, float duration) =>
23-
Tweening.To(getter: () => filter.reverbLevel,
24-
setter: reverbLevel => filter.reverbLevel = reverbLevel,
25-
to, duration).SetTarget(filter);
20+
Tweening.To(filter, (source) => source.reverbLevel, (source, value) => source.reverbLevel = value, to, duration)
21+
.SetTarget(filter);
2622

2723
public static Tween TweenReflectionsDelay(this AudioReverbFilter filter, float to, float duration) =>
28-
Tweening.To(getter: () => filter.reflectionsDelay,
29-
setter: reflectionsDelay => filter.reflectionsDelay = reflectionsDelay,
30-
to, duration).SetTarget(filter);
24+
Tweening.To(filter, (source) => source.reflectionsDelay, (source, value) => source.reflectionsDelay = value, to, duration)
25+
.SetTarget(filter);
3126

3227
public static Tween TweenReflectionsLevel(this AudioReverbFilter filter, float to, float duration) =>
33-
Tweening.To(getter: () => filter.reflectionsLevel,
34-
setter: reflectionsLevel => filter.reflectionsLevel = reflectionsLevel,
35-
to, duration).SetTarget(filter);
28+
Tweening.To(filter, (source) => source.reflectionsLevel, (source, value) => source.reflectionsLevel = value, to, duration)
29+
.SetTarget(filter);
3630

3731
public static Tween TweenDecayHFRatio(this AudioReverbFilter filter, float to, float duration) =>
38-
Tweening.To(getter: () => filter.decayHFRatio,
39-
setter: decayHFRatio => filter.decayHFRatio = decayHFRatio,
40-
to, duration).SetTarget(filter);
32+
Tweening.To(filter, (source) => source.decayHFRatio, (source, value) => source.decayHFRatio = value, to, duration)
33+
.SetTarget(filter);
4134

4235
public static Tween TweenDecayTime(this AudioReverbFilter filter, float to, float duration) =>
43-
Tweening.To(getter: () => filter.decayTime,
44-
setter: decayTime => filter.decayTime = decayTime,
45-
to, duration).SetTarget(filter);
36+
Tweening.To(filter, (source) => source.decayTime, (source, value) => source.decayTime = value, to, duration)
37+
.SetTarget(filter);
4638

4739
public static Tween TweenRoom(this AudioReverbFilter filter, float to, float duration) =>
48-
Tweening.To(getter: () => filter.room,
49-
setter: room => filter.room = room,
50-
to, duration).SetTarget(filter);
40+
Tweening.To(filter, (source) => source.room, (source, value) => source.room = value, to, duration)
41+
.SetTarget(filter);
5142

5243
public static Tween TweenRoomHF(this AudioReverbFilter filter, float to, float duration) =>
53-
Tweening.To(getter: () => filter.roomHF,
54-
setter: roomHF => filter.roomHF = roomHF,
55-
to, duration).SetTarget(filter);
44+
Tweening.To(filter, (source) => source.roomHF, (source, value) => source.roomHF = value, to, duration)
45+
.SetTarget(filter);
5646

5747
public static Tween TweenRoomLF(this AudioReverbFilter filter, float to, float duration) =>
58-
Tweening.To(getter: () => filter.roomLF,
59-
setter: roomLF => filter.roomLF = roomLF,
60-
to, duration).SetTarget(filter);
48+
Tweening.To(filter, (source) => source.roomLF, (source, value) => source.roomLF = value, to, duration)
49+
.SetTarget(filter);
6150

6251
public static Tween TweenDryLevel(this AudioReverbFilter filter, float to, float duration) =>
63-
Tweening.To(getter: () => filter.dryLevel,
64-
setter: dryLevel => filter.dryLevel = dryLevel,
65-
to, duration).SetTarget(filter);
52+
Tweening.To(filter, (source) => source.dryLevel, (source, value) => source.dryLevel = value, to, duration)
53+
.SetTarget(filter);
6654

6755
public static Tween TweenHFReference(this AudioReverbFilter filter, float to, float duration) =>
68-
Tweening.To(getter: () => filter.hfReference,
69-
setter: hfReference => filter.hfReference = hfReference,
70-
to, duration).SetTarget(filter);
56+
Tweening.To(filter, (source) => source.hfReference, (source, value) => source.hfReference = value, to, duration)
57+
.SetTarget(filter);
7158

7259
public static Tween TweenLFReference(this AudioReverbFilter filter, float to, float duration) =>
73-
Tweening.To(getter: () => filter.lfReference,
74-
setter: lfReference => filter.lfReference = lfReference,
75-
to, duration).SetTarget(filter);
76-
60+
Tweening.To(filter, (source) => source.lfReference, (source, value) => source.lfReference = value, to, duration)
61+
.SetTarget(filter);
7762
}
7863

7964
}

0 commit comments

Comments
 (0)