Search Unity

2D Toolkit - 2D in Unity made simple [RELEASED]

Discussion in 'Assets and Asset Store' started by unikronsoftware, Jun 16, 2011.

  1. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    Unity 4.3.0f4
    2DTK... had some difficulty finding the version number in the actual downloaded files (I know it is the latest version) so I searched the code to make sure there was no mistakes and sure enough in this file:
    tk2dEditorUtility.cs

    So it is 2.3
     
  2. Zelek

    Zelek

    Joined:
    Jun 12, 2010
    Posts:
    87
    I just picked up 2D Toolkit, and I'm trying to figure out how to set up an isometric tile map with collision. Are there any tutorials related to this? I went through the tile map tutorial, but I imagine isometric maps will be considerably different.
     
  3. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    No specific tutorials, but its more or less the same.
    1. Switch to Settings > Tile Properties.
    2. Tile Type > Isometric
    3. Enter the correct tile sizes
    4. Switch to Paint mode and paint.
    5. Colliders will be merged the same way they do with normal tiles.
     
  4. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can simply enter the 2D Toolkit > About menu to find out what version you're on. Its the latest version, so its really quite puzzling why this is happening on your installation and not over here. Can you zip up your repro project (the one where you imported into an empty project) and email to support at unikronsoftware.com? I'll look into it.
     
  5. Shinugami

    Shinugami

    Joined:
    Oct 17, 2012
    Posts:
    54
    When I had imported 2DTK in the menu there was only 2 options available. Integrity check and Setup for JS. There was no About.
    I started a new project and before importing anything else I imported 2DTK and it seems to have worked, there is no errors and the menu is complete.

    So I guess it works now. Thankyou for your help and concern. If I get any errors again I'll make note of them but in my opinion I think it had not imported correctly.
     
  6. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    Hello,

    I made an iOS build of my game (only displays a couple of sprites and a tilemap) and I'm noticing that it stutters randomly every couple of minutes or so.

    I've been looking at the profiler data and noticed that tk2dCamera.OnPreCull() is allocating 128 bytes every frame.
    This doesn't seem like a lot but I can see it adding up and triggering a garbage collection every now and then, which I think is causing the stuttering.

    Do you have any thoughts on what to do about this?

    I'm running 2dtoolkit 2.30, on an iPad 3rd gen.
    I don't have a pro iOS license so I'm using the profiler simply by pressing play in the editor and opening the profiler window, I'm not actually using the remote profiler thing for iOS.

    Thanks
    nacho.
     
  7. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The tk2dCamera.OnPreCull memory allocation only happens in the editor - it occurs in tk2dCamera.GetScreenPixelDimensions (reflection to find the game view resolution). You can verify by deleting that bit of code.

    It may well be GC, but I'm pretty certain tk2dCamera.OnPreCull isn't the cause of it.
     
  8. nachobeard

    nachobeard

    Joined:
    May 7, 2013
    Posts:
    47
    ok, I'll have another look around, see if I find any other offenders :)
    thanks for the quick reply
     
  9. Kafar

    Kafar

    Joined:
    Nov 29, 2012
    Posts:
    220
    Hi,

    I don't know if this is a known issue but I receive the exception below on Unity 4.3 and looking in the code a row 702 there's a comment about a bug workaround.
    The only update is the PlayMaker and 2D Platform Controller, done 10 minutes ago, after this update I received the exception below.
    Thanks in advance.

    -Kafar

    IsMatrixValid (matrix)
    UnityEngine.Camera:set_projectionMatrix(Matrix4x4)
    tk2dEditor.tk2dCameraSceneGUI:previewWindowFunc(Int32) (at Assets/TK2DROOT/tk2d/Editor/Camera/tk2dCameraEditor.cs:702)
    UnityEditor.DockArea:OnGUI()
     
    Last edited: Nov 28, 2013
  10. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That is specifically about a bug in previous versions of Unity - it shouldn't affect you in 4.3. What version of 2D Toolkit are you using, and can you send a pic of your tk2dCamera settings page to support at unikronsoftware.com?
     
  11. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello unikron
    i decide to put my hand on your tool and i m happy so far, i have a little issue where i cant find any documentation about it wich is very crucial for my game or any 3d game, in my game i have several 3d cameras that i switch with and i wanted to use toolkit2d as hud , but each time i deactivate one camera t UI disapear. is i possible to achieve that?
    i use the 1-UI demo and add few several camera on that scene for exemple.
    any hint would be apreciated
    thanks

    edit: it seem to work on the 3- 3d UI scene, but cant find how to setup this to work for the 1-UI demo.
     
    Last edited: Dec 8, 2013
  12. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    That example uses Unity layers to configure what each camera sees. Have you set up layers properly on your cameras objects?
     
  13. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    thanks for the quick reply, i just find the error, by default the camera deph is at zero, i just need to put -1 and it work all fine. my bad.
    cheeers!
     
  14. EddieChristian

    EddieChristian

    Joined:
    Oct 9, 2012
    Posts:
    725
    Im using the current build of unity and 2d toolkit. For some reason i am getting this error when I finish the Mole tutorial even though everything is properly assigned:

    Code (csharp):
    1. NullReferenceException: Object reference not set to an instance of an object
    2. MainGameScript+<Start>c__IteratorA.MoveNext () (at Assets/EDDIE2D_TUT/SCRIPTS/MainGameScript.cs:48)
    And the Javascript examples Immediately kick out 3 errors on import into the project.
     
    Last edited: Dec 14, 2013
  15. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    There is a completed package you can compare your work to at the end of each tutorial page. I recommend importing that into a new project and comparing yours to it.

    The javascript ones - have you run Setup For JS?

    If you're still having trouble, zip up the project and send to support at unikronsoftware.com, I'll be happy to take a look.
     
  16. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
  17. Koamr

    Koamr

    Joined:
    Jul 19, 2013
    Posts:
    8
    Hello Unikron,

    have you seen https://www.youtube.com/watch?v=4qE8cuHI93c ? I find those features amazing. Building complex animation from sprites in-unity? Super cool. Particle system? Even more cool. It would be shame, if those features would not be compatible with tk2d.

    Perhaps are you planning to integrate tk2d with unity 4.3 2d features? Perhaps rework tk2dSprite to somehow extend default Unity spriteRenderer? Or some kinds of wrappers over tk2d classes? Right know I am torn between using unity 4.3 2d features and tk2d. I'm not sure whether I should go full tk2d, if it will go further and further away from Unity 2d features. I mean, its Unity. They have more resources and I'm sure, they won't stop creating new cool features.

    I would appreciate your answer on this topic.

    Cheers.
     
  18. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    We've integrated all the features we can right now, and plan to integrate as tightly as possible in the future as they add more features. Here's a page we put together about the new tk2d features in 4.3 -
    http://2dtoolkit.com/unity2d.html

    And a page from the docs -
    http://2dtoolkit.com/docs/2.3/unity_43_integration.html
     
  19. colpolstudios

    colpolstudios

    Joined:
    Nov 2, 2011
    Posts:
    150
    Last edited: Dec 19, 2013
  20. toto2003

    toto2003

    Joined:
    Sep 22, 2010
    Posts:
    528
    hello
    i was testing the uidemoscene, i manage to got few Buttons working, but fail to get more than one row on the uitextinput, is this an expected behavior? if yes would it be possible to have more than one row like the wrapper you had in tk2dtextmesh?

    thanks
     
  21. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The ui text input isn't designed for multi line input at the moment. I've added it to the roadmap trello, feel free to vote on it. https://trello.com/b/UfqlXqXy/2d-toolkit-roadmap
     
  22. eridani

    eridani

    Joined:
    Aug 30, 2012
    Posts:
    655
    There is a 24 hour sale going on right now for an asset called Sprite Factory... I was wondering if it had any capabilities that 2DToolkit doesn't, or perhaps might have some problems working together with 2DToolkit. Any info welcome. Thank you
     
  23. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,037
    I think Sprite Factory is made for the built-in 2D functionality in Unity, so it's not so much working with 2D Toolkit as completely ignoring it. It's just an animation system, as it says in the description. You don't need it at all if you already have 2D Toolkit, since SF only has a subset of the functionality of 2DTK.
     
  24. coder_for_life22

    coder_for_life22

    Joined:
    Dec 25, 2013
    Posts:
    46
    Does anyone know if it is possible to make the Draggable button collidable with other bodies? Meaning the Draggable button wont be able to go through other objects with colliders
     
  25. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Hi,
    Apologies for missing this post entirely. Somehow missed it every time I looked at this thread!

    You will need to tweak the draggable button script to make it work like this. Instead of using transform.position to move it (tk2dUIDragItem.UpdateBtnPosition) you will need to apply forces to a rigid body (disable gravity to avoid it dropping). This way it will collide with other objects as you drag it around.
     
  26. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    I was wondering what's the best way to resize the tk2dCamera's Zoom Factor based off the size of a room (level boundaries).

    E.g. the room/level is smaller then the current camera's bounds, so change the zoom factor so that the camera bounds match up with the levels bounds.
     
  27. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Once you figure out the bounds of the visible sprites, you will need to work out the visible area of the camera in world space (ScreenExtents). Zoom factor is just a scale to fit ScreenExtents into the visible sprite size.
     
  28. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    So, when we're using the tk2dcamera, is Zoom factor the only way we can directly modify the camera's width and height in code? Because right now it seems like we can't modify ScreenExtents to match the sprite size, we can only see it's value.
     
  29. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    ScreenExtents is dependent on resolution, you can't change it. You should change zoom factor to change the camera size.
     
  30. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    What's currently the best way to disable the input on a 2D Toolkit button?
     
  31. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Everything in tk2d UI relies on the collider being hit by a ray cast. You just need to stop this somehow to "disable" something. Eg. turn off the collider on the button, etc. Similarly if you have a window in front of something and want to occlude, simply attach a bit collider to the window and that will occlude things behind it.
     
  32. Sartoris

    Sartoris

    Joined:
    Dec 8, 2013
    Posts:
    23
    Could this tool be used to procedurally create maps like those in Civilization 1? If not procedurally, could it at least be used to make maps like those by hand?
     
  33. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    I was wondering if you could suggest why this code might not be working.

    What I'm trying to do is save the tk2DCamera's ZoomFactor and ScreenExtents based off of the values set in the inspector on Start. Then I want to store the ScreenExtents when the ZoomFactor is 1.

    The problem I'm having is that when I try to store the ScreenExtents when the ZoomFactor is 1, it stores the inspector's ZoomFactor value.

    Code (csharp):
    1.  
    2.  
    3.     // Use this for initialization
    4.     void Start ()
    5.     {
    6.         //Get values from inspector
    7.         float defaultZoomValue = camera2DToolkit.ZoomFactor;
    8.         Rect defaultCameraScreenExtents = camera2DToolkit.ScreenExtents;
    9.  
    10.        //Set ZoomFactor to 1, then store the screen extent values when ZoomFactor is 1
    11.         camera2DToolkit.ZoomFactor  = 1.0f;
    12.         Rect ScreenExtentsWhenZoomFactorIs1 = new Rect(camera2DToolkit.ScreenExtents);
    13.        
    14.        //Put ZoomFactor back to default value
    15.        camera2DToolkit.ZoomFactor = defaultZoomValue;
    16.     }
    17.  
    18.     void FunctionCalledLater()
    19.     {
    20.        //This value is not the ScreenExtents when ZoomFactor is 1, it is the ScreenExtents
    21.        //when ZoomFactor is default from inspector, despite me storing it earlier.
    22.        float height = ScreenExtentsWhenZoomFactorIs1.height;
    23.     }
    24.  
    25.  
    EDIT:
    I do believe the answer to this problem is that ScreenExtents is not updated when ZoomFactor is changed. It is changed in update, thus the ScreenExtents wouldn't be saved the way I thought they would be.
     
    Last edited: Jan 16, 2014
  34. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    Fairly easily. You just create an empty tile map in the editor, attach your script to it and do what you wish with it at runtime. GetTile / SetTile to change tiles, Build() to build it. (http://2dtoolkit.com/docs/latest/html/classtk2d_tile_map.html).

    You could make maps like that by hand too (tutorial: http://2dtoolkit.com/docs/latest/tilemap/tutorial.html), or mix and match as you see fit.
     
  35. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You're right ScreenExtents isn't updated when any properties are changed - that just happens once per frame. You can explicitly call UpdateCameraMatrix to force an immediate update though.

    Edit: On second thought, it isn't necessary to do that at all. All you need to do is to store the ScreenExtents once at startup (make sure its AFTER its updated it!), and then you can calculate ZoomFactor accurately without involving feedback or even caring about what ScreenExtents was changed to.
     
  36. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    That's good to know.

    For the main menu of our game we have a 2D Toolkit sprite as the background, which is a field of stars. My team wanted me to have the starfield scroll as the player sits on the main menu, and the only way I can figure to do it is with offsetting material UV's, which in this forum post you seem to say that's not possible.

    http://2dtoolkit.com/forum/index.php?topic=937.0

    I was wondering if there have been any changes to 2D Toolkit since then that would allow me to do such a thing? If not are there any suggestions you could recommend?
     
  37. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can't tile / offset a tiled texture from within an atlas, as the texture will have something next to it in the atlas. The easiest option is to not use an atlased texture for this (check sprite from texture) which is probably the best thing to do here as its a background and presumably only one of these exist.
     
  38. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    When you say "not use an atlased texture for this (check sprite from texture)", do you mean set the texture import to Sprite, and use Unity's 4.3 sprite instead of 2D Toolkit's sprite?

    Or is there a way to set the 2D Toolkit sprites to not use atlases?


    My main issue is with your much better 2D Toolkit sprites I can directly set the background sprite in code to be the screen size, but I cannot move the texture offset due to the atlas. With Unity's sprites I can move the offset, but there's no direct way to set the sprite to be the screen size, as you can only use the scale to change the sprite's size.
     
    Last edited: Jan 19, 2014
  39. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    You can create a tk2dSprite without an atlas - use the Sprite from Selected Texture function. http://2dtoolkit.com/docs/latest/reference/sprite_from_selected_texture.html

    You can then do whatever you like with the material attached to this.
     
  40. Ben-BearFish

    Ben-BearFish

    Joined:
    Sep 6, 2011
    Posts:
    1,204
    Thank you. Your toolkit is seriously awesome.

    Regarding tk2dSpriteFromTexture, the SpriteCollectionSize does not show the Resolution Width Height in the inspector if it's set to explicit. Was this removed?

    I was trying to figure out how to resize the tk2dSpriteFromTexture to screen size.


    EDIT:
    It looks like this code will do what I needed:

    Code (csharp):
    1.  
    2. float pixelsPerMeter = backgroundNormalSpriteFromTexture.spriteCollectionSize.pixelsPerMeter;
    3. Vector3 nativeSize = backgroundNormalSprite.CurrentSprite.GetUntrimmedBounds().size;
    4. backgroundNormalSprite.scale = new Vector3( screenSize.x / (nativeSize.x * pixelsPerMeter), screenSize.y / (nativeSize.y * pixelsPerMeter), 1);
    5.  
    The only remaining problem I have is when I grab the material on the sprite and move the texture UV's using:

    Code (csharp):
    1.  
    2. backgroundNormalSprite.CurrentSprite.materialInst.SetTextureOffset( "_MainTex", uvOffset );
    3.  
    In the code inspector the UV's are updating, but on the game window they are not. Is this something to do with the BlendVertexColor shader? Should I be accessing the UV's some other way?
     
    Last edited: Jan 21, 2014
  41. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    The default tk2d shader doesn't use texture offsets, as it doesn't need it in the context of sprites. You should switch it to one of the built in Unity shaders for that, eg. Unlit/Transparent
     
  42. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    Unity 4.3.3 f1
    2D Toolkit 2.3.3

    I have a tk2dUIScrollableArea object on the Scene. In its Content property , the object must be a tk2dTextMesh object.

    In the script, the text property of tk2dTextMesh should be changed.

    All my attempts do not alter the ContentLength property of tk2dUIScrollableArea.

    (MeasureContentLength ()
    -no effect.

    textGO.transform.parent = null;
    text: text + = "Blablabla.";
    tehtGO. parent transform. = ScrollableMenu.contentContainer.transform;
    -no effect.
    And so on.)

    I have tried everything and can't understand why it is not happening. And very pleased this extremely intuitivony things! :mad:
    The main question is how to do it?!
     
    Last edited: Jan 22, 2014
  43. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    MeasureContentLength() only measures the content length.
    You need to set it, probably adding after adding some padding.
    scrollableArea.ContentLength = scrollableArea.MeasureContentLength() + padding;
     
  44. AGeorgy

    AGeorgy

    Joined:
    Sep 16, 2013
    Posts:
    42
    1. Change text from script.
    2. Call textMesh.Commit() - this will update the mesh immediately instead of at the end of the frame
    3. scrollableArea.ContentLength = scrollableArea.MeasureContentLength()
     
  45. AjayKhara

    AjayKhara

    Joined:
    Jul 10, 2013
    Posts:
    4
    I am using more than one camera in a game, each camera has different viewport.

    All cameras viewports are set in such a way that they all can render certain objects. at the same point.

    Now, while changing the viewport rect of a camera, sometimes the objects rendered by the camera are re-sized(Meaning : Shown smaller or larger on the screen, not actually re-sized).

    When the viewport width is changed, the size remains the same. but changing the viewport height affects the size.

    All camera's are orthographic. What should I do so that the size of the objects shown remains the same irrespective of the camera viewport ?

    Thanks.

    Case 1 : This does not change the size.

    gameCamera1.rect = new Rect(0,0,0.5f,1);
    gameCamera2.rect = new Rect(0.5f,0,0.5f,1);
    Case 2 : This does change the size.

    gameCamera1.rect = new Rect(0,0,1,0.5f);
    gameCamera2.rect = new Rect(0,0.5f,1,0.5f);

    You can see these images. To get the idea more clear.!
    In Image "1" the size is perfect, in Image "2" the objects have shrink.
    $1.png $2.png
     
  46. ColonyGames

    ColonyGames

    Joined:
    Aug 24, 2013
    Posts:
    9
    Hello,

    First thing I'd like to say is I love the 2D Toolkit. It's a great product at a great price.

    I'm in the process of trying to get the most I can out of it. My first question is will layers assist in my problem of needing tiles on top of other tiles?

    For example, let's say I have tree tiles that have a transparency so you can see other tiles behind them. Like in Secret of Mana:
    $Secret_of_Mana_SNES_ScreenShot2.jpg

    You'll see on the right that the tree has different types of tiles behind it. There's a flower tile behind it, as well as a grass tile.

    However, there's another situation here where I wouldn't know what to do:
    $secret_of_mana_vcmm_10132008.jpg
    http://3.bp.blogspot.com/_4wmuxoiDvdw/TSoy2HebLJI/AAAAAAAAADY/43GwD8YqvVQ/s320/secretofmana.jpg

    Trees appearing in front of other trees, and as you can see on the top right, trees in front of cliff tiles. Replacing trees with sprites would be horribly inefficient, so I'm at a loss here.

    How can I accomplish this?

    Second question is this:
    How can I animate tiles? For example, if I want to animate a current flowing across water. Or water as it splashes ashore. Are shaders my only option or can I have animated tiles?

    Thank you,
    Brian
     
  47. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    1. Layers will definitely work here. You just create your sprites with transparency and it should just work. You can set the tile sort order in tk2d, to get them to sort properly. This isn't super flexible, as ultimately you will need to sort your character sprites with these. You have another option, using the static sprite batcher - that will work pretty well too, but you won't be able to paint them in like tiles in the tile map.

    2. About animated tiles. This is always super tricky as sprites in the tile map aren't really sprites at all, they're merged and optimised into a larger mesh. However, this is doable using shaders - use material overrides on the sprite collection (http://2dtoolkit.com/docs/latest/tutorial/multiple_materials_in_a_sprite_collection.html) to assign an animating material. Whenever you paint that sprite in, it gets replaced with your sprite. We'll possibly make a sample showing how you can achieve this in the next version of tk2d.
     
  48. praveenEL

    praveenEL

    Joined:
    Jul 31, 2012
    Posts:
    14
    Hey,
    I'm New to 2dtk and this may be a very basic question which should be asked on earlier. How can i add 2dtk panel which can slide using button click. is there a specific component on 2dtk?

    Cheers
     
  49. unikronsoftware

    unikronsoftware

    Joined:
    May 21, 2011
    Posts:
    1,287
    2D Toolkit doesn't have a "Panel" construct, but its easy enough to create and use them.
    Check the samples, most of them have "panels" in them. A panel is just a game object with a background sprite (sliced sprite works beautifully) collider to block clicks to things behind it.
     
  50. praveenEL

    praveenEL

    Joined:
    Jul 31, 2012
    Posts:
    14

    Thanks for your quick reply (Y)