Search Unity

HOTween: a fast and powerful Unity tween engine

Discussion in 'Assets and Asset Store' started by Izitmee, Jan 7, 2012.

  1. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    941
    Hi thanks for the examples but using this method also still results in the same behaviour - which is .. it works the first time but subsequent rotations vary in direction.

    HOTween.To(this.transform, actualRotationRate, new TweenParms()
    .Prop("rotation", new PlugQuaternion(new Vector3(rotationAmount,0,0), EaseType.EaseInOutBack, true).Beyond360())
    );

    iByte
     
  2. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Can you post here an example unityPackage of this behaviour? Or otherwise write the code you're using to create both the first tween (and calculate the rotationAmount), and the subsequent ones? So I can check it out and see if it has something to do with the engine or with the usage.
     
  3. JSan

    JSan

    Joined:
    May 25, 2012
    Posts:
    7
    Hi,

    I am trying to change the speed on a moving object while running hoMove scirpt (faster where there is colider touching another one in the terrain) . I cannot do it unless I stop and restart the move - hoMove scirpt from SWS. I did it with simple Stop and StartMove method, but now I loose my path. I am not moving on the same path from waypoint to waypoint I designed before. Any suggestions, please?
     
  4. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hi JSan,

    changing the speed of a playing tween can be easily done when using HOTween. Just do:
    Code (csharp):
    1.  
    2. myTween.timeScale = newTimeScale;
    3.  
    where newTimescale can be any number.

    That said, if you're trying to change the speed directly through SWS in some other way, you should try asking the knightly Baroni (Simple Waypoint System's developer) in SWS thread (I know he implemented a way to get a reference to the current Tweener, so the above method should work).
     
    Last edited: Oct 2, 2012
  5. ibyte

    ibyte

    Joined:
    Aug 14, 2009
    Posts:
    941
    I plan to use the EaseType.EaseOutBack. I see in the API ref that the call takes parameters

    static float EaseOut ( float time,

    float startValue,
    float changeValue,
    float duration,
    float overshoot,
    float unusedPeriod

    )
    [static] Easing equation function for a back (overshooting cubic easing: (s+1)*t^3 - s*t^2) easing out: decelerating from zero velocity.
    Parameters: timeCurrent time (in frames or seconds). startValueStarting value. changeValueChange needed in value. durationExpected easing duration (in frames or seconds). overshootOvershoot ammount: higher means greater overshoot (0 produces cubic easing with no overshoot, and the default value of 1.70158 produces an overshoot of 10 percent). unusedPeriodUnused: here to keep same delegate for all ease types. Returns:The eased value.


    What I am not sure about is how do I over ride the parms on a HOTween.To call or change the default overshoot?

    EDIT: Well that took all of 5 seconds to see

    HOTween.defEaseOvershootOrAmplitude = 1f;
     
    Last edited: Oct 2, 2012
  6. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    @ibyte: while defEaseOvershootOrAmplitude changes the overshoot/amplitude of all the back/elastic tweens created after setting it, you can also set a custom overshoot directly when creating the tween :)
    Code (csharp):
    1.  
    2. HOTween.To(someInstance, 1, new TweenParms().Prop("someValue", 1).EaseType(EaseType.EaseOutBack, myCustomOvershoot));
    3.  
    EDIT: corrected the example, which had wrong code :p
     
    Last edited: Oct 3, 2012
  7. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    New HOTween Visual Editor Update: 1.0.102

    - Fixed conflicts that could derive from having NGUI installed

    As usual, latest version is on HOTween's website.

    That said, I finished at least part of the UnityEditor library inspired from MaDDoX GUILayout alternative (thanks again Breno!). I'm very happy with it. Gonna release it soon as open-source, and the will remake all HOTween Visual Editor GUI with it (don't worry it's just the GUI, and will be compatible with all older projects).
     
  8. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    On other news, I uploaded on Google Code the UnityEditor library I mentioned: HOUnityEditor. Unity forums thread is here. And, Breno, I'm gonna write you a looooong message now ;)
     
  9. JSan

    JSan

    Joined:
    May 25, 2012
    Posts:
    7
    Thanks so much for all the responses, expecially the first one, which I got few minutes after my post. Izitmee is great!
    I am glad there is Unity Community site and people willing to give their time !!! jsan.
     
  10. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Thank you ;) Glad I could be of help, and indeed Unity has a great community.
     
  11. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    New HOTween Visual Editor BIG Update: v1.1.001

    - Inspector and window interface is much more neat and functional, and occupies less space (it was completely redone with the HOUnityEditor libraries I worked on recently - again, thanks got to MaDDoX for the suggestion)
    - Fixed some bugs in the undo system
    - Checked that everything works with Unity 4 (it does)

    As usual, latest version is on HOTween's website, but I'll finally also submit the Visual Editor to the Asset Store.

    IMPORTANT: updating from a previous version won't break your project, but requires that you:

    1. Import the new HOTweenEditor package as usual (a bunch of errors will appear in the console - just ignore them)
    2. Proceed to delete the following directories:
      • Holoville/Editor
      • Holoville/GUI
    3. Proceed to delete the following files:
      • Holoville/HOTween Extensions/HOTweenManager/Core/HOTweenPanelMode (pay attention not to delete the file with the same name in the.../HOTweenManager/Editor/Core directory)
    Don't delete those directories and files BEFORE importing the new package, or you'll have to re-assign all the HOTween components (sigh, that's why I always prefer DLLs)! And just to be on the safe side backup your project before upgrading.

    Here is a BEFORE and AFTER the plastic surgery pic:

    $visualeditors-comparison.png

    And here is a legend of the new/changed buttons and colors:

    $visualeditor-newgui.png
     
    Last edited: Oct 4, 2012
  12. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Nice job on the new editor! I really like the color code if there's something missing. I'm doing this as well for my custom inspectors so the level designers have a pretty big clue if they messed up ;)

    I have a feature request:
    Would it be possible to Append/Insert callbacks in a Sequence?
    For now I add OnComplete callbacks to Tweens but that's not always possible and not very clean.

    Thanks and keep up the good work!
     
  13. dev_peter

    dev_peter

    Joined:
    Aug 9, 2012
    Posts:
    38
    how can I tween only the x-Position?
    I've tried
    HOTween.To(mt.transform.localPosition,1,"x", 100);
    but it's not working.

    My workaround for now: HOTween.To(mt.transform,1,"localPosition", new Vector3(100,mt.transform.localPosition.y,mt.transform.localPosition.z));
    but I'm sure I can just set a single value, or?
     
  14. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Hi dev_peter,

    You can tween a Vector3 component by using the PlugVectorX, PlugVectorY or PlugVectorZ plugins.

    Code (csharp):
    1. HOTween.To(transform, 1.0f, new TweenParms().Prop("localPosition", new PlugVector3X(100.0f)));
    You can find the documentation right here: http://www.holoville.com/hotween/documentation.html#tweenplugins

    You must not forget to add this to your includes or it won't compile.
    Code (csharp):
    1. using Holoville.HOTween.Plugins;
     
  15. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hey Dgizusse, glad you like it (and I agree: color codes are sooo important ;)), and thanks for answering dev_peter.

    About your feature request, when I need an inner callback I actually add OnCompletes/OnStart to the inner Tweeners/Sequences. Let me understand if I got it correctly... you'd like to do this?
    Code (csharp):
    1.  
    2. mySequence.Append(myTween0); // Append regular tween
    3. mySequence.AppendCallback(myFunction0); // Called when myTween0 is complete
    4. mySequence.Append(myTween1);
    5. mySequence.Append(myTween2);
    6. mySequence.AppendCallback(myFunction1); // Called when myTween2 is complete
    7. mySequence.InsertCallback(0.5f, myFunction2); // Called after 0.5 seconds of playing the sequence
    8.  
     
  16. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    That's exactly it.

    The OnComplete/OnStart usually are enough, but with more complex sequences where I need to time animations and events it gets a lot more tricky...
     
  17. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Mhmm might not be that simple, but I like how it sounds. Putting it into my TODO list. Right now I'm working on a Pool Manager, but as soon as I complete it (should be within the week, hopefully) I'll try to add this feature.
     
  18. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    I've just encountered a bug (or more) in Looping Sequences...

    With the following code
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Holoville.HOTween;
    4.  
    5. public class TestSequence : MonoBehaviour {
    6.  
    7.     private Sequence s;
    8.  
    9.     void Start () {
    10.         s = new Sequence();
    11.         Tweener t = HOTween.To(transform, 0.5f, "position", Vector3.one);
    12.         t.ApplyCallback(CallbackType.OnComplete, OnComplete);
    13.         t.ApplyCallback(CallbackType.OnPlay, OnPlay);
    14.         t.ApplyCallback(CallbackType.OnStart, OnStart);
    15.         s.Append(t);
    16.         //s.AppendInterval(0.1f);
    17.        
    18.         s.loops = -1;
    19.         s.Play();
    20.     }
    21.    
    22.     void OnComplete() {
    23.         Debug.Log("OnComplete");
    24.     }
    25.  
    26.     void OnPlay() {
    27.         Debug.Log("OnPlay");
    28.     }
    29.  
    30.     void OnStart() {
    31.         Debug.Log("OnStart");
    32.     }
    33. }
    34.  
    I'll get this output:
    OnStart

    That's it. The OnComplete callback for the tween is never called. Neither is the OnPlay,
    If you uncomment the Interval, OnComplete will get called every loop. The OnStart will will get called once and OnPlay will never be called.

    Is this the expected behavior?

    Thanks!
     
  19. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Sorry if it took me a while to answer, but I wanted to be sure of what I said, so I built a test too. In theory yes, this is the expected behaviour, though I see why an AppendCallback chainmethod is even more needed than I thought.

    For what concerns nested tweens:
    - OnPlay is never called (since they're always in a kind of paused state, in order to be controlled by the sequence)
    - OnComplete is never called (except in very rare cases) on the last nested tween (unless there's a decent interval after that), until the final loop cycle. That's because, in the case of a sequence loop, a nested tween won't be really complete unless the "sequence timeline" is playing a position that is equal or higher than the tween's completion time. It all goes down to HOTween's "precise" time animation (which is an intended feature I really wanted to implement when I made it). Let me explain it a little better, since this sounds way more complicated than it is.

    HOTween's precise time animation
    Let's say we're animating a float property MyProp in infinite 1-second loops.
    - Each frame, HOTween calculates how much time has passed, and advances the animation consequently. But what exactly happens when a second has gone by?
    - HOTween calculates how much time has passed, and what is the total time since the start of the current loop. Since a frame doesn't happen every single millisecond, the total time will most certainly not be exactly 1, but something like 1.010.
    - In a regular tween, the animation would be simply placed at its end position, thus "wasting" those 0.010 additional seconds, and then would wait the next frame to restart another loop cycle. In the case of HOTween instead, this is where the "precise time animation" feature will kick in. It will know it's a loop, and will calculate exactly where the animation should be, and thus place it at a time position of 0.010 (as if the next loop cycle had already restarted).

    This allows for perfect timing of animations that are running together, with different loop times. Example:
    Let's animate two properties: MyProp0 and MyProp1, in infinite loops. Each MyProp0 loop duration is set to 0.5, while each MyProp1 loop duration is set to 1. With a "regular" tween, after one minute, we would see that MyProp0 hasn't looped exactly double the times than MyProp1, because some milliseconds were lost and accumulated each time a completion happened (those wasted 0.010 seconds). With HOTween instead, even after 10 minutes, MyProp0 loops would still be MyProp1 total loops x 2.

    Blabbering apart
    Blabbering apart, I see that: 1) I should document nested callbacks better, 2) I should allow OnComplete to be called on nested tweens, even if they're the last of a loop cycle. I will definitely look into that.

    In the meantime, if you add an OnStepComplete callback to the sequence, it will be called each time the full sequence animation completes and a new loop cycle restarts.
     
  20. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Thanks for the in-depth response.
    I agree that precise time animation is the only way to go.

    OnStepComplete won't cut it for my specific needs where I need OnStart to be called on each loop for specific tweens. I can't use the previous tween OnComplete because there's no OnComplete for intervals.

    My sequence looks like this:
    Code (csharp):
    1. s = new Sequence();
    2. s.Append(0.5 sec tween)
    3. s.Append(0.5 sec tween with OnCompleteCallback to trigger an anim)
    4. s.Append(1.0 sec tween with OnCompleteCallback to trigger a tutorial event)
    5. s.Insert(at 1.0 sec, 1.0 sec tween)
    6. s.Insert(at 1.0 sec, 0.5 sec tween)
    7. s.AppendInterval(1.0 sec)
    8. s.Append(1.0 sec tween with OnStartCallback to trigger an anim)
    9. s.Insert(after interval + 0.25 sec, 0.5 sec tween with OnStartCallback to trigger a tutorial event)
    10. s.Insert(after interval + 0.5 sec, 0.5 sec tween to fade out a tk2dSprite)
    11. s.AppendInterval(1.0 sec)
    This sequence is used in a tutorial to simulate the player input and interaction with the game and it must loop until the player clicks to continue.

    I hope this clarifies my issue and why I can't wait to have Append/InsertCallback for Sequence!
     
  21. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    I see. Ok, then I'll start working on it tomorrow :)

    And by the way, I forgot to talk about OnStart. OnStart Is called only once, because it's only called when a tween is started the very first time.
     
  22. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    Yay!
    Let me know if you need help with the testing.
     
  23. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Sure! Will send you a beta as soon as I have it.
     
  24. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Whew, this was tough (especially to manage the correct order in restarting/reversed loops) :p But here it is: HOTween v1.1.430. Now up to you for additional testing before release :)

    You now have AppendCallback and InsertCallback methods available in a Sequence, like:
    Code (csharp):
    1.  
    2. mySequence.AppendCallback(MyCallback);
    3. mySequence.InsertCallback(insertPosition, MyCallback);
    4.  
    P.S. supports all types of callbacks: simple, with TweenEvent and parameters, and with SendMessage
     
  25. Dgizusse

    Dgizusse

    Joined:
    Feb 1, 2012
    Posts:
    30
    That was faster than I expected ;)

    No bugs found so far in my initial tests.
    That makes sequence so much more clean and easy to setup! Awesome!
     
  26. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Wonderful! Then I'll post the official release tomorrow :) (now I'm off the code and trying to paint a cover for my amazing comic-lady :p)
     
  27. MaDDoX

    MaDDoX

    Joined:
    Nov 10, 2009
    Posts:
    758
    Just stepping by to say again what everyone should know already: this is the BEST tweener for Unity, nothing comes close :)

    Daniele, thanks but I'm not worthy of your compliments, I was just connecting dots when I figured that out (well, that's what designers do right? Heh) but I'm really glad I cold help and now we have a much better editor - due to your amazing work, again.

    On our end, now that we're finally done with the new RageSprite - dude, that was an odyssey - I'll test your new version and see if it's all fine and dandy to add it to the final package.

    Thanks again, you're the man :)
     
  28. absameen

    absameen

    Joined:
    Oct 5, 2011
    Posts:
    121
    Hi Daniele,

    Just wanted to say great work on HOTween. The performance and flexibility of the sequencer is very impressive. I'm looking forward to seeing what direction you'll be taking with this great tweening engine. :)
     
  29. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    New update: HOTween v1.1.430

    - Added AppendCallback and InsertCallback methods to Sequences

    EDIT: please note that callbacks appended to Sequences work only with "root" Sequences, and not with nested ones.

    As usual, latest version is on HOTween's website, though both HOTween and HOTween Visual Editor are also in the Asset Store (but need approval time to be updated - usually half a day)

    @MaDDoX: yey, thanks, you got me all giddy and blushy ;) And you're more than worth any compliment I throw at you. Apart the admiration I have for your Rage stuff, you have no idea how those dots you smartly connected changed my editor coding: it's like breathing a whole new and much fresher air, and I'm still excited about that.

    @absameen: hi, and thanks :) Even if I still didn't use it much, I'm a big fan of Animator, which I consider an indispensable addition to Unity. About directions, I will probably just stick to gathering more feedback and optimizing this HOTween version, before starting the V2 I have in mind - and partially tested - since a lot (faster and more flexible). Though that won't happen before many months: I want HOTween to reach at least one year of age (which will happen this december) before starting to work on a new version - not to mention that I'll also have to find the time :p
     
    Last edited: Oct 12, 2012
  30. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    By the way, since I mentioned the HOUnityEditor libraries here, I though I should mention that they moved. The new project home is HOUnityLibs, where I'm sharing some of the global libraries I use for projects (still relatively few, since I will slowly move them from the previous repository I was using).
     
  31. absameen

    absameen

    Joined:
    Oct 5, 2011
    Posts:
    121
    Hi Daniele,

    Just to let you know, we have decided to start incorporating HOTween into the Animator timeline due to the overwhelming demand for HOTween support from the community; I hope that we have your support in doing so :). We believe that your tweening engine will better suit the Unity community's needs and definitely deserves more recognition.

    I've been working on the HOTween port and am finding the new AppendCallback very useful, but it doesn't seem to be working when used in a sequence that is added to another sequence.

    On another note, would it be possible to allow the use of external plugins? It would make HOTween much more flexible and easier to extend.

    After using HOTween for only a couple of days, we truly believe that your tweening engine should be the standard for any tweening needs in Unity. Once again, great work, and looking forward to hearing from you again.
     
  32. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hi absameen,

    I'm happy to hear the news. Many thanks for the kind words, and you obviously have all my support :)

    About the new Sequence callbacks, they work only within the main "root" Sequence, and are not intended to work in nested ones. My fault for not mentioning it: updating the docs now. If you think it's a needed feature, I'll see about implementing it.

    About external plugins: sure. That was a thing I meant to do since the beginning, but then postponed it a lot. Will start working on it after the weekend.
     
  33. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    I just started using HOTween and for most of what I want it works. But there's one case I can't figure out. How do you produce something like this (pseudo-code):

    Code (csharp):
    1. Sequence ( function_callback, (wait for time t), function_callback, (wait for time t)
    2. .Loop (infinite)
    3. .Ease (none)
    So basically I want to delay function execution over time. Sure there are other methods to do that, but using a tween engine like HOTween seems fit for the job, too. How would I go about it?
     
  34. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hi Bradamante,

    if I understood correctly, you'd like to create a Sequence which doesn't contain any tweens, but is just used to delay function calls overtime? Never thought to use it like that, but you could do it like this:
    Code (csharp):
    1.  
    2. Sequence emptySeq = new Sequence(new SequenceParms()
    3.     .Loops(-1) // Setting loops to -1 makes them infinite
    4. );
    5. emptySeq.AppendCallback(function_callback);
    6. emptySeq.AppendInterval(1);
    7. emptySeq.AppendCallback(function_callback);
    8. emptySeq.AppendInterval(1);
    9. emptySeq.Play();
    10.  
    That said, using an empty Sequence like that would be a waste of resources, and unless you plan to place a tween in there, I'd suggest using a simple infinite coroutine, which would achieve the same result:
    Code (csharp):
    1.  
    2. void Start()
    3. {
    4.     StartCoroutine(CallbackCoroutine());
    5. }
    6. IEnumerator CallbackCoroutine()
    7. {
    8.     while(true) {
    9.         function_callback();
    10.         yield return new WaitForSeconds(1);
    11.         function_callback();
    12.         yield return new WaitForSeconds(1);
    13.     }
    14. }
    15.  
     
  35. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    New HOTween update: v1.1.500

    - External plugins can now be created and used for tweens, by inheriting from Holoville.HOTween.Plugins.Core.ABSTweenPlugin

    You can find an example custom plugin (which works exactly as the core PlugVector3 plugin) on HOTween's Google Code downloads, and the latest HOTween version there or on HOTween's website. If you need help or more infos let me know, and I'll add more explanations in the wiki.
     
  36. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Hi there,

    Just getting my head around HOTween and it seems pretty awesome!
    I was wondering, is there a way to do a sort of punch effect with HOTween? I just found that sort of thing really useful in other systems.

    Anyway, thanks for making such a cool plugin!
    Pete.
     
  37. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hi petey, glad you're liking it :)

    You could achieve a punch effect by using an Elastic easing, and eventually playing with its additional overshoot/period parameters. For example, this setting gives quite a punch:
    Code (csharp):
    1.  
    2. HOTween.To(myTransform, 1, new TweenParms()
    3.     .Prop("position", new Vector3(-2,0,0), true)
    4.     .Ease(EaseType.EaseOutElastic, 0.5f, 0.1f)
    5. );
    6.  
     
  38. petey

    petey

    Joined:
    May 20, 2009
    Posts:
    1,296
    Hey Izitmee,
    Thanks! Just trying that out but I was thinking of more a punch that ends at the same position as it starts. I't handy for a bunch of reasons but i usually use it to highlight menu elements.
    I got something similar happening with HOTween -
    Code (csharp):
    1.     TestObj.transform.position += Vector3(.2,0,0);//Counter the HOTween movement
    2.     yield WaitForFixedUpdate();//Wait
    3.     HOTween.To(TestObj.transform, 1, new TweenParms().Prop("position", new Vector3(-.2,0,0), true).Ease(EaseType.EaseOutElastic, 2f, .5f));
    There are issues with this though in that I'll have to make sure the HOTWeen is finished before I hit it with another one. It's a little bit messy, I'll see if i can come up with something better.
    Pete.
     
  39. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Oh I see! I hope I'm not getting it wrong again, but you could create and maintain it more easily with a Sequence:
    Code (csharp):
    1.  
    2. // Store original position
    3. var orPos:Vector3 = TestObj.transform.position;
    4. // Create Sequence and set autoKill to false,
    5. // so it can be reused even after it's complete
    6. myPunchSequence = new Sequence(new SequenceParms().AutoKill(false));
    7. // Add tween that moves to different position
    8. myPunchSequence.Append(HOTween.To(TestObj.transform, 1, new Vector3(-0.2,0,0)));
    9. // Add tween that oscillates back to original position
    10. myPunchSequence.Append(HOTween.To(TestObj.transform, 1, new TweenParms().Prop("position", orPos).Ease(EaseType.EaseOutElastic, f, 0.5)));
    11. // Play the sequence
    12. myPunchSequence.Play();
    13.  
    I can't test this right now, so I hope the code is ok :p

    Using a sequence is useful also because you can call myPunchSequence.Restart() at any time, and the punch animation will restart from the beginning.
     
  40. relayOne

    relayOne

    Joined:
    Sep 28, 2012
    Posts:
    23
    Hotween is fantastic! I'm loving the design and efficiency of the engine.

    What's the best way to access the target of a tween in a callback? I'd like to something like this, but I don't think there is a target property that I can access. If there isn't just one target to asses, then what's the best way to pass user parameters back to a callback function?

    Code (csharp):
    1.  
    2. ...
    3.             HOTween tween = HOTween.To(child, 4, new TweenParms().
    4.                 Prop("position", new PlugVector3Path(scalePath, true).ClosePath()).
    5.                 Delay(delay * i).
    6.                 Loops(1, LoopType.Restart).
    7.                 Ease(EaseType.Linear).
    8.                                 OnComplete(BirdFinished, null)
    9. ...
    10.  
    11.     void BirdFinished(TweenEvent tEvent) {
    12. -->     GameObject bird = tEvent.tween.target;
    13.     }
    14.  
     
  41. hima

    hima

    Joined:
    Oct 1, 2010
    Posts:
    183
    Assuming that by target you mean the 'child' object you pass as an argument for HOTween.To , you can do the following:

    Code (csharp):
    1.  
    2. ...
    3.             HOTween tween = HOTween.To(child, 4, new TweenParms().
    4.                 Prop("position", new PlugVector3Path(scalePath, true).ClosePath()).
    5.                 Delay(delay * i).
    6.                 Loops(1, LoopType.Restart).
    7.                 Ease(EaseType.Linear).
    8.                                 OnComplete(BirdFinished, child.gameObject)
    9. ...
    10.  
    11.     void BirdFinished(TweenEvent tEvent) {
    12. -->     GameObject bird = tEvent.parms[0] as GameObject;
    13.     }
    14.  
    You can add as many arguments you want after the first argument of OnComplete. They will be stored in 'parms' array. So for multiple targets, you can save them in an array an pass that array as an argument as well.
     
    Last edited: Oct 27, 2012
  42. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Thank relayOne :)

    Actually, you're almost right. tEvent.tween returns the tween as an IHOTweenComponent interface, so it's compatible both with Sequences and Tweeners. In your case, you just have to cast it as a Tweener, so you can access its target property:
    Code (csharp):
    1.  
    2. void BirdFinished(TweenEvent tEvent) {
    3.     // In case your target (child) was a transform, as I suppose:
    4.     // a) get the tween target
    5.     Transform target = ((Tweener)(tEvent.tween)).target;
    6.     // b) since the target was a transform, you can find the gameObject easily
    7.     GameObject bird = target.gameObject;
    8. }
    9.  
    EDIT: ehe didn't see Hima's solution: it's even nicer than mine :D
     
    Last edited: Oct 26, 2012
  43. relayOne

    relayOne

    Joined:
    Sep 28, 2012
    Posts:
    23
    Lzitmee, thank you for the explanation about the difference between the interface and the class. It's something I don't see often in Unity OO design, and I have almost no experience using.

    Hima, your idea worked terrific. That's super cool that the callback function can take arbitrary numbers of arguments! If only SendMessage() could work like that, it would save a bunch of headache in other places.
     
  44. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    @relayOne: ehe totally agree, all callbacks should be more flexible for what concerns parameters. On a tweening-unrelated note, I personally prefer not to use SendMessages ever, but instead to rely on events and a global Notificator. It's a little more verbose and complex to manage, but definitely more powerful (not to mention more efficient, both in terms of performance and of usage). I think I saw a similar framework ready-made on Unify.
     
  45. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    New HOTween Visual Editor udate: v1.1.010:

    - Added Autokill option (next to Autoplay button).

    This feature was officially requested by Jacob Pennock, as a replacement for the pasta alla carbonara I offered in exchange for his awesome SublimeText stuff. Your loss Jacob :D

    As usual, latest version is on HOTween's website, and should be on Asset Store after half a day or so.
     
  46. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Silly note: Uh oh. I just discovered that "tween" means "young girl" in American (maybe also English?) slang. Now I understand the people complaining about the name I gave to my tween engine :B Still, if you write it correctly, no strange links come out in Google (and again, HO is for Holoville, my tiny company, not for HOT) ;)
     
  47. absameen

    absameen

    Joined:
    Oct 5, 2011
    Posts:
    121
    Hi,

    Can we get custom easing support? Preferably through the use of AnimationClips. I think it's a great feature that many will appreciate.
     
  48. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Hi,

    sure, that would be cool, but I need a help about the theory, since I always ignored Animations and AnimationClips in Unity. How do you think it could be implemented?
     
  49. absameen

    absameen

    Joined:
    Oct 5, 2011
    Posts:
    121
    It's pretty simple actually:

    Code (csharp):
    1. // Create an Animation Curve that ranges from 0 to 1 (1 second long)
    2. AnimationCurve curve = new AnimationCurve();
    3. curve.AddKey(0f,0f,1f,1f);   // Keys can be set visually with EditorGUI.CurveField
    4. curve.AddKey(1f,1f,1f);
    5.  
    6. // Evaluate for a value between 0 and 1
    7. float easedValue = curve.Evaluate(.5f); // returns 0.5  because the ease is linear
    Edit:

    Ideally it would work like so:

    Code (csharp):
    1. HOTween.To(g,5f,new TweenParms().Prop("position", new Vector3(0f,0f,0f)).Ease (myAnimationCurve));
    Where we can pass an AnimationCurve, and all that is done on the other end is myAnimationCurve.Evaluate to get the eased values.
     
    Last edited: Nov 4, 2012
  50. Izitmee

    Izitmee

    Joined:
    Jan 27, 2011
    Posts:
    3,228
    Wow looks simple and awesome! Will definitely implement it in the next days: great addition :)
     
unityunity