Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Prime31 GoKit Tween Library Live

Discussion in 'iOS and tvOS' started by prime31, Apr 26, 2012.

  1. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, are you using an uptodate version? The demo scene has used the actual path asset created in the visually editor for the last bunch of releases.
     
  2. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I just downloaded today.
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, as you can see from the source the demo scene uses the demoRoute.asset file that is included and located in the StreamingAssets folder.
     
  4. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    right. I was thinking this would be a plug and play thing, not requiring any coding.


    edit. How do I apply "demoRoute" to any old dummyPath? That is where I am stuck.
     
  5. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, you have to tell it which object to tween and when to actually do the tweening...not much way around that.
     
  6. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    right,
    so here is how it works. (forgive me for figuring this out but this helps.)


    create empty game object.
    attach dumyyPathScript ( i like the visual editor)
    create path.
    save path.
    *now this is where I am confused, as even if I am not using the path (not called in script for XObject to use) I get an error.

    Are you suggesting by its very existence, it must be used in some form, referenced to by some script?
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, following your exact steps I get no error.
     
  8. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    ok,
    weird.
    Will try again.
    Going on what you know. Would you suggest a probable solution?
    Regardless, will try it again.
    Cheers.
     
  9. Game Bakery

    Game Bakery

    Joined:
    Apr 17, 2012
    Posts:
    7
    hey there,

    wanted to try this out and stumpled uppon weirdo problems, when i open your project from github it all works fine, but the whole code hinting extensions in mono dont seem to work. well mono even highlights some syntax stuff but it the scripts compile without errors.. so what am i missing? im feeling a little stupid right now :)
     
  10. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @Bakery, do you have a screenshot showing what you are seeing? Code completion works fine on my end.
     
  11. Game Bakery

    Game Bakery

    Joined:
    Apr 17, 2012
    Posts:
    7
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bakery, that is quite odd indeed. Have you tried the Unity sync Monodevelop menu to refresh your Monodevelop project?
     
  13. Game Bakery

    Game Bakery

    Joined:
    Apr 17, 2012
    Posts:
    7
    well yes, i start mono develop this way. but i'll try again..

    installed GoKit at work, and here everything works as it should. So .. mhh ill try reinstalling unity ..
     
  14. Game Bakery

    Game Bakery

    Joined:
    Apr 17, 2012
    Posts:
    7
    ok found the problem, had nothing to do with your stuff - i somehow still used mono 2.4.2 instead of 2.8.2 - i dont know how i managed to do that ..
     
  15. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @bakery, that makes complete sense. The old version of Monodevelop didnt have support for default parameters. I should have remembered that because it used to drive me nuts.
     
  16. Game Bakery

    Game Bakery

    Joined:
    Apr 17, 2012
    Posts:
    7
    yeah that was what made me thinking too ;)
     
  17. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    I've found the "EaseType" enum, but done know how to implement it on a single GoKit tween.
     
    Last edited: May 27, 2012
  18. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhx, the TweenConfig class has a setEaseType method for setting the easing equation.

    Go.to( cube, 2f, new TweenConfig().position( new Vector3( 25, 23, 2 ) ).setEaseType( YourEaseTyoeHere ) );
     
  19. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    Hi Prime, just wanted to thank you for making this available. Very kind of you, especially as it's free!

    One quick question, is it possible to specify a speed for the tween instead of a duration?
     
  20. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matt, it isn't possible yet (as we havent needed it) but the duration can be determined if you know the speed you want to travel and the distance: distance = velocity * time => time = distance / velocity
     
  21. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    I was thinking about moving an object along a curved path and I'm not sure how to calculate the distance along the curve.
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @matt, the GoSpline solver classes do a distance calculation when initialized. You should be able to subclass and grab the distance from them directly
     
  23. Toad

    Toad

    Joined:
    Aug 14, 2010
    Posts:
    298
    OK cool, thanks. I'll have a go at doing that.
     
  24. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    @Prime31, thank you very much for your help. I know you're busy, and appreciate you offering support for GoKit as it develops :)

    I tried the line below:

    Go.to (MY_TRANSFORM, 2f, new TweenConfig ().position (new Vector3 (25, 23, 2)).setEaseType (EaseType.easeOutCubic));

    however I get the following error in the console:
    error CS1502: The best overloaded method match for `TweenConfig.setEaseType(EaseType)' has some invalid arguments
    error CS1503: Argument `#1' cannot convert `EaseType' expression to type `EaseType'

    any help you can offer me to find my way around this error is much appreciated, if you have the available time :). thanks again


    EDIT: I also tried Go.to (MY_TRANSFORM, 2f, new TweenConfig ().position (new Vector3 (25, 23, 2)).setEaseType (Quadratic.EaseOut));
    it didnt work either. Do I have to pass it a game object, or can I pass it a transform, as I'd prefer to do?
     
    Last edited: May 28, 2012
  25. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhx, you aren't passing legit ease types. If you are using Monodevelop when you type "EaseType." the autocomplete window should show all the different valid types. You can also view the EaseType enum source for all the available types.
     
  26. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    @Prime31, thanks for the reply.

    perhaps I have a conflicting easeType class, hmm. Would you mind listing some valid easeTypes I could pass in, this is odd.


    Go.to (MY_TRANSFORM, 2f, new TweenConfig ().position (new Vector3 (25, 23, 2)).setEaseType (EaseType.easeOutCubic));

    how would you fix/rewrite the line above to make it valid, using a Cubic ease out?
     
    Last edited: May 28, 2012
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  28. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    this is odd, when I use the ease type you listed I get the following error:

    error CS0117: `EaseType' does not contain a definition for `CubicOut'
    i'm pulling form the newest git updates too.
    would having iTween in the assets folder cause this issue?
     
    Last edited: May 28, 2012
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhx, I am not familiar with iTween so I can't say. It is quite possible it has an EaseType enum as well but technically the compiler shouldn't even allow them in the same project.
     
  30. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    @Prime31
    I found the culprit, it was a CS script titled "iTweenExtensions.cs"
    I moved it out of the assets folder, and now monodevelop is finding the proper ease types, unity isnt throwing errors in the console for ease types now.
     
  31. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    has anyone gotten float value tweening to function with GoKit? I've tried a few methods, one of which is below, and I think the "this" is tripping it up, but havent found the issue yet. Any help is appreciated.

    Go.to (this, 4.0f, new TweenConfig ().floatProp("SpriteMaterialOpacityFloat", 1.0f, false));
     
  32. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhx, what you are actually tweeting with that setup is this SpriteMaterialOpacityFloat which I don't think is what you really want. Use the built in material tweens.
     
  33. 3Duaun

    3Duaun

    Joined:
    Dec 29, 2009
    Posts:
    600
    I'm attempting to tween the 4th (alpha) float value of a material. Thank you again for all your support ! I've purchased multiple P31 tools, and will continue to do so, your support, and your tools are top notch!

    I basically want to fade the final 4th float value of a COLOR for a material, from 0.0f, to 1.0f.

    looks like the shader I'm using doesnt have the _Color property. Can you suggest a way I can use the materialColor GoKit method with a shader that looks like the following:

    Code (csharp):
    1. Shader "Sprite_VertColor_Optimized" {
    2. Properties {
    3.     _MainTex ("Particle Texture", 2D) = "white" {}
    4. }
    5.  
    6. Category {
    7.     Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
    8.     Blend SrcAlpha OneMinusSrcAlpha
    9.     Cull Off Lighting Off ZWrite Off Fog { Color (0,0,0,0) }
    10.    
    11.     BindChannels {
    12.         Bind "Color", color
    13.         Bind "Vertex", vertex
    14.         Bind "TexCoord", texcoord
    15.     }
    16.    
    17.     SubShader {
    18.         Pass {
    19.             SetTexture [_MainTex] {
    20.                 combine texture * primary
    21.             }
    22.         }
    23.     }
    24. }
    EDIT: also, can I reuse a tween, or does every tween have to be garbage collected after it is performed? (trying to keep the GC down on mobile).
     
    Last edited: May 28, 2012
  34. pneill

    pneill

    Joined:
    Jan 21, 2007
    Posts:
    207
    Is it possible to determine when a tween is complete and do you have an example of how? I saw on the GitHub site a mention of handlers, but have little success implementing one.

    Thanks!
     
  35. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @zhx, Tweens can be reused and so can TweenConfigs. You can tween a color (or just the alpha component) with the MaterialColorTweenProperty. Examples:

    Code (csharp):
    1. someMaterial.colorTo( 2.0f, theColor );
    2. Go.to( someMaterial, 4.0f, new TweenConfig().materialColor( someColor ) );

    @pneill, there are of course completion handlers for tweens and different ways to add them. Some options are:

    Code (csharp):
    1. // with a method in the current class
    2. Go.to( cube, 4, new TweenConfig()
    3.         .position( new Vector3( 9, 4, 0 ) )
    4.         .onComplete( theCompletionHandlerMethod ) );
    5.  
    6. // with an anonymous Action
    7. Go.to( cube, 4, new TweenConfig()
    8.         .position( new Vector3( 9, 4, 0 ) )
    9.         .onComplete( theTween =>
    10.         {
    11.             Debug.Log( "tween done" );
    12.         }));
    13.  
    14. // adding the handler separately
    15. var theTween = someTransform.scaleTo( 4.0f, 90.0f );
    16. theTween.setOnCompleteHandler( theCompletionHandlerMethod );
    17.  
     
  36. pneill

    pneill

    Joined:
    Jan 21, 2007
    Posts:
    207
    Awesome! Thank you so much for the quick response!!
     
  37. pneill

    pneill

    Joined:
    Jan 21, 2007
    Posts:
    207
    Is there any way to make sure the transform for the tween always points at a target object? I tried including an end rotation in the tweenconfig rotation method, but didn't have much success there.
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pneill, I am assuming you are referring to a path tween. If so, the PositionPathTweenPropertys constructor has a LookAtType parameter and a look target that will orientate the tweening Transform towards the look target.
     
  39. defjr

    defjr

    Joined:
    Apr 27, 2009
    Posts:
    436
    Impressive work as usual, Mike.
     
  40. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hi prime
    could u give a simple exemple of the look at target, is it possible to use it without the position path property?
     
  41. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @toto, look at target is only valid for path tweens.

    Code (csharp):
    1. // two node path setup manually
    2. var vectors = new Vector3[] { new Vector3( 0, 1, 1 ), new Vector3( 4, 5, 6 ) };
    3. var path = new GoSpline( vectors );
    4. Go.to( cube, 4, new TweenConfig().positionPath( path, false, false, LookAtType.TargetTransform, someTarget ) );
     
  42. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    thanks for the answer prime31, so i guess i would have to use the lookat from unity and call it every update, hopefully performance wise shouldn t be too big, is there a way to tween on everyupdate without using the update function, like making an object following the player constently?
    sorry if it s a noob question, but i m new to unity.

    cheers
     
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @toto, there are lots of ways to do that. If the object will always be in the same location relative to the player parenting would work. Otherwise updating position each update is probably easiest.
     
  44. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    thanks for the quick reply, i try to understand the callback with this exemple
    Go.to( cube, 4, new TweenConfig()

    .position( new Vector3( 9, 4, 0 ) )

    .onComplete( theCompletionHandlerMethod ) );

    but failed to call a function from the oncomplete method.
    how could i achieve this?

    Go.to( cube, 4, new TweenConfig()

    .position( new Vector3( 9, 4, 0 ) )

    .onComplete( doSomething(5)) );

    void doSomething (myInt)

    thanks
     
  45. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @toto, you can just pass in a completion handler with the proper method signature. See the docs or the TweenChainGUI class for examples.
     
  46. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    When we think about tweening position we think about changing it by a certain value every frame. Long story short, is there a way to integrate GoKit with physically based characters provided I already have functions to make them move by "unit" steps (I use them to ask the AI to move characters)?
     
  47. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @panajev, sure. You would just use position Tweens to move from one location to the next or a path if there are multiple waypoints.
     
  48. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hi prime
    i was wondering if it s possible to scroll a texture with gokit, i try this with no success

    Go.to( myplane.renderer.material.SetTextureOffset, 10f, new TweenConfig().vector2Prop( "_MainTex", new Vector2( 30, 50 ) ) );

    cheers
     
  49. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @toto, I havent actually tried but the following *should* work:

    Code (csharp):
    1. Go.to( someMaterial, 10f, new TweenConfig().vector2Prop( "mainTextureOffset", new Vector2( 30, 50 ) ) );
     
  50. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    wow, just test it and it simply works :)

    thanks mister prime!