GithubHelp home page GithubHelp logo

kyrylokuzyk / primetween Goto Github PK

View Code? Open in Web Editor NEW
655.0 655.0 25.0 6.59 MB

High-performance, allocation-free tween library for Unity. Create animations, delays, and sequences in one line of code.

Home Page: https://assetstore.unity.com/packages/slug/252960

License: Other

C# 100.00%
animation camera-shake delay ease easing game-feel interpolation screen-shake sequence tween tweening unity

primetween's People

Contributors

kyrylokuzyk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

primetween's Issues

GetTweensCount broken for sequences

Hello,

I am trying to use Tween.GetTweensCount(transform) to determine if an object is being animated without having access to the Tween/Sequence involved. However, what happens is that processAll_internal asserts so I never get a non-zero value back.

My expectation is that I would get N tweens back where N is the number of tweens involved even if they are part of a sequence.

Please let me know if I am missing something.

Thanks!

How to SetEase to a ShakeLocalPosition?

I'm trying to reproduce a shake with OutCubic ease previously achieved with DOTween chaining like this:

transform.DOShakePosition(duration, strength, frequency, randomness)
                 .SetEase(Ease.OutCubic) // Using OutCubic for a fast start and slow end

With PrimeTween I used the easeBetweenShakes parameter but as expected it doesn't output the same result: the ease happens between each shake whereas I want the ease to happen over the overall animation duration, if that makes sense...

Tween.ShakeLocalPosition(transform, strength: new Vector3(25f, 0f, 0), duration: 0.5f, frequency: 12, enableFalloff: true, easeBetweenShakes: Ease.OutCubic)

Not sure if this is achievable with current version (currently using 1.1.10) or if this can be a feature request?
Thanks!

Commercial use help wanted.

Hey, there are a few questions I have. I highly appreciate it if you can answer those questions. Because I have migrated the whole game to this from DOTween to test it out. And it works pretty well.

  1. Is this software free to use in commercial apps?
  2. I have a few project-specific features to be implemented. With those features, this is going to be directly embedded in the project's binary itself. Does the current license permit such things?

Overshoot / Amplitude for Back / Elastic Ease?

Is there some obvious way, that I am missing, to get an overshoot for Back Eases? I know I can use custom curves, but that's an overkill for a simple thing I use all the time. I often use something like OutBack with overshoot to amplify the Back effect in DOTween...

Similar question goes for amplitude in Elastic Eases

Unity Package Manager support

Would be great to add package manager support for this plugin. Using package manager allows for cleaner updates and workflows.

Demo classes should be in namespace

Demo classes should be in namespace, maybe PrimeTween.Demo or something.
If importing to existing Project, demo has classes that are using common names such as "Demo" and "Door" as class names and its prone to cause conflicts if project already contains them in global namespace. Many developers want to easily evaluate the project even if they will delete the demo assets afterwards.

Assert method call in Sequence causes allocation

Hi, im facing some runtime allocation when using Sequence, specifically there is some Assert method call that create the allocation.

image

I'm profiling in the Unity Editor(Play Mode). Will this also happen in build(ex: Android)? Please let me know if you need more information, I'm kind of in a hurry.

Interpolation factor can be calculated incorrectly when cyclic tween is not started yet

For this given code, it should have been:

Repeat 1...3 
1. Sprite Turns Red → White (Rewind)
2. LocalTransform (0,0,0) → (0,1,0) (Rewind)
3. Sprite Turns Green → Light Green (Rewind)
public int cycles = 10;
public Collider2D anyCollider2D;
        
private Sequence _sequence;
public TweenSettings<Color> tweenSettingsWindUp;
public TweenSettings<Vector3> tweenSettingsPositionActive;
public TweenSettings<Color> tweenSettingsCooldown;

public SpriteRenderer cross;

private void OnEnable()
{
    anyCollider2D.enabled = false;
    if (_sequence.isAlive) _sequence.Complete();
    _sequence = Sequence.Create(cycles)
            .Chain(Tween.Color(cross, tweenSettingsWindUp))
            .ChainCallback(() =>
            {
                anyCollider2D.enabled = true;
                cross.color = Color.red;
            })
            .Chain(Tween.LocalPosition(cross.transform, tweenSettingsPositionActive))
            .ChainCallback(() => { anyCollider2D.enabled = false; })
            .Chain(Tween.Color(cross, tweenSettingsCooldown))
        ;
}

What happens:

Repeat 1...?
1. Sprite Turns Red → White (Rewind)
2. LocalTransform (0,0,0) → (0,1,0) (Rewind)
3. Sprite Turns Green → Light Green (Rewind)
?. OnComplete:  LocalTransform (0,0,0) → (0,1,0)
Recording.2024-04-08.001752.mp4

Unity 2022.3.17f1 last update

For some unknown reason latest version [1.1.11] from the assetstore ist not working for me in this mentioned version of Unity.

What I did:
Updated package - everything went red Tween and Ease could not be found. I checked and compared files everything was as it should be so I tried another experiment.

I created fresh project and imported new version - not working.
Imported old version (one below) - working.

I dont mind this as the older version is without bugs for me its just seems really weird. Any ide what could be the reason?

Edit: Im using PrimeTween for months now so this is not my first update rodeo :D

Sequence.Insert() feature request

  1. Group + Delay cannot replace ChainCallback
    It seems that PrimeTween's sequence does not have time point control. Although we use ChainCallback and Group(Tween.Delay()) to set callbacks at the same time point, they have different behaviors.

  2. It seems that we need "Insert"
    In your explanation, you mentioned that "Group" is the same as "Join" and we can use "Group(Tween)" instead of "Insert". However, this has raised a question. In DoTween, "Insert" does not impact the main Sequence, whereas "Join" is similar to "Append" and does affect the main Sequence. As the example shows, it's not always possible to replace "Insert" with "Group".
    Sometimes, we need callbacks to run during a Chain (when the Chain's duration is 1f, the callback needs to run at 0.5f). This means that ChainCallback cannot be used in this situation. Unfortunately, Group + Delay cannot work either.

I apologize for my poor English, and I may use some inappropriate words. Please forgive me.

Here is the project:https://github.com/YZDwork/PrimeTweenDebug

When an ongoing tween is happening while an object is destroyed, an error is logged - with no way to disable?

Sorry if I'm missing something. I've noticed that .OnComplete() always has a "warn if null" flag; which i always set to false (i wish this was the default).

However, I frequently have UI tweens which are ongoing when a UI panel is destroyed. I could keep track of these and kill manually, I know. But coming from DoTween, I didn't have to there, so why do I have to now? If there was at least a flag I'd set it every time, "kill tween if target is null" or something. I don't care if it's null checking every frame, that's fine in this case.

Tween's target is null:  / Vector2 / duration 0.25 / id 419. This error can mean that:
- The target reference is null.
- UnityEngine.Object target reference is not populated in the Inspector.
- UnityEngine.Object target has been destroyed.
Please ensure you're using a valid target.

UnityEngine.Debug:LogError (object)
PrimeTween.PrimeTweenManager:addTween_internal (PrimeTween.ReusableTween) (at ./Packages/com.kyrylokuzyk.primetween/Runtime/Internal/PrimeTweenManager.cs:317)
PrimeTween.PrimeTweenManager:addTween (PrimeTween.ReusableTween) (at ./Packages/com.kyrylokuzyk.primetween/Runtime/Internal/PrimeTweenManager.cs:310)
PrimeTween.PrimeTweenManager:Animate (PrimeTween.ReusableTween) (at ./Packages/com.kyrylokuzyk.primetween/Runtime/Internal/PrimeTweenManager.cs:290)
PrimeTween.Tween:animate (object,PrimeTween.TweenSettings`1<UnityEngine.Vector2>&,System.Action`1<PrimeTween.ReusableTween>,System.Func`2<PrimeTween.ReusableTween, PrimeTween.ValueContainer>) (at ./Packages/com.kyrylokuzyk.primetween/Runtime/Internal/TweenGenerated.cs:2019)
PrimeTween.Tween:UISizeDelta (UnityEngine.RectTransform,PrimeTween.TweenSettings`1<UnityEngine.Vector2>) (at ./Packages/com.kyrylokuzyk.primetween/Runtime/Internal/TweenGenerated.cs:1233)
PrimeTween.Tween:UISizeDelta 
...

LeanTween conversion

Replacing LeanTween in someone else's code with this. I thought I'd share the comparison code for anyone interested. Thanks for the project.

LeanTween.rotateLocal([TRANSFORM], [VECTOR3], [DURATION]).setEaseInOutSine();

becomes

 Tween.LocalRotation([TRANSFORM], [VECTOR3], [DURATION], Ease.InOutSine);

Using tween.Complete() after using a loop to modify the Scale value will cause the scale value to be abnormal.

version is 1.1.9, My code like this:

        [SerializeField] private Image mIvCircle;
        private Tween? mTweenCircle;
        public void ShowCircleAni()
        {
            mTweenCircle?.Stop();
            //The original scale size is 1f
            mTweenCircle = Tween.Scale(mIvCircle.rectTransform, 0.7f, 0.5f, cycles: -1, cycleMode: CycleMode.Yoyo);
            Test().Forget();
        }


        /// <summary>
        /// Test Complete
        /// </summary>
        private async UniTask Test()
        {
            await UniTask.Delay(2000);
            //TODO:  Will cause the size of the control to become 1.9f 
            mTweenCircle?.Complete();
        }

image

Tweens do not have a fixedUpdate update mode?

I see you have an "useUnscaledTime" parameter, but there's no "useFixedTime" parameter. I'm currently trying out the plugin to replace DoTween, but we use fixed update tweens quite often.

Fixed in 1.1.16: enabling PRIME_TWEEN_SAFETY_CHECKS in IL2CPP builds throws exception

I've been using PrimeTween well, but today when I built my game on an Android device, all of my PrimeTwins are throwing an assertion like the error message below and the tweening doesn't work(In Unity Editor, it works well without bug.).

All of PrimeTween tweenings are throwing that assertion.
This isn't the first time I've built with PrimeTween since it was applied, and it's been working fine, but starting with the version I built today, it's not working.

I suspect this may not be a PrimeTween-specific issue, but rather a conflict with something I've done.
There are currently 2 possible causes I think.

  1. https://github.com/Mr-sB/UnityTimer => I applied this package to my project,
  2. I added and then removed the Assembly Definition (in a different path that doesn't include PrimeTween).
    Please take a look at the error message and let me know if you have any answers.

2024-04-11 17:16:41.204 12460 12490 Error Unity AssertionException: Assertion failure. Value was False
2024-04-11 17:16:41.204 12460 12490 Error Unity Expected: True
2024-04-11 17:16:41.204 12460 12490 Error Unity at UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at PrimeTween.StackTraces.Record (System.Int32 id) [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at PrimeTween.PrimeTweenManager.addTween_internal (PrimeTween.ReusableTween tween) [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at PrimeTween.Tween.Scale (UnityEngine.Transform target, UnityEngine.Vector3 endValue, System.Single duration, PrimeTween.Ease ease, System.Int32 cycles, PrimeTween.CycleMode cycleMode, System.Single startDelay, System.Single endDelay, System.Boolean useUnscaledTime) [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at Talk.Boing () [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at Talk.Say (System.String _text, System.Single timeout) [0x00000] in <00000000000000000000000000000000>:0
2024-04-11 17:16:41.204 12460 12490 Error Unity at PlayerHuman.OnChangeState_BattleDefence () [0x00000] in <00000000

The looping functionality within the Tween seems not working.

I tried replacing the DOTween statement with PrimeTween, but instead of continuously scaling up and down, it just stops at the final number.

// DOTween
transform.DOScale(1.1f, 0.25f).SetLoops(-1, LoopType.Yoyo);

// PrimeTween
Tween.Scale(transform, 1.0f, 1.1f, 0.25f, Ease.Linear, -1, CycleMode.Yoyo);

The name 'Assert' does not exist in the current context

Unity 2022.3.12f1 on Windows

Assets\Plugins\PrimeTween\Demo\Scripts\MeasureAllocations\MeasureMemoryAllocations.cs(64,21): error CS0103: The name 'Assert' does not exist in the current context

Adding "using UnityEngine.Assertions;" solves it. Installing PrimeTween also solves it.

Chaining PositionAtSpeed tweens doesn't work as expected

        Sequence.Create()
            .Chain(Tween.PositionAtSpeed(transform, pos1, _moveSpd, Ease.InCubic))
            .Chain(Tween.PositionAtSpeed(transform, pos2, _moveSpd, Ease.Linear))
            .Chain(Tween.PositionAtSpeed(transform, pos3, _moveSpd, Ease.OutCubic));

I expect the following code to move my object sequentially: start -> pos1 -> pos2 -> pos3.
Instead, the object position is reset on each tween: start -> pos1, start -> pos2, start -> pos3.

Using Position instead of PositionAtSpeed works as expected.

Incremental Cycle doesn't work properly with Rotation Tween.

Hello there!
Not sure if anyone else has this issue, too, but for the LocalRotation tween, when i use the Incremental Cycle Mode, the cycles don't work properly. It loops only once, then it rewinds like it was set to Yoyo Cycle Mode, and then it stops.

This only happens to me with any Tween that affects Rotation. It works fine with other tweens like Position.

Here is a sample of the code i used.

Tween.LocalRotation(rotateTransform, new Vector3(0, 0, 180), 0.3f, Ease.Linear, -1, CycleMode.Incremental, useUnscaledTime: true);

Thank you for your time.

Sequence Tween.OnComplete early call when Time.timeScale = 15

Sorry for my poor english.
the code is that

Time.timeScale = 15;
var myTrans = transform;
myTrans.localScale = new Vector3(0.2f, 0.2f, 0.2f);
Sequence
    .Create(Tween.Scale(myTrans, 1.2f, 0.2f, Ease.OutSine).OnComplete(() => { Debug.Log("Tween1 " + myTrans.localScale); }))
    .Chain(Tween.Scale(myTrans, 1, 0.1f, Ease.OutBack).OnComplete(() => { Debug.Log("Tween2 " + myTrans.localScale); })
    );

I set timeScale to 15, , but Tween2 prints out before Tween1, which is the reverse order.

DontDestroyOnLoad errors

Existence of DontDestroyOnLoad(go) in PrimeTweenManager causes below errors when changing scenes. After removing this line, they go away:

AssertionException: Add 'PRIME_TWEEN_SAFETY_CHECKS' to 'Project Settings/Player/Scripting Define Symbols' to see which tween produced this error (works only in Development Builds).

Assertion failure. Value was False
Expected: True
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <30adf90198bc4c4b83910c6fb1877998>:0)
UnityEngine.Assertions.Assert.IsTrue (System.Boolean condition, System.String message) (at <30adf90198bc4c4b83910c6fb1877998>:0)
PrimeTween.Assert.IsTrue (System.Boolean condition, System.Nullable`1[T] tweenId, System.String msg) (at Assets/Scripts/PrimeTween/Runtime/Internal/Assert.cs:23)
PrimeTween.ReusableTween.getSequenceSelfChildren (System.Boolean isForward) (at Assets/Scripts/PrimeTween/Runtime/Internal/ReusableTween.cs:177)
PrimeTween.ReusableTween.updateSequence (System.Single _elapsedTimeTotal, System.Boolean isRestart) (at Assets/Scripts/PrimeTween/Runtime/Internal/ReusableTween.cs:168)
PrimeTween.ReusableTween.SetElapsedTimeTotal (System.Single newElapsedTimeTotal) (at Assets/Scripts/PrimeTween/Runtime/Internal/ReusableTween.cs:81)
PrimeTween.ReusableTween.updateAndCheckIfRunning (System.Single dt) (at Assets/Scripts/PrimeTween/Runtime/Internal/ReusableTween.cs:68)
PrimeTween.PrimeTweenManager.update (System.Collections.Generic.List`1[T] tweens, System.Single deltaTime, System.Single unscaledDeltaTime, System.Int32& processedCount) (at Assets/Scripts/PrimeTween/Runtime/Internal/PrimeTweenManager.cs:161)
PrimeTween.PrimeTweenManager.Update () (at Assets/Scripts/PrimeTween/Runtime/Internal/PrimeTweenManager.cs:139)

and continuous spam of

Exception: updateDepth != 0
PrimeTween.PrimeTweenManager.update (System.Collections.Generic.List`1[T] tweens, System.Single deltaTime, System.Single unscaledDeltaTime, System.Int32& processedCount) (at Assets/Scripts/PrimeTween/Runtime/Internal/PrimeTweenManager.cs:143)
PrimeTween.PrimeTweenManager.Update () (at Assets/Scripts/PrimeTween/Runtime/Internal/PrimeTweenManager.cs:139)

SetCycles then StopAll cause AssertFail

PrimeTween 1.0.17

Update

  • 2023-11-21

Environment

  • Unity 2019.4.32f1
  • PrimeTween 1.0.17

Reproduce steps

  1. Open project
  2. Open Test1.unity
  3. Play

Error

AssertionException: Assertion failure. Values are not equal.
Expected: 0 == 1
UnityEngine.Assertions.Assert.Fail (System.String message, System.String userMessage) (at <781ae7ac455e4981a7a57fe4b3a3ae5b>:0)
UnityEngine.Assertions.Assert.AreEqual[T] (T expected, T actual, System.String message, System.Collections.Generic.IEqualityComparer`1[T] comparer) (at <781ae7ac455e4981a7a57fe4b3a3ae5b>:0)
UnityEngine.Assertions.Assert.AreEqual[T] (T expected, T actual, System.String message) (at <781ae7ac455e4981a7a57fe4b3a3ae5b>:0)
PrimeTween.Assert.AreEqual[T] (T expected, T actual, System.String msg) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Internal/Assert.cs:7)
PrimeTween.ReusableTween.rewindIncrementalTween () (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Internal/ReusableTween.cs:155)
PrimeTween.Sequence.restart_internal () (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Sequence.cs:395)
PrimeTween.Sequence.restart () (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Sequence.cs:376)
PrimeTween.Sequence.onTweenKilled (System.Int32 tweenId) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Sequence.cs:235)
PrimeTween.ReusableTween.updateSequenceAfterKill () (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Internal/ReusableTween.cs:401)
PrimeTween.Tween+<>c.<StopAll>b__838_0 (PrimeTween.ReusableTween tween) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/TweenMethods.cs:30)
PrimeTween.PrimeTweenManager.processAll_internal (System.Object onTarget, System.Predicate`1[T] predicate, System.Nullable`1[T] minExpected, System.Nullable`1[T] numMaxExpected) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Internal/PrimeTweenManager.cs:379)
PrimeTween.PrimeTweenManager.processAll (System.Object onTarget, System.Predicate`1[T] predicate, System.Nullable`1[T] numMinExpected, System.Nullable`1[T] numMaxExpected) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/Internal/PrimeTweenManager.cs:367)
PrimeTween.Tween.StopAll (System.Object onTarget, System.Nullable`1[T] numMinExpected, System.Nullable`1[T] numMaxExpected) (at Library/PackageCache/com.kyrylokuzyk.primetween@2728f0d0794b-1699791494000/Runtime/TweenMethods.cs:28)
Test1.Update () (at Assets/Test1.cs:20)

Key

SetCycles() is the key line. If you don't set it at all, then all things works perfectly.

Repository

Redundant error message log spam when using useFixedUpdate on both a Sequence and its Tweens

Here is some example code. The sequence has useFixedUpdate, and the Tween also has useFixedUpdate.
image

This results in the following error log:

'useFixedUpdate' was ignored after adding tween/sequence to the Sequence. Parent Sequence controls isPaused/timeScale/useUnscaledTime/useFixedUpdate of all its children tweens and sequences.

It shouldn't log when I'm intentionally using fixed update?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.