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

ex2D - the best 2D sprite solution for Unity [RELEASED]

Discussion in 'Assets and Asset Store' started by johnny_karas, Aug 24, 2011.

  1. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Em, my question is: are those exSpriteAnimationClips using these atlas also included in the Asset Bundle?
     
  2. Lisan

    Lisan

    Joined:
    Jun 17, 2009
    Posts:
    220
    Actually i don't know, i haven't tried it yet. I planned to put only textures there, but maybe prefab with script component will do.
    I never used asset bundles before, so i'm not sure how they are working yet. Will do some experiments.
     
  3. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    OK, I didn't try much complex structure in asset bundle. So as far as I know, you should but assets that have dependencies all into one bundle, so if sprite animation clip reference 4 atlas, they should go into one bundle which can make sure they still keep the reference.
     
  4. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    jwu!

    One Question, All have one Animation Manager, who keeps reference to all animations i have on my game, and everytime i need play some animations i just call this functions:

    Code (csharp):
    1.  
    2. MJAnimationManager.PlayEx2DAnimationOn(exSprite, "anim_fire_gota");
    3.  
    Do you know if this keep reference to image? if was that, i load every single image in my game, at first scene, can you guys check that?
     
  5. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi badawe,

    This will keep all your animation clip, so it will referenced all atlas that these animation clips used for. Each atlas will reference the atlas texture so at the end you will reference all atlas textures that used in your animation clips in your game.

    That means you will load all atlas textures in your first scene definitely.
     
  6. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Holy CRAP! =/

    I Must change that immediately!!

    Another thing, do you know if have some way to bitmapFont break line automaticly?
     
  7. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Break line ? Do you mean wrap the text in a given rectangle zone ? Not yet, it is still in TODO list. Current version only support Multiline text.
     
  8. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Every time i compile for iOS i Get this warning, should I concerned?

    Code (csharp):
    1.  
    2. Script attached to 'ComedyClub - EditorInfo' in scene 'Temp/__BuildPlayer Backupscene' is missing or no valid script is attached.
    3. UnityEditor.HostView:OnGUI()
    4.  
     
  9. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    jwt i made some Wrap for my multiline texts:

    here is:
    Code (csharp):
    1.  
    2. private string WrapTextWithMaxChars(string pText, int pMaxChars)
    3.     {
    4.         string[] words      = pText.Split(' ');
    5.         List<string> lines  = new List<string>();
    6.         string currentLines = "";
    7.        
    8.        
    9.         foreach(string currentWord in words)
    10.         {
    11.             if((currentLines.Length > pMaxChars) || ((currentLines.Length + currentWord.Length) > pMaxChars))
    12.             {
    13.                 lines.Add(currentLines);
    14.                 currentLines = "";
    15.             }
    16.             if(currentLines.Length > 0)
    17.             {
    18.                 currentLines += " "+currentWord;
    19.             }
    20.             else
    21.             {
    22.                 currentLines += currentWord;
    23.             }
    24.         }
    25.         if(currentLines.Length > 0)
    26.         {
    27.             lines.Add(currentLines);
    28.         }
    29.        
    30.         string returnTxt = "";
    31.         foreach(string pLine in lines)
    32.         {
    33.             returnTxt+=pLine;
    34.             returnTxt+="\n";
    35.         }
    36.        
    37.         return returnTxt;
    38.     }
    39.  

    Maybe the only thing you need to do is the calcule of the
    TextBoxSize / Character Size = Max Characters per line!
     
  10. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Guys just to let you guys know that:


    I have ALL SpriteAnimClip referenced in one manager, im my mind this sound better, so this give me this usage of real memory on iPad 2:


    After I remove my spriteAnimClipManager, and set all the references of animations where this need to be, this give me at some points more than 30Mb of free memory :)
     
  11. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    So you should check about this ComedyClub - EditorInfo, see what happend to it. But since this is an editor error, you don't need to worry about the final build in your iOS device.
     
  12. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Thanks for sharing the code. I'll see what I can do.

    For us, we do have plan in wrapping text, and we are busying developing a GUI system based on ex2D, so this will in our todo list and available soon I guess.
     
  13. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Hi.
    1. can ex2d support 2dtoolkit's Sprite Batcher feature?
    2. figured it out q:
     
    Last edited: Oct 29, 2011
  14. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello valyard,

    In current version of ex2D, we didn't support customize batch sprites for static objects in the scene. We've consider this in our future release.
     
  15. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    Bounding box of multiline texts seems to be wrong.

    So, yellow and red lines show as though mesh is one line height )8
    Blue line shows actual mesh dimensions.

    Code (csharp):
    1.  
    2. exSpriteFont text;
    3.  
    4. Rect bounds = text.boundingRect;
    5. Debug.DrawLine( tt.position + new Vector3(bounds.xMin, bounds.yMin, 0) * tt.localScale.x, tt.position + new Vector3(bounds.xMax, bounds.yMax, 0) * tt.localScale.x, Color.yellow );
    6. Bounds bounds2 = text.GetComponent<MeshFilter>().sharedMesh.bounds;
    7. Debug.DrawLine( tt.position + (bounds2.min) * tt.localScale.x, tt.position + (bounds2.max) * tt.localScale.x, Color.red );
    8.        
    9. Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
    10. Vector3 max = new Vector3(-float.MaxValue, -float.MaxValue, -float.MaxValue);
    11. Vector3[] vertices = text.GetComponent<MeshFilter>().sharedMesh.vertices;
    12. foreach ( Vector3 vert in vertices ) {
    13.     if ( vert.x <= min.x ) min.x = vert.x;
    14.     if ( vert.y <= min.y ) min.y = vert.y;
    15.     if ( vert.z <= min.z ) min.z = vert.z;
    16.     if ( vert.x >= max.x ) max.x = vert.x;
    17.     if ( vert.y >= max.y ) max.y = vert.y;
    18.     if ( vert.z >= max.z ) max.z = vert.z;
    19. }
    20. Debug.DrawLine( tt.position + (min) * tt.localScale.x, tt.position + (max) * tt.localScale.x, Color.blue );
     
  16. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello valyard,

    We just fix a multi-line text problem within scale. So is this bug you report use the scaled sprite text?
     
  17. valyard

    valyard

    Unity Technologies

    Joined:
    Jun 4, 2010
    Posts:
    291
    yes, I use multiline sprite text which is scaled much. have to use the hack in the code right now.
     
  18. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    This kind of bug in ex2D make me going crazy:


    Any change on any atlas, crashes everything!

    serious guys, must have a way to prevent this kind of bug.
     
    Last edited: Nov 3, 2011
  19. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello badawe,

    I see there have a infinite loop at the end of the rebuild scene.

    Would you mind to tell me a step by step reproduce method? The snapshot do help us, but the resolution is too low to see things clearly.
    And you said "any change on any atlas, crashes everything" which is not really happend every time. So this kind of word can't help us figure out the problem.

    I can understand you are getting mad in such bug, and we really trying hard to reproduce it. Recently we catch this bug in some of our computer, but it is randomly happend. So your step in this video is really important for us!

    Can you send me a high resolution video on this? And if possible, can you write a step 1,2,3 to reproduce it? And BTW: in the last step, Which one you are rebuilding? the scene sprite or rebuild the scene layers?

    Thanks in advance for any help you provide!
     
  20. silver-wind

    silver-wind

    Joined:
    May 8, 2007
    Posts:
    19
    Is it possible to animate vertices ?
    I found the function ForceUpdateMesh() but I don't see how to use it.
     
  21. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi rineddy,

    The ex2D can't animate vertices freely. The ForceUpdateMesh just calculate the size of the quad vertices.

    However in the inspector, you can scale, shear the vertices. And if you are using Animation View Editor control them, you need to Enable the "Use Animation Helper" in the inspector. So it depends how complicate vertices animation you trying to do.
     
  22. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    Hi jwu,

    Great tool !

    Is it possible to create a fresh exSprite (GameObject.AddComponent), assign a texture and let the system figure out what to do with it ? Much like what happens in inspector when you drag and drop a texture but from code ? I managed to get a textureGUID for a texture that is in an atlas and assign it to exSprite.textureGUID, but the sprite does not update until I select the object. Even with ForceUpdateMesh with all updateflags. And it does not work with a texture that is not in an atlas so that would be only half the result I want.

    Thanks.
     
  23. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi jfmoulin,

    You can not assign texture to sprite in Runtime. Because when you running the game, there is no original texture in the build app. However, if you wish to do it in Editor, here is the way:

    Code (csharp):
    1.  
    2. Texture2D newTexture = ...;
    3. exSprite yourSprite = ...;
    4. yourSprite.Build( newTexture );
    5.  
    Remember, the exSprite.Build only available in Editor. And inside it, there have lots of UnityEditor Only API, that's another reason there have no way to make it work in Runtime.
     
  24. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
  25. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi badawe,

    Many thanks to the video, I'm waiting for download.

    There have a hack solution for this. Since the problem caused by the progressBar can't not clear from the editor, You can open a atlas editor, and select an atlas, click the Apply button which will do some code including clear the progress bar. After that, you will get back of your control.

    BTW:

    We are thinking about to introduce a TextureInfo asset and a json/xml DB file for solving the problem when working with Asset Server or other CVS tools.

    So with the json/xml DB, user can merge things instead of accept one (cause the binary file format). And the TextureInfo will solve the rebuild problem when changing atlas and loading other scenes.

    We are going to develop this in the next coming 1.3.0 with lots of other new features. In the mean-time I still try to find the problem and see if I can do a quick fix.

    Please be patient and follow our daily fix.
     
    Last edited: Nov 7, 2011
  26. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    Thanks jwu !

    This is for editor, not runtime. It does exactly what I wanted to do.

    Is it documented somewhere ? In your documentation, section editor script reference, exSprite is not listed.
     
  27. badawe

    badawe

    Joined:
    Jan 17, 2011
    Posts:
    297
    Great jwt! I'm waiting!
     
  28. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Well, it belongs to exSpriteUtility, in here: http://www.ex-dev.com/ex2d/script_ref/classex_sprite_utility.html
     
  29. Seokho

    Seokho

    Joined:
    Aug 31, 2011
    Posts:
    23


    Hello, in this video (I recorded) I used soft clip.
    And in my script add items (child of soft clip object) and update soft clip manually.
    Then I try to move these children objects using transoform's position.
    And it looks very different between ex2D's examples scene and mine.

    Clipping is not clearly. Why? Did I do something wrong?
     
  30. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello Seokho,

    Your video is set to private. Here is the Youtube message: This video is private, Sorry about that.
     
  31. Seokho

    Seokho

    Joined:
    Aug 31, 2011
    Posts:
    23
    Hello jwu,

    I changed youtube access^^;;
    And I resolved this problem myself.
    I had a orthographic UI Camera with size 1.
    This makes a problem. So I changed size where reference adviced. (Screen / 2).
    And I fixed all of UI.
    And clipping worked very good.
    Thanks.
     
  32. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    Is it me or exSprite.Build and exSpriteUtility.Build do not assign any values that are editable in inspector ? I can see the sprite in the scene, but it does not set the corresponding atlas and index and the exSprite texture in inspector it still a gray square. Is it a bug or the expected result ?

    Thanks
     
  33. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704

    Hi jfmoulin,

    Sounds strange. Basically after exSpriteUtility.Build invoked, it will update the scene. I'll try to reproduce it. Can you give me more details in how you doing this in script ?

    Regards
     
  34. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    I'm currently doing an editor window where I need to replicate some functionality of your Ex2D to ease integration of it. In my window, I set that I'll be using Ex2D and I drag and drop a texture in my window to set the texture.

    In pseudo code :

    Get the texture from DragAndDrop
    if we have a texture
    Get the script containing exSprite
    exSprite.Build( texture )

    I then access atlas and index but they are not updated even though I see the sprite in the scene.
    If I click the object with the exSprite script, I see default values in all exSprite fields in inspector.

    I will try to make a simple script to isolate the problem.

    By the way, I'm on mac with unity 3.4.2f2 indie.
     
  35. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    here is a script that gets the same behavior. This is as simple as it gets.

    Code (csharp):
    1.  
    2. public class TestBugEx2D : EditorWindow
    3. {
    4.     public GameObject _ObjTest = null;
    5.     static TestBugEx2D _EditorWindow;
    6.  
    7.     [ MenuItem( "Window/Test/TestBugEx2D" ) ]
    8.     static void StartFlex()
    9.     {
    10.         TestBug();
    11.     }
    12.    
    13.     static void TestBug()
    14.     {
    15.         _EditorWindow = (TestBugEx2D)EditorWindow.GetWindow( typeof( TestBugEx2D ), true, "Test Bug Ex2D" );
    16.        
    17.         _EditorWindow.Show();
    18.        
    19.         GameObject obj = new GameObject("ObjTest");
    20.         obj.AddComponent< exSprite >();
    21.         _EditorWindow._ObjTest = obj;
    22.     }
    23.    
    24.     void OnGUI()
    25.     {
    26.         if( Event.current.type == EventType.DragExited )
    27.         {
    28.             Texture2D tex = DragAndDrop.objectReferences[0] as Texture2D;
    29.             if( tex != null )
    30.             {
    31.                 exSprite sprite = _ObjTest.GetComponent< exSprite >();
    32.                 sprite.Build( tex );
    33.             }
    34.         }
    35.     }
    36. }
    Simply open the window from window/test/testbugex2d and drag a texture anywhere in the window. For reference, I used one of your image (ninjajump_1). If I drag it in the window, the inspector is not updated but if I drag it in the texture square in inspector, all values are updated.

    If you want other info, just ask. I don't know what else to say.
     
  36. Seokho

    Seokho

    Joined:
    Aug 31, 2011
    Posts:
    23
    Hello, jwu.

    I have a question about drawcall.

    ex)
    1. I have two images (.png)
    One is called Panel_C.png (60 * 221) and another is White_Round.png (24 * 24)
    2. Build these using ex2D and make through one material.
    3. And also make gui border using ex2D.
    4. Create 2 SpriteBorder objects.
    5. And assign those to 4's objets's GUI Border.
    6. Make GUI Border's size to 960 * 151.
    7. When I play in UNITY, it has 2 drawcall.

    Why not draw 1 call? Why 2 draw call??
     
  37. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704

    Hi jfmoulin,

    Sorry for my late reply. I check the code and i think I miss to mention you also need to call exSpriteEditor.UpdateAtlas before exSpriteUtility.Build( texture ); So the code looks like this:

    Code (csharp):
    1.  
    2. exAtlasDB.ElementInfo elInfo = exAtlasDB.GetElementInfo( exEditorHelper.AssetToGUID(_texture) );
    3. exSpriteEditor.UpdateAtlas( sprite, elInfo );
    4. sprite.Build(_texture);
    5.  
     
  38. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi Seokho,

    It looks like the Unity will increase draw call in different reason. Such as camera distance, the number of mesh batched. I don't know why but we met this problem, too. The draw call will become 2 in no reason. And I can't get it down :(
     
  39. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    I don't see exSpriteEditor anywhere in your documentation and MonoDevelop does not see it too. I looked for UpdateAtlas in other classes and I didn't see it. Is it public API ?
     
  40. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi jfmoulin,

    I just check the source code, though it is a public function, I didn't public the class exSpriteEditor. So this fix will be added in v1.2.3. If you are quite urgent for this, please send me an Email address and your invoice number, I'll send you a daily fix version first.
     
  41. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Hi !

    I started building my own library to deal with 2D in Unity since when I started, solutions like yours were not existing.

    The library I have developed take care of screen resolution, because we're targeting Android phones/tablets, iPhone and iPads, so I have a solution that will place elements in the scene based on a pourcentage of the screen width/height, so it render "the same" in different size screens.

    I want to start and use ex2D, but I'm wondering if there's something like that. I mean, will I be able to just place elements in my scene, and have them display the same way on different screen sizes ?
    For example, if I'm building a 2D game in 480x320, and I place a sprite at the top/left of the screen, will it be at the top/left on a 800x480 device ?

    Thanks ! :)
     
  42. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    Good. When will it be out ? I can wait a week or two. I have other things to take care of. If it will be available for download in a month or more, it would be nice to have a temporary release with this fix before that.

    Thanks !
     
  43. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hello nah0y,

    ex2D provide exViewportPosition and exScreenPosition. The first one use percentage to calculate screen position, the second one use absolute position for that. So with these two component, you can do the jobs above.

    For more details, you can read the documentation here: http://www.ex-dev.com/ex2d/wiki/doku.php?id=manual:2d_screen_coordination_system

    Regards,
    Wu Jie
     
  44. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi jfmoulin,

    I just come back from IGF China, so I may have 1-2 days rest, then start doing the release of ex2D v1.2.2. The new version should be released in 2011.11.18.
     
    Last edited: Nov 15, 2011
  45. jfmoulin

    jfmoulin

    Joined:
    Aug 28, 2009
    Posts:
    13
    All right. I'll wait for the release.

    Thanks a lot !
     
  46. myprabath01

    myprabath01

    Joined:
    Sep 15, 2011
    Posts:
    33
    hi,
    Hi im developing game for iphone and i have to keep my Atlases under 1024 x 1024 resolution. My Main Character contains loads of animations and one atlas(1024 x 1024) is not enough for pack. So If i use 2 Atlases for animate one objet does it cause any problem. or is it possible ?
     
  47. nah0y

    nah0y

    Joined:
    Apr 4, 2011
    Posts:
    74
    Okay thanks! I'll take a look at it :)
     
  48. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi myprabath01,

    ex2D is designed to support multi-atlas animation naturally. So you don't need to worry about it. The only problem is you can't batch character and other things in one atlas which give you less draw call. But since the amount of the data you are using. Saving one to two draw call on this is impossible.
     
  49. shinriyo_twitter

    shinriyo_twitter

    Joined:
    Aug 12, 2011
    Posts:
    328
    Hi jwu

    I'd like to use Map Editor future.
    But I couldn't find menu of ex2d.
    It is not released yet?
     
  50. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi shinriyo,

    The TileMap Editor still under developing. We are currently focus on solving the problem of ex2D work with Source Control and Asset Server.