Skip to content

Custom CanTween override and NRE fix merge #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ Includes a SRP shader for blurring the background of UI panels.
#### Using UnityPackageManager (for Unity 2019.3 or later)
Open the package manager window (menu: Window > Package Manager)<br/>
Select "Add package from git URL...", fill in the pop-up with the following link:<br/>
https://github.com/coryleach/UnityGUI.git#3.0.10<br/>
https://github.com/coryleach/UnityGUI.git#3.0.11<br/>

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

Find the manifest.json file in the Packages folder of your project and edit it to look like this:
```js
{
"dependencies": {
"com.gameframe.gui": "https://github.com/coryleach/UnityGUI.git#3.0.10",
"com.gameframe.gui": "https://github.com/coryleach/UnityGUI.git#3.0.11",
...
},
}
Expand Down
22 changes: 20 additions & 2 deletions Runtime/Tween/TweenExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,21 @@ public static class TweenExtensions
private static CancellationTokenSource _cancellationTokenSource;
private static Dictionary<int, TweenData> _tweenDict;

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

private static bool CanTween => Application.isPlaying && !CancellationToken.IsCancellationRequested;
private static bool CanTween => CanTweenPredicate.Invoke();

private static Func<bool> _canTweenPredicate = DefaultCanTweenPredicate;
public static Func<bool> CanTweenPredicate
{
get => _canTweenPredicate;
set => _canTweenPredicate = value ?? DefaultCanTweenPredicate;
}

private static bool DefaultCanTweenPredicate()
{
return Application.isPlaying && !CancellationToken.IsCancellationRequested;
}

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

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)
{
if (!CanTween)
{
return;
}

var instanceCancellationToken = StartTween(id);

float t = 0;
var ease = easeType != Easing.CustomCurve ? EaseFunctions.Get(easeType) : customCurve.Evaluate;

action?.Invoke(ease.Invoke(0));

while (t < duration && CanTween)
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "com.gameframe.gui",
"displayName": "Gameframe.GUI",
"version": "3.0.10",
"version": "3.0.11",
"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.",
"keywords": [],
"author": {
Expand Down