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
    I just added a unitypackage for the latest version of GoKit in the downloads section on GitHub (https://github.com/prime31/GoKit/downloads). Future releases will probably be available as both a unitypackage and the full source through GitHub as well.
     
  2. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    Hello Prime31,

    I'd like to be able to call a method either after a tween call has completed successfully, after a chain of tweens has completed successfully, or as a normal action inside the tween chain.

    How should I proceed? Do you think it can be added to GoKit?
     
  3. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @panajev, all Tweens and TweenChains have a completion handler prooerty that can be set and will be called when the tween completes. You can even set it right on the TweenConfig object.
     
  4. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  5. Panajev

    Panajev

    Joined:
    Mar 26, 2012
    Posts:
    42
    I will look at the docs again, I could not find a clear description of how to call any custom function as completion delegate :(.
     
  6. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    Hey Prime31,

    I'm pretty excited about this tool, but I'm currently using a mix of web and iOS. It seems like your GoSpline.cs uses ReadAllBytes, which is something that's unsupported through web.

    Do you have any plans to add web support? In the meantime, is there a way that I can safely disable splines to still use your tweening features on web?

    Thanks for the awesome free tool either way!
     
  7. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
  8. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    My issue is that I get compile time errors when I have the build set to deploy as a web game. Specifically, the errors are:

    GoSpline.cs(83,34): error CS0117: 'System.IO.File' does not contain a definition for 'ReadAllBytes'
    GoSpline.cs(84,24): error CS1502: The best overloaded method match for 'GoSpline.bytesToVector3List(byte[])' has some invalid arguments
    GoSpline.cs(84,24): error CS1503: ARgument '#1' cannot convert 'object' expression to type 'byte[]'

    But, if I change my build settings to iOS, the compile errors do not come up. I'm looking for a way to use your code and still build to web. Any thoughts? Am I possibly installing things wrong? I just took the Plugin folder and dropped it into my project folder.

    Thanks for the quick response!
     
  9. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pickles, you can wrap the file read line with standard precompiler defines (#if UNITY_WEBPLAYER). We had to temporarily remove them for DLL builds.
     
  10. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    Awesome! Now I've got that all set for the web builds. Much appreciated!
     
  11. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi Mike, i want to alter a path tweens timeScale dynamically at any point. The way, in my title, will be via trigger. So, i beleive I must be able to access UpdateType.Update. If true, I then need to just set a var, float timeScaleTarget, and have the update, work its way towards that value.

    So my question is, if my logic is true, how do I access an update call specific to said tween?
     
  12. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, you can't access the update method of a tween unless you make your own subclass. You also do not need to access it to change the timeScale property. You can just set it anytime you want. The demo scenes have a few examples of how to do it.
     
  13. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Thanks Mike,
    I am looking at the baseGUIDemo as it seems the only one that has timeScale involved. I want to incorportate it into the TweenChain Demo.

    I have added in a float[]. the idea is to use those values and apply them against the cubes[]. So, cube[0] has timeScale set to float[0] and so on. However I am usnure if timeScale needs to be a member of the chain. Of course then I want to adjust the timeScale per cube around line 28. I am very much stuck here. Can you help me?


    Code (csharp):
    1.  
    2.  
    3. public class TweenChainGUI : BaseDemoGUI
    4. {
    5.     // we have 4 cubes setup
    6.     public Transform[] cubes;
    7.     public float[] tweenTimeScale;
    8.    
    9.     void Start()
    10.     {
    11.         // create a TweenConfig that we will use on all 4 cubes
    12.         var config = new TweenConfig()
    13.             .setEaseType( EaseType.QuadIn ) // set the ease type for the tweens
    14.             .materialColor( Color.magenta ) // tween the material color to magenta
    15.             .eulerAngles( new Vector3( 0, 360, 0 ) ) // do a 360 rotation
    16.             .position( new Vector3( 2, 8, 0 ), true ) // relative position tween so it will be start from the current location
    17.             .setIterations( 2, LoopType.PingPong ); // 2 iterations with a PingPong loop so we go out and back 
    18.        
    19.         // create the chain and set it to have 2 iterations
    20.         var chain = new TweenChain().setIterations( 2 );
    21.        
    22.         // add a completion handler for the chain
    23.         chain.setOnCompleteHandler( c => Debug.Log( "chain complete" ) );
    24.  
    25.         // create a Tween for each cube and it to the chain
    26.         foreach( var cube in cubes )
    27.         {
    28.             var tween = new Tween( cube, 0.5f, config );
    29.             chain.append( tween );
    30.             print("cube " + cube);
    31.         }
    32.        
    33.        
    34.         _tween = chain;
    35.     }
    36. }
    37.  
    38.  
     
    Last edited: Jul 5, 2012
  14. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    Just set the timeScale to whatever you want on the _tween object.
     
  15. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Thanks,
    But I am struggling with two things,
    1. by entering...
    Code (csharp):
    1.  
    2.         // create a Tween for each cube and it to the chain
    3.         foreach( var cube in cubes )
    4.         {
    5.             tweenCount++;//public float var.
    6.             print("tweenCount " + tweenCount);
    7.             var tween = new Tween( cube, 0.5f, config );
    8.             chain.append( tween );
    9.             tween.timeScale = 0.3f;///previously 0.3 was tweenCount.
    10.         }
    11.  
    I get no effect on time scale for any tween.



    2. The Tween Chain scene has a GUI control system in it, with a half dozen btns. I am wondering how this even exists since the only script in scene appears to be the TweenChainGUI Script.
     
  16. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    I altered the code to refernce chain instead of tween but that does not work either.

    Any ideas?


    Code (csharp):
    1.         // create a Tween for each cube and it to the chain
    2.         foreach( var cube in cubes )
    3.         {
    4.             tweenCount++;
    5.             var tween = new Tween( cube, 0.5f, config );
    6.             chain.timeScale = tweenTimeScale[tweenCount];
    7.             chain.append( tween );
    8.        
    9.  
     
  17. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Hi Mike,
    Any help on this? As I say, I think GoKit has the potential to be a huge time saver for me, but the lack of quality documentation hurts that progress. Please if you can address my question, I am sure it is something you could answer in less than a minute. Meanwhile I have spent a week trying to figure out this system.
     
  18. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    I seem to be having some trouble editing a custom property. Does this code look wrong to anyone?

    Tween openTween = new Tween( this, 0.25f, new TweenConfig()
    .setEaseType( EaseType.QuadIn )
    .floatProp("_width", 100)
    .floatProp("_height",100)
    .onComplete(c => Debug.Log("FINISHED"))
    //.onComplete( c=> renderPopup = false)
    );

    openTween.play();

    I have both _width and _height set up as public variables with a getter and setter as in the wiki. The code runs without errors, but the values don't actually change. I tracked the values with a Debug.Log, but noticed no changes. Any suggestions?
     
  19. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pickles, assuming you have props setup like below that looks about right to me:

    Public float _width { get; set; } // setter and getter can of course be implemented
     
  20. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    Yeah...that's what I have...I'm going to try it in a new script file to see if I can isolate a problem. Let me know if you have any suggestions. If I can't get a simple thing working, I'll post that code.

    Thanks!
     
  21. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    So I just made a simple script, and the Tween doesn't seem to play. I tested to make sure that editing the variable in update would adjust the GUI.box's position, which worked. The tween is just not changing the value.

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestUITween : MonoBehaviour {
    5.  
    6.     public bool playAnim = false;
    7.     public float _x { get; set; }
    8.     private Tween openTween;
    9.  
    10.  
    11.     // Use this for initialization
    12.     void Start () {
    13.         openTween = new Tween( this, 1.0f, new TweenConfig()
    14.             .floatProp("_x", 900)
    15.             );
    16.     }
    17.    
    18.     // Update is called once per frame
    19.     void Update () {
    20.         if (playAnim){
    21.             openTween.rewind();
    22.             openTween.play();
    23.             playAnim = false;
    24.         }
    25.     }
    26.  
    27.     void OnGUI(){
    28.         Debug.Log(_x);
    29.         GUI.Box(new Rect(_x, 100, 200, 100), "BOX GO");
    30.     }
    31. }
    32.  
    Any thoughts?
     
  22. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pickles, I whipped up this working sample:

    Code (csharp):
    1.     private float _someFloat = 10f;
    2.     public float someFloat
    3.     {
    4.         get
    5.         {
    6.             return _someFloat;
    7.         }
    8.         set
    9.         {
    10.             _someFloat = value;
    11.             Debug.Log( "someFloatt changed: " + value );
    12.         }
    13.     }
    14.    
    15.     void Start()
    16.     {
    17.         Go.to( this, 10f, new TweenConfig().floatProp( "someFloat", 100 ) );
    18.     }
    and also this one that is more similar to yours:

    Code (csharp):
    1.     public float someFloat
    2.     {
    3.         get; set;
    4.     }
    5.    
    6.    
    7.     void Start()
    8.     {
    9.         Go.to( this, 10f, new TweenConfig().floatProp( "someFloat", 100 ) );
    10.     }
    11.    
    12.    
    13.     public void Update()
    14.     {
    15.         Debug.Log( "someFloat: " + someFloat );
    16.     }
     
  23. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    Awesome, that works.

    It seems that you can't create a Tween and use its play commands. Is this a missing feature, or designed as intended? It seems odd to not be able to use the Tween class for custom properties.

    Either way, this runs. I appreciate the assistance!
     
  24. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @pickles, plugging the following code (notice the extended BaseDemoGUI class to provide visual controls) full control works fine for me:

    Code (csharp):
    1. public class SimpleTween : BaseDemoGUI
    2. {
    3.     public Transform cube;
    4.    
    5.     public float someFloat
    6.     {
    7.         get; set;
    8.     }
    9.  
    10.     void Start()
    11.     {
    12.         _tween = Go.to( this, 10f, new TweenConfig().floatProp( "someFloat", 100 ) );
    13.     }
    14.  
    15.  
    16.     public void Update()
    17.     {
    18.         Debug.Log( "someFloat: " + someFloat );
    19.     }
    20. }
     
  25. PicklesIIDX

    PicklesIIDX

    Joined:
    Aug 4, 2009
    Posts:
    32
    So a Go.to returns a Tween. Complete failure on my part to read the function call in the wiki there. Thank you for taking the time to inform me!
     
  26. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    How does this compare to HOTween? Sorry if this has been asked before.
     
  27. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helios, I can't say I have ever used HOTween so I can't say. When we needed a tween lib HOTween was the first thing we grabbed but as soon as we saw how it set values on mobile we stopped evaluation immediately. We needed something a bit more high performance.
     
  28. helios

    helios

    Joined:
    Oct 5, 2009
    Posts:
    308
    I'm in need of a tweening solution and HOTween was also the first thing I grabbed (haven't used yet). Considering mobile is our main target, I'll take your word for it and check out GoKit :) How was it setting the values btw?
     
  29. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @helios, on desktop it was using a very fast and clever approach using Reflection to emit and JIT compile code on the fly. On mobile (due to the lack of JIT compiled code) it resorted to dog slow reflection.
     
  30. Cameron_SM

    Cameron_SM

    Joined:
    Jun 1, 2009
    Posts:
    915
    Greate little addon. However I'm confused about how the .asset path files are used in final builds. In the editor everything works fine, I save them in StreamingAssets folder ect, but if I build the game I get a file IO error unless I then go and create a Raw folder inside my "Game Name_Data" folder and copy the .asset from Streaming Assets (which is already in the build's data folder) into the Raw folder. Is this how it's meant to function? Kinda annoying that I have to manually mess around with that for every build - makes it impossible to do multiplayer testing if I have to manually make folders and copy files around every time I want to test a change.

    Here's the error I get when just building the project (from output.txt):
    I'm not sure why it's looking inside that Raw folder which doesn't even exist in the build's generated folder. The StreamingAssets folder does exist inside the generated [TailDrift Multiplayer Demo_Data] folder, and it's got my CameraLevelOverview.asset spline in there too, but it's not trying to load it from there once I build the game.

    Edit: I should point out this is a desktop/windows build, not iOS. Not sure if that's the reason (found this thread through google and posted before seeing that this was in the iOS section).

    Edit 2: Quickfix (for windows): Append a relative path that'll work in both the editor and final build such as:

    Code (csharp):
    1. new GoSpline("..\\StreamingAssets\\MyPath.asset");
    Final build will then load form \Raw\..\StreamingAssets\... (or just \StreamingAssets\...) which does exist in the build files.
     
    Last edited: Jul 12, 2012
  31. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @cameron, honestly, GoKit wasn't run a single time in Windows. I haven't booted Windows up in so many months I can't remember.
     
  32. Visloc

    Visloc

    Joined:
    Jan 17, 2012
    Posts:
    6
    I liked, with iTween i have too much lag and i test GoKit and i dont have lag this is for mobile and is much smoother in Fps etc.. from other "Tweens"
    Thanks for make free :)
     
  33. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @visloc, glad to hear you are liking GoKit :) We were 100% mobile focused from day one so it made sure everything was really fast.
     
  34. Tripwire

    Tripwire

    Joined:
    Oct 12, 2010
    Posts:
    442
    I'm trying out GoKit now but i get a debug error on this line:

    Go.to( Camera.main.gameObject, 2f, new TweenConfig().position( new Vector3( 25, 23, 2 ), true ) );

    tween failed to validate target;

    EDIT:
    I'm using JavaScript btw
     
    Last edited: Jul 25, 2012
  35. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    It's not really a problem with GoKit specifically... but here's the issue I'm having, copypasta'd from another thread I posted in the tools section. I don't know if there's anything you can do to help, but I figured I'd mention it... I guess I'll have to use the dll version of GoKit or something.

     
  36. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @trip, use the transform for a position tween.


    @mattrix, have your tried the latest (non Unity) Monodevelop? It is usually quite a bit ahead of Unitys version and works like a charm as long as you done need the debugger (which is only in the Unity version).
     
  37. MattRix

    MattRix

    Joined:
    Aug 23, 2011
    Posts:
    121
    I'll check it out, although if it still syncs with Unity's projects at all then I guess it still won't work. For now I'm just using the dll version of GoKit, which is better than nothing, but I'd really like to be able to easily edit+view the source as needed... it also makes debugging more tricky.

    Oh and I found a bug in GoKit. If you set the tween duration to zero (0.0f), any floatProps will get turned into NaNs for some reason, whereas I'd expect the float to just be set instantaneously (or on the next tween update, I guess?). The workaround is just setting the time to something super small like 0.0001f, so it's not a huge deal, but it took me a little while to figure out why 0.0f was making crazy errors happen.
     
  38. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mattrix, the way I do development for GoKit and any projects with shared code might actually work for you. I open the GoKit source in the latest Monodevelop (non-Unity build). I use the post build action in Monodevelop to copy the DLL to my Unity project. I then just use Unity as normal with its built in Monodevelop. This lets me jump back and forth between the two Monodevelops easily. I'll look into the bug. We also happily take pull requests via GitHub :)
     
  39. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    I've played around with this briefly and great job!

    I tried to build my game for iOS but was met with:

    Error building Player: SystemException: System.Net.Sockets are supported only on Unity iPhone Advanced. Referenced from assembly 'Mono.Data.Tds'.

    i am using iOS basic, but on your site you state:

    All our plugins are compatible with Unity 3.x Basic

    i installed from the asset store. Any help would be much appreciated.

    oh, a side question, are durations internally multiplied by deltaTime or something to that effect, or is that something i need to take care of myself?
     
  40. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mu-kow, GoKit isn't a native code plugin. It is all contained in Unity and definitely doesn't use sockets. You may want to check for other packages that are in your project. Duration is in seconds and is the length of the tween.
     
  41. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    @prime31 thanks for the reply, i ended up finding the culprit, a file named system.data.dll was in my assists folder (have no idea how it got there...).

    also, i appreciate the free asset, i've been keeping an eye on your other plugins and this'll give me a better feel of what to expect from your other products
     
  42. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    Sorry if I'm just missing something. Couple of questions:

    Edit: by dynamic end target i mean, the position vector changes.
    Is it possible to have a dynamic end target for the tween?
    (I'd like to have something tween to the main player during any movement)

    Is it possible to have a path that fallows another object?
    (like create a circular path and have the path follow around the main player)
     
    Last edited: Jul 28, 2012
  43. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @mu-kow, for a dynamic target you would have to constantly remove then add the tween. That is probably something better suited for just doing in the objects update method. The same goes for the path. You would be better off using the Unity provided method for orbiting right in the objects update method
     
  44. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    @prime31 thanks for the info.

    question:

    "target validation failed. destroying the tween to avoid errors"

    i was trying to take care to not have this show up when loading another level by doing this:

    void OnDestroy(){
    Go.removeTween(someTween);
    someTween.Destroy();
    }

    that worked, but sometimes i get:

    "Some objects were not cleaned up when closing the scene"

    so i guess my question is, is there any harm in letting the tweens clean themselves up in this case? if there is, how do you recommend i go about cleaning everything up?
     
  45. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    The downloaded GoKit folder is 3.8 MB. I am wondering, if I am only using paths in it, will the final build have an added 3.8 MB? Is there a way to insure a smaller file size?

    Also, I just went to import the asset into my project but the file I can not find, so I went to the page and downloaded the zip (http://prime31.github.com/GoKit/) but it seems this is just the demo. Am I missing something? Where can I find the link for the asset?

    Thirdly, if this is used in my project for iOS market release, is there a licensing fee?
     
  46. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, you will want to remove the Tweens if possible. That will clean them up a bit quicker. If you don't, they will eventually get cleaned up so it isn't too big a deal. There is no licensing fee for GoKit.
     
  47. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Ok. Great.
    Regarding the download. Is tha the correct link?
     
  48. prime31

    prime31

    Joined:
    Oct 9, 2008
    Posts:
    6,426
    @renman, that is the correct location for the library. All the source code is available on GitHub.
     
  49. renman3000

    renman3000

    Joined:
    Nov 7, 2011
    Posts:
    6,697
    Ok, will double check, I must have not gone to the github library. Right!
    Cheers.
     
  50. mu-kow

    mu-kow

    Joined:
    May 15, 2012
    Posts:
    106
    @prime31

    thanks for the quick response!

    I have been playing around more with this and i have to say that i am very impressed!

    Thanks for the great and free resource! I'll certainly be purchasing some of your other plugins when the time comes :D