Skip to content

Commit 2eca72d

Browse files
authored
Merge pull request #27 from coryleach/dev
Custom CanTween override and NRE fix merge
2 parents dfe9add + a5205c9 commit 2eca72d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,15 @@ Includes a SRP shader for blurring the background of UI panels.
2222
#### Using UnityPackageManager (for Unity 2019.3 or later)
2323
Open the package manager window (menu: Window > Package Manager)<br/>
2424
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
25-
https://github.com/coryleach/UnityGUI.git#3.0.10<br/>
25+
https://github.com/coryleach/UnityGUI.git#3.0.11<br/>
2626

2727
#### Using UnityPackageManager (for Unity 2019.1 or later)
2828

2929
Find the manifest.json file in the Packages folder of your project and edit it to look like this:
3030
```js
3131
{
3232
"dependencies": {
33-
"com.gameframe.gui": "https://github.com/coryleach/UnityGUI.git#3.0.10",
33+
"com.gameframe.gui": "https://github.com/coryleach/UnityGUI.git#3.0.11",
3434
...
3535
},
3636
}

Runtime/Tween/TweenExtensions.cs

+20-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,21 @@ public static class TweenExtensions
1111
private static CancellationTokenSource _cancellationTokenSource;
1212
private static Dictionary<int, TweenData> _tweenDict;
1313

14-
private static CancellationToken CancellationToken => _cancellationTokenSource.Token;
14+
private static CancellationToken CancellationToken => (_cancellationTokenSource != null) ? _cancellationTokenSource.Token : CancellationToken.None;
1515

16-
private static bool CanTween => Application.isPlaying && !CancellationToken.IsCancellationRequested;
16+
private static bool CanTween => CanTweenPredicate.Invoke();
17+
18+
private static Func<bool> _canTweenPredicate = DefaultCanTweenPredicate;
19+
public static Func<bool> CanTweenPredicate
20+
{
21+
get => _canTweenPredicate;
22+
set => _canTweenPredicate = value ?? DefaultCanTweenPredicate;
23+
}
24+
25+
private static bool DefaultCanTweenPredicate()
26+
{
27+
return Application.isPlaying && !CancellationToken.IsCancellationRequested;
28+
}
1729

1830
[RuntimeInitializeOnLoadMethod]
1931
public static void Initialize()
@@ -81,10 +93,16 @@ public static Task DoPunchTweenAsync(int id, float duration, CancellationToken c
8193

8294
public static async Task DoTweenAsyncWithLerp(Func<float,float,float,float> lerpMethod, int id, float duration, CancellationToken cancellationToken, Action<float> action, Easing easeType = Easing.Linear, AnimationCurve customCurve = null)
8395
{
96+
if (!CanTween)
97+
{
98+
return;
99+
}
100+
84101
var instanceCancellationToken = StartTween(id);
85102

86103
float t = 0;
87104
var ease = easeType != Easing.CustomCurve ? EaseFunctions.Get(easeType) : customCurve.Evaluate;
105+
88106
action?.Invoke(ease.Invoke(0));
89107

90108
while (t < duration && CanTween)

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.gameframe.gui",
33
"displayName": "Gameframe.GUI",
4-
"version": "3.0.10",
4+
"version": "3.0.11",
55
"description": "This is a library of GUI helpers for UGUI \r\nIncludes a panel system that implements a navigation stack. \r\nIncludes a scene transition system. \r\nIncludes a SRP shader for blurring the background of UI panels.",
66
"keywords": [],
77
"author": {

0 commit comments

Comments
 (0)