Skip to content

Commit

Permalink
Merge pull request #4 from techno-dwarf-works/refactoring
Browse files Browse the repository at this point in the history
Version 0.0.3
  • Loading branch information
OpOpYaDev committed Aug 31, 2024
1 parent 4846c7c commit 340ffc2
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 2 deletions.
24 changes: 24 additions & 0 deletions Runtime/Extensions/TweenCoreExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,31 @@ public static IEnumerable<TweenCore> AddTrigger(this IEnumerable<TweenCore> self

return self;
}

public static TweenCore AddTrigger(this TweenCore self, TweenCoreAction action, CancellationToken cancellationToken, string id = Trigger.UndefinedId)
{
if (!ValidationUtility.ValidateNullReference(self))
{
return null;
}

if (!ValidationUtility.ValidateNullReference(action))
{
return self;
}

var trigger = new CancellationTokenTrigger(id, action, cancellationToken);
return self.AddTrigger(trigger);
}


public static TweenCore AddTrigger<TAction>(this TweenCore self, CancellationToken cancellationToken, string id = Trigger.UndefinedId)
where TAction : TweenCoreAction, new()
{
var action = new TAction();
return self.AddTrigger(action, cancellationToken, id);
}

#if BETTER_CONDITIONS

public static TweenCore AddTrigger(this TweenCore self, TweenCoreAction action, Condition condition, string id = Trigger.UndefinedId)
Expand Down
21 changes: 21 additions & 0 deletions Runtime/Triggers/CancellationTokenTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Threading;
using Better.Tweens.Runtime.Actions;

namespace Better.Tweens.Runtime.Triggers
{
public class CancellationTokenTrigger : ActionTrigger
{
private readonly CancellationToken _cancellationToken;

public CancellationTokenTrigger(string id, TweenCoreAction action, CancellationToken cancellationToken)
: base(id, action)
{
_cancellationToken = cancellationToken;
}

public override bool Invoke(TweenCore tweenCore)
{
return _cancellationToken.IsCancellationRequested && base.Invoke(tweenCore);
}
}
}
3 changes: 3 additions & 0 deletions Runtime/Triggers/CancellationTokenTrigger.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "com.tdw.better.tweens",
"displayName": "Better Tweens",
"version": "0.0.2",
"version": "0.0.3",
"unity": "2021.3",
"description": " ",
"dependencies": {
"com.tdw.better.internal.core": "0.0.2",
"com.tdw.better.projectsettings": "0.1.3",
"com.tdw.better.commons": "0.0.44",
"com.tdw.better.conditions": "0.0.4",
"com.tdw.better.statemachine": "0.1.17",
"com.tdw.better.attributes": "0.0.1"
},
Expand Down

0 comments on commit 340ffc2

Please sign in to comment.