HOTween: a fast and powerful Unity tween engine

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

  1. ShreddinPB

    ShreddinPB

    New Member

    Joined:
    Aug 18, 2011
    Messages:
    79
    Damn! Im sorry to hear the trip sucked, but cool that the final result is good ;)

    Yeah. I got it to work, there was a little bump in the road tho.
    In my head, setting up the sequence was just setting it up, and not playing it.. so since it automatically plays I was a bit confused. I just added a Pause() after all the Append()s and then just called Play() when I needed it to play.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using Holoville.HOTween;
    4. using Holoville.HOTween.Plugins;
    5.  
    6. public class sequencedCountdown : MonoBehaviour {
    7.    
    8.     public GameObject numbersParent;
    9.     public GameObject numOne;
    10.     public GameObject numTwo;
    11.     public GameObject numThree;
    12.    
    13.     int countDownScaleTo = 1;
    14.     public static int countDownYonScreen = 200;
    15.     public static int countDownYoffScreen = -38;
    16.    
    17.     public static Sequence theCountDown;
    18.    
    19.     void Start()
    20.     {
    21.         theCountDown = new Sequence(new SequenceParms().OnComplete(countDownDoneLocal));
    22.         theCountDown.Append(HOTween.To(numbersParent.transform, 0.01f, "position", new Vector3(16,countDownYonScreen,-92)));
    23.         theCountDown.Append(HOTween.To(numThree.transform, 0.99f, "localScale", Vector3.one));
    24.         theCountDown.Append(HOTween.To(numThree.transform, 0.01f, "localScale", Vector3.zero));
    25.         theCountDown.Append(HOTween.To(numTwo.transform, 0.99f, "localScale", Vector3.one));
    26.         theCountDown.Append(HOTween.To(numTwo.transform, 0.01f, "localScale", Vector3.zero));
    27.         theCountDown.Append(HOTween.To(numOne.transform, 0.99f, "localScale", Vector3.one));
    28.         theCountDown.Append(HOTween.To(numOne.transform, 0.01f, "localScale", Vector3.zero));
    29.         theCountDown.Append(HOTween.To(numbersParent.transform, 0.01f, "position", new Vector3(16,countDownYoffScreen,-92)));
    30.         theCountDown.Pause();
    31.     }
    32.    
    33.     public static void Play()
    34.     {
    35.         theCountDown.Play();
    36.     }
    37.    
    38.     public static void countDownDoneLocal()
    39.     {  
    40.         levelAimer.okToShoot = true;
    41.         doMoveDown.startLevelTimer = true;
    42.     }
    43.    
    44. }
  2. ShreddinPB

    ShreddinPB

    New Member

    Joined:
    Aug 18, 2011
    Messages:
    79
    I do have another question if you have a minute.

    In my game, the objects you are going to lob are lined up on a path. Lob your object and the others on the que path will shift forward like they are stacked up on the path.

    I searched around and am having trouble figuring this out :(
    I am having a hard time figuring any of it out hahahaha

    How do I create a path?
    How do I animate along that path, but just to a certain point along the path, like move from 50% of the way to 60% of the way?

    As much as it seems I am asking you to just write it, I really am not lol just with no working example that I can find of how the path animation system works, I cant pick it apart and figure it out :(
  3. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    To create a path, you just store an Array of Vector3 points, and then use PlugVector3Path to animate it. I just created an example (Path Basics) on HOTween's website, so you can download it and see how it works :)

    When you animate on a path, the tween moves along the whole path (though what you're asking is quite interesting, I will see if I can add a "partial tween" option in the near future). But you can "jump" to a position in time using GoTo or GoToAndPlay, and then use the OnUpdate callback to do something when it goes beyond a certain time position:
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using Holoville.HOTween;
    4. using Holoville.HOTween.Plugins;
    5.  
    6. /// <summary>
    7. /// Attach this class to an empty gameObject in the scene.
    8. /// </summary>
    9. public class Sample : MonoBehaviour
    10. {
    11.     public      Transform           myTransform; // Attach a transform here via inspector.
    12.     public      Vector3[]           myPath = new Vector3[4] { new Vector3(0,0,0), new Vector3(5,0,0), new Vector3(5,5,0), new Vector3(-10,5,0) };
    13.    
    14.     private     IHOTweenComponent   tweener;
    15.    
    16.    
    17.     void Start()
    18.     {
    19.         tweener = HOTween.To( myTransform, 2, new TweenParms().Prop( "position", new PlugVector3Path( myPath ) ).OnUpdate( PathUpdate ) );
    20.         // Jump to 50% time position (1).
    21.         // GoTo moves to the given position and doesn't change the play mode
    22.         // (meaning the tween will goto and play if it was playing, or goto and pause if it was paused).
    23.         tweener.GoTo( 1 );
    24.        
    25.         // I add this to show the path in the Editor (if the Gizmos button is selected).
    26.         HOTween.showPathGizmos = true;
    27.     }
    28.     void PathUpdate()
    29.     {
    30.         if ( tweener.position >= 1.2f ) {
    31.             // If the time position is higher than 60% (1.2) of the duration,
    32.             // move back to 50% duration and go on playing.
    33.             // This will create an infinite loop between 50% and 60% time position.
    34.             tweener.GoTo( 1 );
    35.         }
    36.     }
    37. }
    38.  
    Note that in the above code I stored the tweener as an IHOTweenComponent instead than as a Tweener: IHOTweenComponent is an interface which you can use both for Tweeners than for Sequences, thus controlling them (with GoTo and other methods) in the same way.

    P.S. what you said about Sequence sounds totally right... Tomorrow I will probably change its behaviour so that it doesn't start automatically anymore :)
  4. ShreddinPB

    ShreddinPB

    New Member

    Joined:
    Aug 18, 2011
    Messages:
    79
    That totally rocks! I can work with that.. I just tested and can use Pause() on it also.. so I can set it to pause when it gets to a certain point, then play again when I need it to move :D

    But yeah, being able to just set a distance along the curve to move to would be great.. possibly to the parametric length 0.5 half way, something like that ;)

    Cool, glad I can contribute some ideas ;)

    as a note, when I go to the link for your examples http://www.holoville.com/hotween/examples.html it just says "Coming Soon!"
  5. Thom Denick

    Thom Denick

    Member

    Joined:
    Jul 12, 2010
    Messages:
    31
    Hi Izitmee,

    Just wanted to let you know I'm using HOTween in my new project, and it's really fantastic. It's a bit challenging to figure out how to manually execute some of the stuff iTween does automatically with all it's methods, but it's worth it because you have way more control over your code, and there are no Hashes!

    I wish there was some way around having to use a string in Prop, but it's easy enough to just pop the hints up for whatever script you are trying to tween.

    Keep up the great work!
  6. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Ooops, sorry, that's a cache issue. If you press refresh on your browser the example should magically appear :)

    @Smorpheus: thanks a lot for letting me know, I'm very glad you're liking it :) I tried all possible hacks not to use a string to define the property to tween, but that was truly impossible (unless, maybe, I'd decide to go with "unsafe" code, but that's a thing I definitely want to avoid).

    P.S. 8-bit RPG hooked me! Just seeing those characters made me hunger for it :D
  7. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Just a quick update (v0.8.007), which I thought I'd mention because of some changes:

    The ConstantSpeed parameter I introduced yesterday for paths doesn't exist anymore. This doesn't mean that it doesn't work anymore, but simply that it's now used by default (I realized that there's no use in moving along a curved path without constant speed, thus the parameter was futile).

    As rightfully suggested by ShreddinPB, Sequences are now created in a paused state, and you will need to call mySequence.Play() to start them.

    As usual, you can get it all on HOTween's website.
  8. ShreddinPB

    ShreddinPB

    New Member

    Joined:
    Aug 18, 2011
    Messages:
    79
    Hey man, not sure if I am doing something wrong, or if its a bug.
    I downloaded the newest update and copied it over.

    When I use the path, a fresh setup or even running the script you posted, there seems to be an extra Vector3 in there.
    So in your example you have a vector3 array of 4.. in the editor the path has 5 points
    my one I made has 10, but when it plays there is an 11th point that isnt along the path at all.. it seems to be at 0,0,0
  9. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Hey, just tried to replicate the issue, even using the script I posted, but I can find no additional points.

    Consider that, if the target position doesn't coincide with the first path point, HOTween automatically adds a curve leading from the target's position to the beginning of the path. Maybe that is what you're seeing?
  10. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    Since I need an alert box, so I decided to quickly code an alert box with HOTween. Hopefully this can be useful, as well as showing how HOTween can be used easily with UnityGUI.

    Alert Box with HOTween
  11. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    @himatako: Wow, that Alert Box is a thing of beauty. I downloaded and tried it out, and I'll probably use it in the future - thanks for sharing (also, your blog looks way interesting: you got a new follower) :)

    Also, I just uploaded HOTween v0.8.011, with the enhancements you asked for (there's also a demo in the Test Run - just refresh the page if you don't see it :p). Now, even while playing, you can change timeScale, loops, loopType, and easeType (this last one is available only from Tweeners, while the others both from Tweeners than from Sequences, or via the IHOTweenComponent interface), like:
    Code (csharp):
    1.  
    2. myTweener.timeScale = 2;
    3. // etc.
    4.  
    Next features will be one of these: changing Props while playing (not sure if it can be done efficiently), a plugin for the tweening of Rects, an option to tween only through "parts" of the whole tween.
    Last edited: Jan 29, 2012
  12. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    I would like to port the code using iTween to HOTween, but there is problem to increment the text string number (e.g. from "100" to "200" in 0.25 sec)

    The following code is using iTween:
    void OnScoreUpdate(){
    iTween.ValueTo( this.gameObject, iTween.Hash("from", 100 ,"to", 200 ,"time",0.25f,"onupdate","UpdateScoreText") );
    }
    void UpdateScoreText(int newValue){
    scoreLabel.text = string.Format("{0:N0}", newValue);
    }
  13. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    I assume that scoreLabel is a reference to a GUIText component, thus you could simply do like this:
    Code (csharp):
    1.  
    2. // Store the int score, so you can animate its value.
    3. // If you have it stored somewhere else,
    4. // you can apply HOTween to that stored score
    5. // (remember that HOTween doesn't need its target to be a GameObject)
    6. public int score = 100;
    7.  
    8. void OnScoreUpdate()
    9. {
    10.   // Animate the score value, using an update callback to set scoreLabel's text.
    11.   // Since score is an int, it will be automatically animated using integers only.
    12.   HOTween.To( this, 0.25f, new TweenParms().Prop( "score", 200 ).OnUpdate( OnScoreUpdateCallback ) );
    13. }
    14.  
    15. void OnScoreUpdateCallback()
    16. {
    17.   scoreLabel.text = score.ToString();
    18. }
    19.  
  14. Dgizusse

    Dgizusse

    Member

    Joined:
    Feb 1, 2012
    Messages:
    30
    I have some questions regarding future features:

    1 - Will you integrate a visual Path editor?
    2 - Will you add some kind of Punch/Shake functionality.
    3 - Right now it's impossible to use the visual editor for prefabs. Is there a plan to allow visual editing per object rather than with the Manager?
    4 - I'm wondering why you destroy the HOTween.tweenGOInstance as soon as there's no tweens left to process? I'm guessing there's an overhead to recreate/destroy that GameObject.

    Do you have a roadmap available somewhere so we can track what you plan to integrate? (Is it the issues in GoogleCode?)

    Converting from iTween was really easy and painless for most of my project.
    Very nice job!

    Thanks a lot!
  15. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Thanks to you Dgizusse :)

    1 - Yes, but after I'll be done with the other enhancements I've planned. I might start working on that by the end of next week.
    2 - Now that you mention it, I might add a Punch/Shake option. I will think about how to introduce it in the best possible way.
    3 - This is a complex one, I never thought about animating prefabs. I will think about it, but as of now I'd say no: for that you have to use HOTween via script.
    4 - Since the tweenGOInstance is a single and very light GameObject (almost all its methods are static), the overhead for creating/destroying it is practically null, thus I prefer to keep the scene clean and remove it when it's not needed.

    Also, yup, the roadmap is given by the "enhancements" issues in Google Code.
  16. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    I would like to clarify that OnScoreUpdate(int oldValue, int newValue) that is passed with oldValue = 100, newValue = 200.
  17. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    HOTween use the current value of the tweening property as the old value; thus, there is no need for you to specify the old value like in iTween.

    I second Punch and Shake options as well. Also, I was wondering if you've planned on HOTween.From? :D
  18. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    The actual result is the text value is incremented with string format within a time period

    Initially, scoreLabel.text = "0"

    First Call: HOTween.To( scoreLabel, 1, new TweenParms().Prop( "text" , 100 ) ); //The end value set for "XXXX.text" tween is invalid. The tween for this property will not be created.

    time = 0s, label = "0"
    time = 0.1s, label = "1"
    time = 0.2s, label = "2"
    ....
    time = 1s, label = "100"

    Second Call: HOTween.To( scoreLabel, 1, new TweenParms().Prop( "text" , 200 ) );
    time = 0s, , label = "100"
    time = 0.1s , label = "101"
    time = 0.2s , label = "102"
    ...
    time = 1s , label = "200"
  19. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    Or , how to write my custom ABSTweenPlugin, can you give some simple example how to do my own?
  20. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    Doesn't the code that Izitmee provided for you already do what you want?
    Code (csharp):
    1.  
    2. public int score = 100;
    3.  
    This is where you set your current score. If it start from zero, then it should be score = 0

    Code (csharp):
    1.  
    2. void OnScoreUpdate()
    3. {
    4.  
    5.   // Animate the score value, using an update callback to set scoreLabel's text.
    6.  
    7.   // Since score is an int, it will be automatically animated using integers only.
    8.  
    9.   HOTween.To( this, 0.25f, new TweenParms().Prop( "score", 200 ).OnUpdate( OnScoreUpdateCallback ) );
    10.  
    11. }
    12.  
    Here you animate the integer. With this, HOTween will tween the integer from whatever it was to 200 with in 0.25f seconds.
    The "OnUpdate( OnScoreUpdateCallback )" part means that everytime the tween has updated the score integer, it will call a method named "OnScoreUpdateCallback", which we will take a look next.

    Code (csharp):
    1.  
    2. void OnScoreUpdateCallback()
    3. {
    4.  
    5.   scoreLabel.text = score.ToString();
    6.  
    7. }
    8.  
    Once this method is called, it set the text in the label to represent the score integer. Since this is called everytime the tween update the score integer, so scoreLabel will show the increasing score.

    Once 0.25 seconds have passed, score integer will become 200. If you want to modify the method to set your own target instead of a fixed 200, you could do

    Code (csharp):
    1.  
    2. private Tweener _tweener;
    3. void OnScoreUpdate(int target)
    4. {
    5.   // Keep the reference of the tweener to make sure that there's always one tweener working on the score integer
    6.    if( _tweener != null  !_tweener.isComplete ) _tweener.Kill();
    7.    _tweener =  HOTween.To( this, 0.25f, new TweenParms().Prop( "score", target).OnUpdate( OnScoreUpdateCallback ) );
    8.  
    9. }
    10.  
    Don't tween the text in the label directly. That will give you a type-writer effect, not incrementing from 101 - 200 that you want. Since it doesn't understand that it's an integer value and look at it as a string, it would replace 100 with 200, slowly letter by letter.
    Last edited: Feb 2, 2012
  21. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    @himatako, actually, it works but I prefer directly tween the text because it is more elegant. I would be more flexible if we can write our own ABSTweenPlugin.
  22. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    @yuewah: about creating your own ABSTweenPlugin, it's a thing I will explain in detail in the future, since I see it as an interesting feature. Though as of now, I prefer not to deal with it because I might change something while creating additional plugins, and thus a user-created plugin might not work with future versions of HOTween.

    Anyway, to give you a general idea: you have to extend ABSTweenPlugin (found in Holoville.HOTween.Plugins.Core), and implement its abstract methods. You can check for example PlugColor and its code comments to see how it's done. Mainly, you have to implement one (or more) constructor, the SetChangeVal and DoUpdate methods (plus the GetSpeedBasedDuration one if you need the "tween by speed" option to work), and the typedStartVal, typedEndVal and changeVal fields/properties. "validPropTypes" is used to store valid properties for this plugin, and "validValueTypes" the valid "endValue" types.
    Though as I said, as of now I'd suggest you go with the less "elegant" way :)

    @himatako: thanks for the clarifications :) And about HOTween.From, you will have to convince me :D I never understood the real usefulness of it: can you lure me in with some example (or with why you need it)?
  23. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    @himatako: hey, I don't need any more convincing (ah! I was quick! :D). I just realized I might need a From in a short game I'm making, so I'll implement it, maybe immediately :)
  24. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    @yuewah
    Ah, I see what you mean. Yes, having to write another function is not pretty elegant.

    @Izitmee
    lol But I haven't even said anything! :p

    Out of curiosity, I wonder if HOTween only work with public variable? What about private or protected with a public getter/setter?
  25. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Lol, I could read your thoughts :D

    About the variables, HOTween can animate only public variables or getters/setters, but this means that if you have a public getter/setter for a private variable, you can definitely animate the getter/setter.
  26. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    Awesome! Thanks :D
  27. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    does HOTween possible to animate an object property From value1 to value2 ?
  28. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    I'm implementing HOTween.From right now. Will be ready within the weekend or for the start of the next week.
  29. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    I just tried tweening a private string with public getter/setter, and this error occured.
    Code (csharp):
    1.  
    2. NullReferenceException: Object reference not set to an instance of an object
    3. Holoville.HOTween.Plugins.PlugString.set_startVal (System.Object value)
    4. Holoville.HOTween.Plugins.Core.ABSTweenPlugin.Init (Holoville.HOTween.Tweener p_tweenObj, System.String p_propertyName, EaseType p_easeType, System.Type p_targetType, System.Reflection.PropertyInfo p_propertyInfo, System.Reflection.FieldInfo p_fieldInfo)
    5. Holoville.HOTween.TweenParms.InitializeObject (Holoville.HOTween.Tweener p_tweenObj, System.Object p_target)
    6. Holoville.HOTween.Tweener..ctor (System.Object p_target, Single p_duration, Holoville.HOTween.TweenParms p_parms)
    7. Holoville.HOTween.HOTween.To (System.Object p_target, Single p_duration, Holoville.HOTween.TweenParms p_parms)
    8.  
    Do you know what could be causing it?
  30. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Uhm, I tween getters/setters all the time without issues (even the first example in HOTween's Test Run shows a getter/setter being tweened).

    From the error you posted I'm not sure... could you write me both the code of the getter/setter and of the private variable you're tweening, than the code you're using for HOTween.To? This way, I could either see if something's wrong in there, or replicate the issue and fix it (and also make HOTween dispatch a more clear message if this error happens).
  31. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    No problem. Here's the code for the getter/setter
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System.Collections.Generic;
    5.  
    6. /// <summary>
    7. /// A group of TextMesh where one TextMesh act as a main text,
    8. /// while the others act as the text border
    9. /// </summary>
    10. public class UVNTextMeshWithBorder : MonoBehaviour
    11. {
    12.     public string startText;
    13.     public float startSize = 12;
    14.     private string _text;
    15.     private float _size;
    16.    
    17.     public TextMesh mainTextMesh;
    18.     public List<TextMesh> borderTextMeshes;
    19.     public Color mainTextColor = Color.white;
    20.     public Color borderTextColor = Color.black;
    21.    
    22.     public void Awake()
    23.     {
    24.         UpdateText();
    25.     }
    26.    
    27.     /// <summary>
    28.     /// Getter/Setter for the text to be rendered on the screen
    29.     /// Basically just apply the text to all the TextMesh instances
    30.     /// </summary>
    31.     public string Text
    32.     {
    33.         get{ return _text; }
    34.         set
    35.         {
    36.             _text = value;
    37.             mainTextMesh.text = _text;
    38.             foreach( TextMesh textMesh in borderTextMeshes )
    39.             {
    40.                 textMesh.text = _text;
    41.             }
    42.         }
    43.     }
    44.  
    45.     /// <summary>
    46.     /// Getter/Setter for the character size of our textmesh
    47.     /// </summary> 
    48.     public float Size
    49.     {
    50.         get { return _size; }
    51.         set
    52.         {
    53.             _size = value;
    54.             mainTextMesh.characterSize = _size;
    55.             foreach( TextMesh textMesh in borderTextMeshes )
    56.             {
    57.                 textMesh.characterSize = _size;
    58.             }
    59.         }
    60.     }
    61.    
    62.     /// <summary>
    63.     /// UNFINISHED
    64.     /// Update the color of the textMesh and the border
    65.     /// </summary> 
    66.     public void UpdateText()
    67.     {
    68.         mainTextMesh.renderer.material.color = mainTextColor;
    69.         foreach( TextMesh textMesh in borderTextMeshes )
    70.         {
    71.             textMesh.renderer.material.color = borderTextColor;
    72.         }
    73.     }
    74. }
    75.  
    And this is the class where it calls the tween
    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. using System.Collections;
    5.  
    6. using Holoville.HOTween;
    7.  
    8. using Holoville.HOTween.Plugins;
    9.  
    10.  
    11.  
    12. /// <summary>
    13.  
    14. /// The main message box of our visual novel.
    15.  
    16. /// </summary>
    17.  
    18. public class UVNMessageBox : MonoBehaviour
    19.  
    20. {
    21.  
    22.     public FreeSpriteBase textBackground;
    23.  
    24.     public FreeSpriteBase nameBackground;
    25.  
    26.     public UVNTextMeshWithBorder nameMesh;
    27.  
    28.     public UVNTextMeshWithBorder textMesh;
    29.  
    30.     public int width;
    31.  
    32.    
    33.  
    34.     private string _text;
    35.  
    36.     private string _name;
    37.  
    38.     private Tweener _textTweener;
    39.  
    40.    
    41.  
    42.     /// <summary>
    43.  
    44.     /// Getter/Setter for the body text of the message box
    45.  
    46.     /// Will tween the text in the UNVTextMeshWithBorder for
    47.  
    48.     /// type-writer effect
    49.  
    50.     /// </summary>
    51.  
    52.     public string Text
    53.  
    54.     {
    55.  
    56.         get{ return _text; }
    57.  
    58.         set
    59.  
    60.         {
    61.  
    62.             // Apply word wrap to the input string
    63.  
    64.             _text = UVNStringUtility.WordWrap(value, width);
    65.  
    66.            
    67.  
    68.             // If previous text is still whoing, force it to complete
    69.  
    70.             if( textTweener != null )
    71.  
    72.             {
    73.  
    74.                 textTweener.Complete();
    75.  
    76.                 textTweener = null;
    77.  
    78.             }
    79.  
    80.            
    81.  
    82.             // Start tweening for type-writer effect
    83.  
    84. //          Debug.Log(_text);
    85.  
    86. //          textTweener = HOTween.To(textMesh, _text.Length * 0.1f, "_text", _text);
    87.  
    88.             textTweener = HOTween.To(textMesh,
    89.  
    90.                                      _text.Length*0.1f,
    91.  
    92.                                      new TweenParms().Prop("Text", new PlugString(_text, EaseType.Linear)
    93.  
    94.                                                            )
    95.  
    96.                                      );
    97.  
    98.         }
    99.  
    100.     }
    101.  
    102.    
    103.  
    104.     /// <summary>
    105.  
    106.     /// Getter/Setter for the text represent the name of the
    107.  
    108.     /// active speaker for this message box
    109.  
    110.     /// The name window will be hidden if name is set to null or an empty string
    111.  
    112.     /// </summary>
    113.  
    114.     public string Name
    115.  
    116.     {
    117.  
    118.         get{ return _name; }
    119.  
    120.         set
    121.  
    122.         {
    123.  
    124.             _name = value;
    125.  
    126.             nameMesh.Text = _name;
    127.  
    128.             if( string.IsNullOrEmpty(_name) )
    129.  
    130.             {
    131.  
    132.                 nameBackground.Hide();
    133.  
    134.             }else
    135.  
    136.             {
    137.  
    138.                 nameBackground.Show();
    139.  
    140.             }
    141.  
    142.         }
    143.  
    144.     }
    145.  
    146.    
    147.  
    148.     public virtual void Activate()
    149.  
    150.     {
    151.  
    152.     }
    153.  
    154.    
    155.  
    156.     public virtual void Deactivate()
    157.  
    158.     {
    159.  
    160.     }
    161.  
    162. }
    163.  
    I tried changing the property name from "Text" to "_text" and make my variable public, and it gave me no error. :(
  32. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Whew, copying/pasting from this forum creates a very messy code :D

    Anyway, I checked it out, and I think the reason you're getting an error is because something's wrong inside the UVNTextMeshWithBorder's Text setter (and that's why using the variable directly works). Within UVNMessageBox's Text setter, instead than using HOTween, try to simply set your UVNTextMeshWithBorder Text, and then reading it with Debug.Log (myUVNTextMeshWithBorder.Text): it should return an error, possibly because some reference is missing?
    Code (csharp):
    1.  
    2. // Inside UVNMessageBox.Text setter, instead than HOTween.To...
    3. textMesh.Text = "HELLO";
    4. Debug.Log( " > " + textMesh.Text );
    5.  
    Let me know :)
  33. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    I tried it and the UVNTextMeshWithBorder works just fine though :S Debug.Log also returns a correct value as well.

    Code (csharp):
    1.  
    2. public string Text
    3.     {
    4.         get{ return _text; }
    5.         set
    6.         { _text = value; }
    7.     }
    8.  
    I've tried reducing the code in UVNTextMeshWithBorder to just simple getter/setter, and the same error's still there. So maybe it's somewhere else?
    Last edited: Feb 3, 2012
  34. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Uhm... then I must be having some issues in recreating a working environment for your classes. Could you send me a UnityPackage with a working stripped version of your scene? So I can just import it and check everything in the correct conditions (and with the correct errors :p).
  35. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    Ok, here it is! I hope it's fat-free enough :) Thank you for taking your time doing this.
    View attachment $HOTweenBugTest.unitypackage

    You can go to UVNMessageBox, and uncomment the code in getter/setter to reproduce the bug.
  36. SteveB

    SteveB

    Member

    Joined:
    Jan 17, 2009
    Messages:
    985
    Hi again Izitmee!

    I was recently having to do some fancy mathf work to get a particular motion, saw that it was tapping into my CPU cycles quite a bit, so I figured I'd check back in with you to see how things are progressing.

    That said, have you given any further thought on run-time on the fly parameter changing? Rest assure I read through the forum after my last post to see if you had before asking (I don't want to pester you). :D

    Thanks man!


    -Steve
  37. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    @himatako: got it! :) Actually, it's because strings can be null (when reached through a getter/setter), and when you start, Text actually returns a null value, thus HOTween doesn't know where to start from. If you set your _text variable to "", everything works:
    Code (csharp):
    1.  
    2. private string _text = "";
    3.  
    In the next release (the one with HOTween.From), I will add a check to HOTween to see if a string is null, and eventually set it automatically to "".

    @SteveB: you're never pestering! :D If you mean changing endValues on the fly, I'm thinking about that, but seeing that it involves a lot of code (because I'd obviously want the tween to "readapt" smoothly), I'm doing other enhancements first. Anyway, in the last update I added the possibility to change almost all other parameters on the fly (timeScale, loops, loopType, and easeType).
    As a temporary fix to changing endValue on the fly, if you're using linear easings, consider using the new SpeedBased parameter (new TweenParms().SpeedBased()). That way, if you kill a tween and create a new one with different endValues but the same speed, the change won't be noticeable.
    Last edited: Feb 3, 2012
  38. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Aaand... HOTween.From is available, in the just uploaded v0.8.015 :)

    Also, himatako, now PlugString automatically checks if a string is null and replaces it with "", thus everything should work in your project without changing anything. Oh, and by the way, now strings are also tweened using defaults, so you don't need to write:
    Code (csharp):
    1.  
    2. ...Prop( new PlugString( "myStringVariable", "New text for my string" ) )...
    3.  
    but you can just write:
    Code (csharp):
    1.  
    2. ...Prop( "myStringVariable", "New text for my string" )...
    3.  
    or completely avoid TweenParms and go for the fast tween (if you don't need any parameter like loops, delay, etc.):
    Code (csharp):
    1.  
    2. HOTween.To( myObject, 2, "myStringVariable", "New text for my string" );
    3.  
  39. ShreddinPB

    ShreddinPB

    New Member

    Joined:
    Aug 18, 2011
    Messages:
    79
    I think I have run into a conflict between HOTween and NGUI :(
    everything is fine in my project, I import the ngui package and I get this error
    Assets/Holoville/HOTween Extensions/HOTweenManager/HOTweenManager.cs(78,17): error CS0029: Cannot implicitly convert type `Holoville.HOTween.Tweener' to `Tweener'

    and none of the NGUI menus get added to the unity interface :(:(

    edit: yup.. it has a class called "Tweener"
    Last edited: Feb 4, 2012
  40. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Ouch! Can't believe it. Due to Unity's "loose" class policy, when you create an extension you either have to use a DLL with namespaces, or name your classes with some prefix, otherwise there will be tons of conflicts. Can't believe Mr. NGUI ignored this... I'll try to write him and ask him to change it.

    In the meantime, I uploaded HOTween Editor v0.2.002, which solves this issue.
    Though, if you store a reference to HOTween tweeners via script while using NGUI, to avoid conflicts you will have to prefix them with the full namespace (Holoville.HOTween.Tweener instead than simply Tweener), sorry for that :/
  41. hima

    hima

    New Member

    Joined:
    Oct 1, 2010
    Messages:
    179
    @Izitmee
    Thank you so much! It works now ^o^ Now I can move on to do other part of the visual novel engine :)

    @ShreddinPB
    Alternatively, you can use using directive and assign some nickname to the namespace.
    Code (csharp):
    1.  
    2. using HT = Holoville.HOTween;
    3. using HTPlugins = Holoville.HOTween.Plugins;
    4.  
    5. public class SomeScript : MonoBehaviour
    6. {
    7.        private HT.Tweener  _savedTweener;
    8. }
    9.  
    So you don't have to go through the whole long name like Holoville.HOTween.Tweener

    Though instead of namespace, I think it would be nice if prefix is used. Objective-C use this approach and I'm kinda used to it and happy with that.
  42. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Great suggestion himatako :)

    Also, ArenMook, was very nice and changed the Tweener class name to NGUITweener: will be available in the next NGUI update (which looks awesome by the way - will probably buy it sooner or later) :)
  43. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Sorry for the update flood (but on a positive side: they're all new features :)), but I wanted to mention that v0.8.016 is out.

    New features are:
    • PlugRect plugin added (which is now used by default for all Rect properties), thanks to Romain Giraud.
    • Now PlugVector3Path's OrientToPath parameter has an additional "lookAhead" option, to choose the lookAhead amount.
  44. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    If I run the following code, the final result of myObject.fieldName = 50 , I expect it should be 100.

    HOTween.To(myObject, 1, new TweenParms().Prop("fieldName", 50));
    HOTween.To(myObject, 1, new TweenParms().Prop("fieldName", 100));
  45. yuewah

    yuewah

    New Member

    Joined:
    Sep 21, 2009
    Messages:
    98
    HOTween is a little bit confusing, especially the Tweener.Reverse(). I think something like PlayForward and PlayBackward is better as it looks like a video playback.
  46. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    As of now, you should always kill a Tweener before starting a new one on the same property. HOTween has an OverwriteManager, but it's not active at the time. But I will push it up in the list of priorities.

    Uhm, you might be right... I will think about adding a PlayBackwards() method that applies a Reverse() and then a Play().
  47. nsxdavid

    nsxdavid

    Member

    Joined:
    Apr 6, 2009
    Messages:
    211
    So what platforms does HOTween work on (or not work on)? It says "Now works on iPhone" which of course begs the question... what doesn't it work on? Android? Mac? Flash?
  48. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Oops, that was dumb communication on my part. Initially, it worked on all platforms except iPhone, so that's why I added the "now works on iPhone" thing.

    It actually works on all non-beta platforms. For Flash I can't guarantee: as of now, it doesn't (HOTween needs Reflection, which is not yet implemented in Flash Unity export, though the Unity guy say it might be when the final version is released).
  49. nsxdavid

    nsxdavid

    Member

    Joined:
    Apr 6, 2009
    Messages:
    211
    Cool. I can't get anything to work on Flash anyway. :)
  50. Izitmee

    Izitmee

    Member

    Joined:
    Jan 27, 2011
    Messages:
    2,345
    Just a quick update. I forgot to remove a Debug.Log from PlugVector3Path, in the last version (a "HERE/HERE" was sent to the output panel). I removed it in the new v0.8.017.

    About other HOTween's enhancements, they will be waiting for a while, because now I'm focused on another project. If you find any bugs though I will try to quickly solve them :p