Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

How Tween System actually working?

Discussion in 'Project Tiny' started by reallyhexln, Apr 29, 2019.

  1. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Hello for everyone.

    I trying to understand how to determine if some entity has active tweener.

    I have tried to use the following code:

    Code (JavaScript):
    1. if (this.world.hasComponent(entity, ut.Tweens.TweenComponent)) {
    2.     ...
    3. }
    But it seems it doesn't working.

    The documentation for ut.Tweens.TweenService.addTween() says:

    Code (JavaScript):
    1. Creates a new tweening entity with a TweenFloat component and a TweenComponent component.
    2. This a helper function that does the following:
    3. e = createEntity
    4. addComponent(e,TweenFloat)
    5. addComponent(e,TweenComponent)
    So, it looks like I should check some another [created] entity for TweenComponent presence.

    Anyone know, how to get reference to such entity?

    Maybe, there are some another ways to determine if animation is active for entity?
    And, yes, I know about Watchers. Unfortunately, low FPS on some mobile devices may leads to animation can be stopped on some middle point between minimal and maximal values.
     
  2. reallyhexln

    reallyhexln

    Joined:
    Jun 18, 2018
    Posts:
    69
    Oh, I'm sorry, guys, I get the point:

    Code (JavaScript):
    1. this.tweenEntity = ut.Tweens.TweenService.addTween(
    2.                 this.world, this.animatingEntity,
    3.                 this.field,
    4.                 this.startValue, this..endValue,
    5.                 this.duration, this.delay,
    6.                 ut.Core2D.LoopMode.Loop,
    7.                 this.tweenType,
    8.                 true); // auto-destroy on complete
    9.  
    10. ...
    11.  
    12. if (this.tweenEntity.isNone()) {
    13.     // animation is completed
    14. }
     
  3. qoly

    qoly

    Joined:
    Jun 18, 2019
    Posts:
    12
    How Tween System actually working in C# now ? I add tween, but build failed.
    new TweenSystem().AddTween<Translation>(entity, null, pos, endPos, 5);

    What is "FieldInfo" and where get it?
     
  4. AlexMasse

    AlexMasse

    Joined:
    Jun 29, 2014
    Posts:
    19
    To start a tween on the Translation component in C#:

    Code (CSharp):
    1. var tweenSystem = World.GetExistingSystem<TweenSystem>();
    2. tweenSystem.AddTween(entity,
    3.     "Translation.Value",
    4.     new float3(0f, 0f, 0f),
    5.     new float3(10f, 0f, 0f),
    6.     1.0f,
    7.     TweenFunc.Linear,
    8.     LoopMode.Loop);
     
  5. jhgametest2

    jhgametest2

    Joined:
    Jan 11, 2019
    Posts:
    1
    thanks a lot for this sample
     
    AlexMasse likes this.