Search Unity

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

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

  1. d3gator

    d3gator

    Joined:
    May 28, 2009
    Posts:
    23
    thanks, works fine
     
  2. Wild-Factor

    Wild-Factor

    Joined:
    Oct 11, 2010
    Posts:
    607
    ex2D crop the empty Alpha image zone a little too much (sometimes pixel half trasparent), when an atlas is build with it.
     
  3. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Q1

    I need my atlases made by ex2D to be read-enabled. So, after atlas build I need to go to texture settings, set "read/write enable" checkbox and click apply. That would be not a great problem if unity never re-builds atlases. But sometimes (I'm working in a group and using Git subversion system) after merging changes it re-builds all atlases and drops all "read/write enable" checkboxes. And I need to do it again and again.

    So, maybe, the atlas editor should have some "read/write enabled" checkbox too? And when ex2d will build an atlas it will set the corresponding checkbox automatically?

    Q2 Is there possibility (or do you plan it?) to make different font colors/effects in one exSpriteFont field? For example to make possible to print one sentance with the middle word highlighted by the different color?

    Q3 Is there really a problem with unicode symbols? I've made a bitmap font with latin and cyryllic symbols. All english words look ok - like "Hello world", but all russian letters (which use unicode) are followed by a space. So, the text line looks like "П р и в е т" ("H e l l o" in case you can't see rus letters) - every letter is followed by a space.

    Q4 If I buy the pro version - will I receive all updates too?
     
    Last edited: Jun 28, 2012
  4. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I'm currently have a discuss of this issue here, but not it yet. Did anyone have more suggestion on this?
    https://github.com/jwu/ex2D_Runtime/issues/26
     
  5. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Q1: Added in the plan, I'll find a time implement it.
    Q2: Yes, I have for the GUI. Not implement yet. But the implementation is not change the code inside the exSpriteFont, but add another component that will generate different color font object as child of it.
    Q3: It works fine for Chinese character. Would you mind to send me a package with the problem resource and letters ?
    Q4: Yes, you will receive all updates.
     
  6. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    And can you please tell when the Q1/Q2 will be implemented? I'm looking forward for it very much.

    About russian letters bug, here it goes.

    That is how it looks like:
    $rus_bug_ex2d.png


    And here's the project (I've deleted folder "Assets/ex2D" for reason you don't want to be it distributed this way):
    View attachment $exSpriteFontTest.zip
     
    Last edited: Jun 29, 2012
  7. funke

    funke

    Joined:
    Sep 17, 2011
    Posts:
    48
    Hi, I've copied project folder to another computer and it looks like the scales of sprites are all wrong, they are bigger then on the first one. Scale numbers are the same, only collider boxes remained in the correct size. How to fix that or avoid in the future?
     
  8. vfranchi

    vfranchi

    Joined:
    Jun 30, 2012
    Posts:
    1
    I have a problem that I can't find an answer, nor I found anyone with my particular problem.
    When I have any object with a exSoftClip on the scene, and in runtime I need to Destroy it, exSpriteMng keeps trying to using it thus giving me an exception. "... is trying to use 'exSoftClip' but it has been destroyed...", something like that.
    I managed to Destroy exSoftClips objects by first destroying all children from the exSoftClip, updating the clip list of it, and later calling exSpriteMng.DestroyObject(<exSoftClip gameObject>); I don't know if what fixed it, but until now that worked fine.

    The "trick" I've using so far:
    Code (csharp):
    1.  
    2.         if (mSoftClip != null)
    3.         {
    4.             for (int i = 0; i < mSoftClip.transform.childCount; i++)
    5.             {
    6.                 Destroy(mSoftClip.transform.GetChild(i).gameObject);
    7.             }
    8.            
    9.             exSpriteMng.DestroyObject(mSoftClip);
    10.         }
    11.  
    Recently I have yet another object that has exSoftClip and needs to be Destroyed on runtime. But for this object, that "trick" doesn't work.
    Is there any other, maybe correct, way to destroy and exSoftClip object?
    I saw that the exSpriteMng has a AddClipToList method, or something like that, but it doesn't have a RemoveClipFromList, does it?

    Additional Info: I have two camera on my project, apparently the "trick" works when an object is being seen by my Main Camera and not when the object is being seen by my secondary one. I'll run some more tests on that.

    Thanks in advance.
     
  9. johnny_karas

    johnny_karas

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

    The Q1, Q2 will start after September, no release time yet.

    Update:

    I check the project and I think this is the problem of your generated resources. Let's take a look at character '1055'. It have the Xoffset = 5, Xadvance = 49 which obviously width than the ASCII characters. When I change them manually to 0 and 38. The result looks correct as the picture show.

    I suggest you change a font tool to generate the resource without advance and offset.

    Regards,
    Wu
     

    Attached Files:

    Last edited: Jul 2, 2012
  10. johnny_karas

    johnny_karas

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

    Try to rebuild the scene, or try to copoy the project folder by export and import unity-package.

    Regards
     
  11. johnny_karas

    johnny_karas

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

    The exSoftClip have been deprecated in v1.2.6. We develop the exClipping instead of it. It will calculate clipping by shader and can be destroyed at Runtime.

    Just wait for our update. (daily version will come first this week.)

    Regards,
    Wu
     
  12. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I have a problem. I have a 1024x768 sprite in the Atlas to use as the background. Ortho camera set to 384 size. When the sprite is drawn eith exSprite there is a blank single pixel line on the left side and top of the screen. Also the sprite seems to have a slight twist or sheer in it when it's drawn.
     
  13. coldsteel

    coldsteel

    Joined:
    Jul 2, 2012
    Posts:
    4
    I'm building a project using(among other things), ex2D and Lost Zombie Studios' FSM plugin.

    I'm having trouble getting ex2DAnimations to play when I call them from within the code of a given state. I can do other operations like translate fine, so I'm wondering if I have the syntax wrong.

    I don't have the exact code right with me to show you, but could you possible give me an example of how you would access and get an ex2DAnimation to play from within code defined in a state?

    What I'm trying right now roughly looks like

    Code (csharp):
    1. public override OnEnter() {
    2.  
    3. if (!(Parent.getComponent<exSpriteAnimation>().isPlaying("SomeAnimation"))) {
    4. Parent.getComponent<exSpriteAnimation>().Play("SomeAnimation"); }
    5.  
    6. }
    where Parent is the ref to the main FSM script driving the object. When I run this the animation doesn't play at all and the default sprite just stays there, although it seems to pass the conditional and generally run as normal otherwise.
     
  14. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I've tried the orth and projection camera and neither solves my problem of a slight distortion on large sprites. Here is the source image example and the end result in editor and player. Notice the red circled areas for how the image is distorted.
    Also Clipping doesn't seem to allow me to set pixel perfect coordinates so moves the clipping area when the resoloution changes.





    I tried an experiment and extracted your mesh verticies and rounded them down and the distortion went away, but the plane no longer fitted the correct size. Also when you create your own plane in code to do the same as ex2d the distortion doesnt happen.
     
  15. johnny_karas

    johnny_karas

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

    This is very strange, but your information do help me locate the problem. I think I should take your suggestion, and try some round calculation in the mesh generation script. I'll find you later.

    Meanwhile, if you can provide your example package to me that will help a lot!

    Regards,
    Wu
     
  16. johnny_karas

    johnny_karas

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

    Do you put the exSpriteAnimation component and exSprite component together in the same gameobject ?
    If everything find, please send me and example for this problem.
     
  17. coldsteel

    coldsteel

    Joined:
    Jul 2, 2012
    Posts:
    4
    Yes, the gameobject does have both scripts(exSprite/exSpriteAnimation) attached.

    The core script:
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class HakuCore : FSMSystem {
    5.  
    6.    
    7.     //states
    8.     public HakuIdle S_HakuIdle;
    9.     public HakuWBck S_HakuWBck;
    10.     public HakuWFwd S_HakuWFwd;
    11.  
    12.  
    13.     void Awake() {
    14.         AddState(S_HakuIdle);
    15.         S_HakuIdle.Parent = this;
    16.         AddState(S_HakuWBck);
    17.         S_HakuWBck.Parent = this;
    18.         AddState(S_HakuWFwd);
    19.         S_HakuWFwd.Parent = this;
    20.     }
    21.  
    22.    
    23. }
    24.  
    The idle state:

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. [System.Serializable]
    5. public class HakuIdle : FSMState
    6. {
    7.  
    8.     [System.NonSerialized]
    9.     public HakuCore Parent;
    10.     private float move;
    11.  
    12.     public override void OnEnter()
    13.     {
    14.         Debug.Log(string.Format("{0}: Entering", this));
    15.  
    16.         if (!(Parent.GetComponent<exSpriteAnimation>().IsPlaying("HakuIdle")))
    17.         {
    18.             Parent.GetComponent<exSpriteAnimation>().Play("HakuIdle");
    19.         }
    20.  
    21.     }
    22.  
    23.     public override void OnFixedUpdate()
    24.     {
    25.         move = GameObject.Find("InputMng").GetComponent<InputCore>().p1Move;
    26.  
    27.  
    28.         if (move < 0)
    29.         {
    30.             Parent.GoToState(Parent.S_HakuWFwd);
    31.         }
    32.  
    33.         else if (move > 0)
    34.         {
    35.             Parent.GoToState(Parent.S_HakuWBck);
    36.         }
    37.  
    38.     }
    39.  
    40.     public override void OnExit()
    41.     {
    42.         Debug.Log(string.Format("{0}: Exiting", this));
    43.     }
    44.  
    45. }
     
  18. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I have found the cause Wu. When you set the Atlas texture to filtermode Point causes it to shear the texture.

    The problem is I need point mode because the sprites have a line around them otherwise when they are drawn.
    How do I get rid of the line in bilinear mode?
     
    Last edited: Jul 3, 2012
  19. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Sorry for font issue, I didn't have in mind it can be a font utility error.

    About "read/write" checkbox - is there any chance to have a quick hot fix? It is VERY annoying to set "read/write" for all my 5 textures (the number is growing) every time I merge the project with others (every day).

    PS: Thaks a lot for your support! It was said before, but I will say it again - you're the best supporter I have ever seen! ;)
     
  20. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    I am trying to use the sprite clipper but I can't get it to be pixel perfect the same as the sprite. How do I make the clipper resoloution independent and pixel perfect?
     
  21. johnny_karas

    johnny_karas

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

    I see nothing wrong in your code. Would you mind to play the sprite animation in a simple game object see if it works first ? And in anytime you can send me an E-Mail including the error package. I can help you find out the problem.

    Regards,
    Wu
     
  22. johnny_karas

    johnny_karas

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

    I recently find the solution on this, which is texture bleeding, so I will do one more pixel when generate sprite in atlas so bilinear filter will read the pixel and tile them without black line.
     
  23. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Thanks man :)

    I see what I can do this week for the checkbox. Because I'm busy in preparing the v1.2.6 as you can see here: http://www.ex-dev.com/ex2d/wiki/doku.php?id=misc:change_log

    The changes of the clipping system make me hard to send a daily-fix version for user (Some one still use soft-clip, but it is been removed from v1.2.6, instead we have exClipping a shader clipping solution). Also a GUI solution is prepared for publish.

    I'll try as fast as I can to make all this works in this week. Hope you can understand.

    Regards,
    Wu
     
  24. johnny_karas

    johnny_karas

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

    We've already deprecated exSoftClip in v1.2.6, and use exClipping replace it. The exClipping is a shader clip solution which will solve your problem. The v1.2.6 probably available this week. Daily fix version will send first.

    Regards,
    Wu
     
  25. arkon

    arkon

    Joined:
    Jun 27, 2011
    Posts:
    1,122
    Ok I'm confused as to how to get ex2d to work correctly on different screen resoloutions. I have all my graphics sized and positioned to fit on a 1024 x 768 screen and it all looks fine. When I change the player output to 960 x 640 a section of graphics on the right had side and bottom are now missing. It's like ex2d keeps the graphics exactly the same resoloution and doesn't scale them to fit the new screen size.

    How do I overcome this?
     
  26. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Wu Jie, great! I'll be waiting for "read/write enabled" solution. A pair of weeks is not a problem. Waiting till september will be a problem, though! :)

    Thanks again.
     
  27. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Maybe my post will be helpfull for others who get the similar issues. I think almost everybody who use scaling or not pixel-perfect graphics will have the similar problems.

    So, I think my post can be like a FAQ.

    Issue description: When scaling or moving not pixel-perfect graphics some artifact appear at the edges of a sprite (or edges of transparent areas).

    Explanation. To explain why it happens you should know how video card makes scaling. Imagine you picture has two layers - one is colors (RGB) layer and other is alpha (transparency) layer. If your sprite has areas where totally non-transparent pixels are neighboured by totally transparent ones, you'll get this bug (the edges of a sprite in atlas will work too because sprites are padded with transparent areas).

    So, what you should know is that even transparent areas of a picture have color. That color is invisible, but is still there. The color of totally transparent pixel can by any (depends on saving software/alghorythm).

    Lets assume we have such an image:



    And lets assume it has following color/alpha channels:



    So, you see - pixels around our image (blue square) are while, but totally transparent. They are invisible to users and because of that - it is no matter than they are white.

    But what happens when you scale this picture (lets assume we scale down by 80%, but its not really matter what scaling is done).

    The scaling on videocard is very simple and it made by separately scaling color and alpha channels.



    So, you see? The blue pixels were mixed with white pixels that were around and new color (light blue) appeared. When you scaling transparent image in Photoshop, it weightens pixels by their tranparency. Video card does not. That is why the artifacts on the edges appear.

    Solution. The solution is simple - you always need to be sure your image is surrounded by transparent pixels with color that is similar to the edge ones.

    How to achieve that?

    The easiest way I've found is before exporing PNG from Photoshop - to make a second layer under the existing one, blur it and apply 1% transparency. That layer will be invisible to the eye, but will enshure that transparent pixels around the image will have correct colors.

    And you should never have your sprite stucked to the edge of the image. Always leave a blank area.

    I hope this post will help somebody.
     
    Last edited: Jul 4, 2012
  28. johnny_karas

    johnny_karas

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

    Sure ex2D won't do scale. And it is not the part of ex2D should do. If you want your App scale in size. I only know the Retina Display won't let your scale double size of your iOS3 app or something. So the way to solve the problem is make a new batch of resources that fit your iOS4 resolution. More discuss about how to design a game fit the multi-resolution can be found in iOS game development forum. As far as I know you only have these ways:

    * Make your game in each platform with different resolution of resources
    * Choose a large background and define a regular game view in it for your iPad 1/2/3 game, then the iPhone4 device will fit it by cut out those out of range pixel.
    * Make your game build in iPhone3/3GS, and they will provide 2x button in iPad device.
     
  29. JKL

    JKL

    Joined:
    Apr 19, 2012
    Posts:
    4
    Hi, how do I copy the texture altas and animations from one computer to another?
    My friend and I each have a local copy of the same project. He added more sprites to his copy of the atlas and created a new animation. I copied the new and modified files to my computer. When I open Unity, the atlas doesn't display the new sprites and the animation is blank. I tried reimport, sync, rebuild, but didn't work. I don't know what the sequence of actions I need to take.

    These are the files that I copied over:
    _ex2D_AtlasDB.asset, _ex2D_SpriteAnimationDB.asset
    AtlasEditorInfo.asset, Atlas.asset, Atlas, Atlas.png
    new sprite images
    new animation file
     
  30. Niokizou

    Niokizou

    Joined:
    Jul 3, 2012
    Posts:
    3
    Hello, I am a beginner but I haven't found how to know the name of the animation currently played by the sprite.

    I want to test something like
    if (currentAnim = "myAnim")
    debug.Log("test");

    Thanks in advance ! ;)
     
  31. JKL

    JKL

    Joined:
    Apr 19, 2012
    Posts:
    4
    I tried this and it gives me the name of the current animation clip.

    exSpriteAnimation spAnim;
    spAnim.Play("your_animation_clip");
    Debug.Log(spAnim.GetCurrentAnimation().name);
     
  32. GrandMasterHsu

    GrandMasterHsu

    Joined:
    Jul 5, 2012
    Posts:
    50
    hi, i'm currently using ex2d for the font and i'd like to access the Text property to display scores

    i've tried something like this but ended up having errors, did i go about it the wrong way? how can i access the text property via code?
     
  33. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704

    Hello JKL,

    You should use some VCS tool for your project since you have multiple people working on the same project. I recommend Git. If you don't know how to set it up, please read this document http://docs.unity3d.com/Documentation/Manual/ExternalVersionControlSystemSupport.html

    Other wise, you have to export your works through unitypackage.
     
  34. johnny_karas

    johnny_karas

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

    Just do

    Code (csharp):
    1.  
    2. if ( spAnim.IsPlaying("myAnim") )
    3. {
    4.     ...
    5. }
    6.  
     
  35. johnny_karas

    johnny_karas

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

    Based on your code, I can see ScoreFont has no type. And exspriteSCORE do the thing, the code should looks like this:

    Code (csharp):
    1.  
    2. private exSpriteFont exspriteTIMER;
    3. private exSpriteFont exspriteSCORE;
    4.  
    5. void Start(){
    6. exspriteSCORE = ScoreFont.GetComponent<exSpriteFont>();
    7. exspriteTIMER = TimerFont.GetComponent<exSpriteFont>();
    8. }
    9.  
    10. void Update(){
    11. exspriteSCORE .text = ScoreConvert();
    12. }
    13.  
    14. private string ScoreConvert(){
    15. string temp = null;
    16. temp = "" + score;
    17. return temp;
    18. }
    19.  
     
  36. gerasim13

    gerasim13

    Joined:
    Jun 6, 2012
    Posts:
    3
    Hello Wu Jie. First of all thank you for your work.
    I know that current version of ex2d did not support custom shapes of physics body, but how to create sprite with pixel perfect collision? Maybe you could point me to right direction and give me couple advices? Should i start with creating the new component or maybe modifying ex2d runtime source?
     
  37. johnny_karas

    johnny_karas

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

    If you wish to do pixel collision, you may be wish to do separate them in two phases. The first phase is use box/mesh collision to test the collided targets. In the second phase, you can pick up the pixels by textures.GetPixel() function and test if it is transparent and overlap with other objects.

    In the latest daily build (1.2.6 120706) I've add the Set Read/Write Enable in atlas build tool.

    Regards,
    Wu
     
  38. JKL

    JKL

    Joined:
    Apr 19, 2012
    Posts:
    4
    I'm trying to use the layer manager to organize the draw order of the sprites. I noticed that the layer manager script is changing the z index of the game objects. The problem is that I have physics and collision detection on these game objects and they are not colliding anymore because they are not on the same z axis. How should I solve this?
     
  39. johnny_karas

    johnny_karas

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

    you can solve this by put those collision in a single gameobject and become child of the sprite. Attach some respond script on them and handle things by reference parent.

    You also can consider add those collision box into layer manager and set the layer as abstract. If this setting, the collision box will only occupy the layer, but their child will share the same z.

    Regards,
    Wu
     
  40. MihaPro

    MihaPro

    Joined:
    Dec 23, 2010
    Posts:
    13
  41. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    I've see the problem, and try to fix it. This bug only happen in Editor, so it will not crash when you build the game. I'll try to fix it asap.
     
  42. H-Kuribara

    H-Kuribara

    Joined:
    Jul 14, 2012
    Posts:
    5
    Hi , Wu Jie.

    Ex2D's Sprite font is quite useful for multi-byte language region because of Unity's font doesn't suport this language.

    So I recognize the region often require to replace font sheets because of reducing font char and modifying scenario.
    Then we replace font sheet and recreate ex2dBitMapFont asset.
    But existence spritefont's "font info" property has been missing even though overwriting ex2dBitMapFont.
    I reassgin by editor script but really want assigning recreated fonts automatically.

    Thanks.
     
  43. johnny_karas

    johnny_karas

    Joined:
    Sep 20, 2010
    Posts:
    704
    Hi H.Kuribara,

    I'll check the problem and see if can be fixed.
     
  44. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Hi, Wu Jie!

    I'd like to stop using evaluation copy and purchase an indie version. But I need 1.2.6 features. Do you have a stable build you can send me?

    If no, then when 1.2.6 will be released?
     
  45. johnny_karas

    johnny_karas

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

    If you purchase the product and subscribe the newsletter, you will receive our daily build E-Mails. You can always ask me through E-Mail for a latest daily build.

    Regards,
    Wu
     
  46. Dragonhill

    Dragonhill

    Joined:
    Jun 2, 2010
    Posts:
    22
    My team is in the same boat with 36+ levels. I'm pretty fast at rebuilding, takes about 8 seconds per level. but still..seams to happen twice a day here.

    ~D
     
  47. johnny_karas

    johnny_karas

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

    I've add an "rebuild sprite in the scene" menu button in v1.2.6, if you select all scenes and right click the mouse you will see it in the ex2D/ column. I hope this can temporarily solve your problem. The way to completely solve it is re-design some of the structure and working pipeline which is what I am trying to develop in ex2D v2.0. Before the version comes out, there's no simple way for this, hope you can understand.

    Regards,
    Wu
     
  48. coldsteel

    coldsteel

    Joined:
    Jul 2, 2012
    Posts:
    4
    Could I ask for some example as to how to use your FSM script(s), Wu Jie? I want to see if the issue I'm having has to do with how I'm managing structures.
     
  49. soulburner

    soulburner

    Joined:
    Mar 25, 2012
    Posts:
    169
    Is it possible to make exSpriteFont to automatically wrap lines (limit its width)?

    I didn't find the implementation in your engine.

    If it isn't implemented, please, give me a hint how to do that? F.e. how do I count the width of a particular letter? I suppose there's an internal function for that.
     
  50. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    I searched for a while how to wrap text and here is what I came up with.
    I'm a terrible coder BUT this code works for me, and maybe someone will be able to help make this better?
    Create a javascript file and attach to gameobject with the exspritefont component....

    Code (csharp):
    1. #pragma strict
    2. import System.Collections.Generic; //for the generic array
    3.  
    4. //MAKE SURE ExSpriteFont Has WordWrap Clicked!
    5. //attach to same gameObject as exSpriteFont you want to wrap!
    6. var wrappedtext : String = "";
    7. var wraplength : int = 18; //set wraplength in inspector or through code
    8. var txtarray : List.<String> = new List.<String>();  
    9.  
    10. function Wraptxt(inputtext : String) {
    11.     if (inputtext == "clear") {
    12.         GetComponent(exSpriteFont).text = "";
    13.     }
    14.     else {
    15.         var i : int = 0;
    16.         txtarray.AddRange(inputtext.Split(" "[0])); //split the string by "space"
    17.         var txtarraylength : int = txtarray.Count; //size of the array is size of array - 1 (not sure why);
    18.         var temptextlength : int;
    19.         var temptextsub : int = 0; //store something here to subtract from wrapptext.length after each line break to effectively reset counter
    20.        
    21.        
    22.         for (i = 0; i<txtarraylength; i++) {
    23.            
    24.             wrappedtext += (txtarray[i] + " ");
    25.             temptextlength = (wrappedtext.Length - temptextsub);
    26.            
    27.             if (temptextlength >= wraplength) {
    28.                 temptextsub += (wraplength + 2); //2 above length to account for the 2 chars \n
    29.                 wrappedtext += "\n"; //add line break
    30.             }
    31.         }
    32.        
    33.         GetComponent(exSpriteFont).text = wrappedtext; //print the text to exSpriteFont this script is attached to.
    34.        
    35.         inputtext = "";  //clear all the variables and array
    36.         txtarraylength = 0;
    37.         txtarray.Clear();
    38.         wrappedtext = "";
    39.  
    40.     }
    41.    
    42.    
    43. }