Search Unity

  1. Check out our Unite Austin 2017 YouTube playlist to catch up on what you missed. More videos coming soon.
    Dismiss Notice
  2. Unity 2017.2 is now released.
    Dismiss Notice
  3. The Unity Gear Store is here to help you look great at your next meetup, user group or conference. With all new Unity apparel, stickers and more!
    Dismiss Notice
  4. Introducing the Unity Essentials Packs! Find out more.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice
  6. Unity 2017.3 beta is now available for download.
    Dismiss Notice

Pixel-Perfect Dynamic Text - Support Thread

Discussion in 'Assets and Asset Store' started by tonic, Feb 16, 2014.

  1. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Pixel-Perfect Dynamic Text for Unity.

    LINK TO ASSET WEBSITE: Pixel-Perfect Dynamic Text website.
    Also a "Lorem Ipsum"-demo version is available if you want to try the asset in Unity.


    The Pixel-Perfect Dynamic Text component is used for displaying pixel-perfect camera-facing text. The size and position are defined in world units. If compared to Unity's built-in text components, Pixel-Perfect Dynamic Text is sharp like built-in GUIText, but part of the scene like TextMesh.

    What features does Pixel-Perfect Dynamic Text have?

    Most of the listed features are demonstrated in the interactive demo which also comes with the package as an example scene.

    Text size is proportional to world units, and not dependent on screen size in pixels or dpi resolution.
    • For example, if you use an orthogonal camera in Unity with Size=5, it means the total height of window is 10 units. Pixel-Perfect Dynamic Text with unit size of 2.0 will mean one row takes vertically 20% of screen so that there will be space for 5 rows of text.
    For maximum sharpness, pixel size for text font rendering is dynamically selected to be the nearest matching size for text world unit size.
    • For example, suppose your window height is 512 pixels and you have a camera like in the previous example. If you make a text with size 1.0, the row height will be 1 unit, corresponding to 51.2 pixels. The font will be rendered sharp with pixel size of 51.
    Pixel-Perfect Dynamic Text component also works with both orthogonal and perspective cameras.
    • For perspective cameras, it measures distance from text object to the camera plane. With the power of trigonometry it figures out what is the correct pixel size for the text (with its current position and size, measured in world units).
    • This is done separately for each different piece of text with varying distances.
    You can choose if text is pixel snapped to keep it sharp when it moves on screen.
    • With pixel snapping enabled, sub-pixel position of transform.position will be snapped to nearest pixel (of currently used screen resolution).
    The Pixel-Perfect Dynamic Text component uses Unity's internal font renderer and atlasing.
    • So you can use same fonts what you can use with the built-in Text Mesh or GUI Text — use custom truetype fonts.
    • Regular Font Styles are supported: normal, bold, italic, bold and italic.
    • Change color dynamically.
    • Standard built-in font material shader is used. No need for custom heavy-weight shaders.
    • Note: There's no support for Rich Text with html-like syntax (for now, at least).
    Text can be aligned and anchored, similar to how Unity's built-in Text Mesh (3D Text) works.
    • Text can be left-, center- or right-aligned.
    • Horizontally text can be left-, center- or right-anchored.
    • Vertically text can be upper-, middle-, lower- or baseline-anchored. Pixel-Perfect Dynamic Text defaults to baseline anchoring for easier working with text (baseline anchor is not featured by built-in Text Mesh).
    You can ask for font metrics and use tabs for alignment.
    • The component has baseline, ascent and descent properties.
    • You can also get size of the whole text (bounds of the generated mesh).
    • Tab size is defined in world units and tab char in text moves to the next tab stop.
    The component contains many small tweaks to make it better.
    • Mesh is regenerated/reallocated only when necessary. E.g. when there's longer text than previous frame, or if text properties change (size, style, anchor, alignment, ...). Previous mesh arrays are reused when possible.
    • Pixel-Perfect Dynamic Text is compatible with dynamic batching. It can even combine with built-in text meshes as same font material and texture can be used with both.
    • You can update text dynamically, even every frame. See the last screen (10/10) of interactive demo. It has a "text mode" effect consisting of over 2000 characters updated every frame.
    • Aware of different texel sampling between graphics APIs, and adjusts as needed to keep your text sharp.
    • Automatically converts replaces existing Text Mesh objects if you add a new Pixel-Perfect Dynamic Text component to them.
    No native code small footprint.
    • Works with Desktop, Mobile, Webplayer and WebGL platforms.
      (probably with consoles as well, but we haven't tried)
    • Supplied as only a small DLL with the component and with bit of C# source for editor extension.
    • Works with the Free and Pro versions of Unity 2017, Unity 5 and Unity 4.2-4.7!
    Pixel-Perfect Dynamic Text works also with the new Unity 2D.
    • The default font material shader seems to render using the Default Sorting Layer with Order 0. So, to make sprites render behind text, you can make a new Sorting Layer and drag it to be before Default. Or you can use Default Layer for your sprite but set the Order in Layer to negative value. And, of course, in similar way to force sprites render front of text.
    NOTE: Tight integration with new Unity GUI or other 3rd GUI libraries is not officially supported, as the new Unity GUI has roughly equivalent text functionality itself.

    Check out more info and interactive demo in the Pixel-Perfect Dynamic Text website.

    In addition to featuring the interactive demo, the website shows you a few examples what can often go wrong when you work with UI and text layouts between different screens. Also a few trade-offs and caveats are listed, and there's a separate section for Questions and Answers.
     
    Last edited: Jun 25, 2017
  2. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
  3. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    New version has been submitted for review.

    Latest changes:

    // 2014-03-09, 1.0.2 - Added support for using a StringBuilder (textSB field).
    // 2014-03-04, 1.0.1 - Fixed an unnecessary allocation when reusing mesh arrays.

    So, essentially no more issues with GC (garbage collection)!
     
  4. SmashedAvocado

    SmashedAvocado

    Joined:
    Dec 19, 2013
    Posts:
    32
    I'm really enjoying this plugin. It makes the text nice and crisp!

    I know this might be a bit out of scope for the project, but it would be great if you could add some features to make this more of a general text solution.

    Things like:
    * word wrapping
    * getting the position of a character or the exact width/height of the textbox (which seems to be incorrect/strange when I try to get it).
    * Richtext (which you mentioned in the description)

    Either way - great extension!
     
  5. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi AndySum, great to hear you like Dynamic Text!

    Can you elaborate on the problem you have with getting width/height of the text? You can test viewing of the current bounds in the editor by adding a Box Collider component (Component->Physics->Box Collider), and that shows the bounds are a tight fit for the generated text mesh. (Note that if you change the text and still have the box collider, you have to manually Reset the box collider to update it.)

    There's no any special code for the measurement. That is, the bounds returned by Dynamic Text is the same thing you get if you ask for bounds from the Mesh Filter.

    I'd also like to have both of these, so they're definitely feature candidates for future versions.
     
  6. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Last edited: Feb 25, 2017
  7. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,534
    performance on mobile? and no source?
     
  8. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    It works on mobile as well. There may be hickups in framerate when Unity's font system needs to render new glyphs to the font atlas texture, but as long as the text size isn't changing every frame, that shouldn't matter (no need to regenerate anything in those frames). The pixel snapping is checked for on each OnUpdate() and the transform.position is snapped if it's different from last frame (assuming the snapping is enabled). Source code isn't included (component is in a dll file). Source code for the example scene is included of course.
     
  9. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,534
    No source = no sale, unfortunately.
     
    GCat likes this.
  10. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    I may consider including source for the component itself at some point in the future. But for now it's in dll form.
     
  11. VHornet

    VHornet

    Joined:
    Jul 10, 2012
    Posts:
    45
    Anyone try this with NGUI? Will it work?
     
  12. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Unfortunately I don't know how well Dynamic Text integrates with any of the UI packages like NGUI or Daikon Forge.

    If you happen to have some UI which is built using Text Mesh then Dynamic Text should be quite easy to use as a replacement. (except if you need rich text)
     
  13. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Now the Dynamic Text home page has a "Lorem Ipsum"-demo version available for evaluation inside the Unity editor.

    In the demo version your own text is not shown, but instead replaced with characters from the well known lorem ipsum text.
     
  14. Flyclops

    Flyclops

    Joined:
    Apr 19, 2013
    Posts:
    10
    Hi Tonic,

    This is a fantastic plugin. We have been using NGUI just for text because they were the only solution that gave us everything we needed. But NGUI's rendering is very slow. Any animations involving text are very clunky. DynamicText is going to allow us to rip out NGUI altogether while still keeping draw calls low, and giving us most of the features we need. So thanks!

    It is missing some of the bells and whistles of NGUI, like text wrapping and shrink to fit, but those would be easy to write ourselves if you added one feature: a method to get the size of a string of text in a given font and font size. Is this logic you already have in your class? If so, any possibility of exposing this publicly? Either that, or making the plugin open source?

    Thanks
     
  15. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Thank you for the kind words!

    The text wrapping etc. are things which I'm planning to add at some point, but I understand wanting to implement them yourselves if you need them urgently.

    Currently you can get the generated text size by reading the DynamicText.bounds property (don't read the bounds from mesh filter mesh). But note that due to few reasons, the mesh generation is deferred (it's generated in the next Update, or in case of default Arial font, one additional frame to fix an on-device rarely occurring issue). So e.g. in Start() the bounds will still be zero-sized. This is a bit unfortunate, maybe I need to revisit this and see if I can make it work better in the future.

    Using the size properly has come up a few times with other users as well, so I actually just made an example how to dynamically create dynamic text objects from array of prefabs, and how to align them after each other when the bounds are available. Here's link to the example: http://strobotnik.com/temp/DT_aligned_text_array.unitypackage
    (be sure to import the DynamicText package first)


    If you more exactly want to know the size of text before actually creating one, unfortunately there's no way to do that right now. I'm slightly reluctant to add it, since that method would need to do the full work similar to actually creating a text. That is, ask for Unity to add the glyphs in the asked size to the atlas texture (and if the atlas is full, this can potentially lead to flush of it and recreation of all other texts, so it is sometimes very slow). And after that a mesh would need to be generated, and only then the requested size of the text can be known.

    To give an exact result, there is no shortcut for that. The text sizes can vary a bit depending on the font size and if hinting is used or not, and the exact sizes can be queried from the Unity font system only after the glyphs are actually added to the atlas. While I agree that asking for potential size is an important feature one would really want to have, in this case it'd also be very good if one could design the system not to need that. Otherwise some perhaps unnecessary queries can "pollute" the font atlas leading to a flush more often which would end up in worse performance.

    That being said, I think there is a hackish workaround to do that now: you could just create a text with the wanted size but hide the mesh renderer, and then check how big the text ends up being.

    All this might be possible to implement better if we'd have detailed access to font metrics through the Unity Font class. If somebody from Unity reads this, please expand the API... ;)
     
  16. peterfrog

    peterfrog

    Joined:
    Dec 13, 2013
    Posts:
    9
    Hi Tonic,

    I bought a few days ago. I am very satisfied. but one thing missed.

    Custom Soring Layer is impossible? I'm really really need that.

    Thanks.
     
  17. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Ok, I looked around a bit. If you are trying to sort the text with sprites, and order the text to different order number than 0, try adding this component (SetSordingOrder.cs):

    Code (csharp):
    1.  
    2. using UnityEngine;
    3.  
    4. [ExecuteInEditMode]
    5. public class SetSortingOrder : MonoBehaviour
    6. {
    7.     public int sortingOrder;
    8.  
    9.     void Update()
    10.     {
    11.         renderer.sortingOrder = sortingOrder;
    12.     }
    13. }
    14.  
    Hope this helps. I'm not sure if this is exactly what you were after.
     
  18. peterfrog

    peterfrog

    Joined:
    Dec 13, 2013
    Posts:
    9
  19. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    740
    This looks terrific. I have a question if you wouldn't mind.

    Is it possible to recognize each letter in a dynamic text string, and if generated in a scene, (for example, the work "cat"), Instantiate a specific prefab/gameObject based on each letter? So for example, there are 26 letters. If I had 26 prefabs, could I reference which letters were in a dynamic string and spawn the assigned prefabs at spawn points in the scene? Image a 3d landscape.

    I hope that made sense. Thanks.

    B.
     
  20. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Sure that's possible. But that kind of thing is really out of the scope of this Dynamic Text asset. You probably should post your question to some more generic area of the forum.
     
  21. ZJP

    ZJP

    Joined:
    Jan 22, 2010
    Posts:
    2,617
    So, with your tool i can use any standard shader (Outline, Glow etc..) i want (with less or few draws call)?
     
  22. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    You can replace the material with something else you want to use, e.g. for special effects. However, currently Dynamic Text component has a convenience feature which sets the "correct" font material when generating mesh. And the mesh generation can be deferred a frame or two. So it is marginally tricky to replace with your own material -- the easiest way if you just force the new material with script code in Update() call. I'll probably make it easier to use custom material in a future update...

    About draw calls: Dynamic Text doesn't do anything special regarding draw calls. It creates a single mesh for each object, and relies on Unity's own dynamic batching to reduce draw calls. If you have a different shader, that will naturally need at least one more draw call for each shader.
     
  23. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    740
    thanks.. the scenario was more for context. Just curious if individual letters in your strings were accessible via script.
     
  24. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Ah, ok, I see. No they aren't.
     
  25. outtoplay

    outtoplay

    Joined:
    Apr 29, 2009
    Posts:
    740
    Errr, so now I'm confused. In the first post you said, "sure, that's possible", and above you said "no, they aren't". Could you clarify?
     
  26. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Oh, sorry for managing to be so confusing.

    When I said "sure that's possible", it is because I mistook your question to be too generic... so I answered with the mindset if it is possible at all with Unity (and tried to redirect you to some other forum area).

    But, to clarify an answer your question, no there is no access to individual character meshes or positions in Dynamic Text.

    There is one "big" mesh generated to be part of the mesh filter. And note that the character positions themselves are not static -- their XY positions do move around sometimes, when the actual text pixel size changes so that the text mesh needs to be updated. (This happens e.g. if resolution changes when switching between portrait/landscape mode, or if you use perspective camera and move the text in Z.)
     
  27. peterfrog

    peterfrog

    Joined:
    Dec 13, 2013
    Posts:
    9
    Hi,

    1 or 2 ... Which is correct? What is different between?
     
  28. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Both are OK - there isn't much difference. But I can still explain the subtle details.

    The thing is that in the initial version there was only the dt.text (public string, also visible in inspector). Afterwards support for the string builder (textSB) was added, where you can build a composite string without having to create a temporary string object, and then finally call dt.FinishedTextSB() to signal that it's now ready.

    However, if you use textSB, the plain dt.text string is not updated so that no extra string objects will be leaked(except if you run in editor, it will be periodically updated for debugging purposes so that you can see the contents in the inspector). For convenience, there is dt.GetText() which simply converts the textSB to a string and returns it - and for parity there is also SetText, which takes a single string. Using SetText will internally clear the textSB, append the string there, and then call FinishedTextSB(). If you don't use SetText, and instead just put a new string to the dt.text field, then in Update() the change will be noticed and internally SetText(text) will be called.
     
  29. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    254
    Can I specify width of text in in Gui space (0,1) ? I am okay with using orthographic camera coordinates.

    Say my initial text font is 20 for "Hello". Now I've changed the text to "Hello Hello", I want font size to be reduced to keep the same MaxWidth. I don't want font size to become too small that it is unreadable. So, If text value become "Hello Super long Super long Super long Super long " Does it auto-wrap the text or truncate it?
     
  30. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Sorry, there's no width limiting features currently (word-wrapping, auto-shrinking or truncating). I might add some in the future though, e.g. word-wrapping.
     
  31. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Great news -- version 1.0.3 has just been submitted to the Asset Store. There is many small subtle bugfixes and improvements. Although there isn't many new features, in terms of overall performance and robustness 1.0.3 is a big and noteworthy update.

    While you wait for the update to go through review process, you can already check out the updated interactive web player demo.

    PS. Don't forget to check out this new useful thing: Internet Reachability Verifier.
     
  32. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi all, version 1.0.3 update is now available!

    It has overall better performance and robustness, and it contains many small fixes.

    One clear API change is that the direct access to "dynamicText.text" is gone. Now, in script code, the recommended way is to use the textSB string builder to change text content and call FinishedTextSB() when you're done. If you rather use strings then there is SetText() and GetText() methods for that. This needs some updating in scripts but this change helped to make this much better, so that mostly there is not anymore need to defer the mesh updating to next Update() call. The GenerateMesh() will be automatically called by FinishedTextSB() or GetText().

    List of changes (pasted from version history):
    // 2014-07-04, 1.0.3 - Overall better performance and robustness. Fixed
    problem when internal sampling setting might be out of sync until toggling
    "Use Direct3D 11" in Player Settings. Metrics are now updated when
    switching font (fixes incorrect change in position). New "Auto Set Font
    Material" checkbox to control overwriting renderer.sharedMaterial. Added
    example of how to dynamically create DT prefabs aligned after each other.
    Default font is now automatically set when creating a new dynamic text
    object from code and leaving font as null (worked previously only in
    editor like this). Added custom inspector which indicates more clearly if
    camera or font reference is missing. Fix for changing text from script
    code in Start(). Removed need for deferred mesh generation (must have
    proper camera & font). Direct text string access replaced with SetText
    and GetText methods. Fixes for Windows Store and Windows Phone 8 support.
     
  33. jfiola

    jfiola

    Joined:
    May 24, 2013
    Posts:
    2
    Hi Tonic,

    I've been using your plugin ( which is awesome !) in a recent project (http://www.cmegroup.com/education/4-h-risk-ranch.html all text in the game is displayed with your plugin) and I've just upgraded it to the new 1.0.3 version, but I have stumble into an issue. Just to give some background information, I am using Unity 4.3 and my scripts are written in UnityScripts.

    In the previous version, I was directly modifying texts trough "dynamicText.text" and I have updated my code to use SetText() instead. The problem is that I have scripts calling this method in the Start() functions and the text is not being modified this way, while it was working fine with the old dynamicText.text statement called in Start().

    I have found a work around that is to put a yield; statement in the Start() before calling SetText(). This way the text is correctly modified

    Here's a sample of my code.

    Code (JavaScript):
    1. private var GMGameobjectRef:GameObject;
    2. private var GMRef:scr_GameManager;
    3. public var scoreUIText:DynamicText;
    4.  
    5. function Start () {
    6.  
    7.     GMGameobjectRef = GameObject.FindGameObjectWithTag ("Game Manager");
    8.     GMRef = GMGameobjectRef.GetComponent("scr_GameManager");
    9.  
    10.     currentScore = GMRef.GetScore();
    11.  
    12.     yield;//scoreUIText will not be modified in runtime without yielding Start().
    13.     scoreUIText.SetText(currentScore.ToString());
    14. }
    The same behavior happen when using TextSB.

    I don't know if this is really a bug and this is just how the plugin works (updating the text dynamically with Update()), but I have not found any information related to that in your documentation or on this forum, so I wanted to let you know and other peoples updating the plugin about this behavior.

    Best,
    Jonathan
     
  34. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi Jonathan (@jfiola). Thanks for the report & hint how you solved your issue.

    This is one of the issues I worked to improve with 1.0.3, but it seems it isn't perfect yet.

    I think the problem here is actually about the script execution order. Now I think it should work properly if you define the script execution order in Edit->Project Settings->Script Execution Order, so that DynamicText comes before your own scripts. I just tested with a script like that and for me this fixes the issue. But, I think your solution is fine as well, so feel free to use the "yield;" way above.

    (Earlier versions were subject to this same thing... but e.g. for bounds the only way was to wait until Update cycle - now it should work as long as the order is good.)
     
  35. jfiola

    jfiola

    Joined:
    May 24, 2013
    Posts:
    2
    I can confirm that your solution worked on my side also. I've simply defined DynamicText to execute before the default time and voilà!

    Thanks and keep up the good work!
     
  36. dizzywhip

    dizzywhip

    Joined:
    Mar 17, 2014
    Posts:
    6
    Hey @tonic! I just found this plugin and it looks really great. I'm currently using the TextFX plugin to achieve various text-related effects. I don't know how much trouble it is for you to investigate this, but do you know if it would be possible to use DynamicText in conjunction with TextFX? I suspect it would require support from the author of TextFX (or maybe I could add it myself since it's open-source), but any insight from your point of view would be appreciated.
     
  37. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    @dizzywhip, sorry but I'm pretty sure there's no easy way to make TextFX work with Dynamic Text. It seems to use pre-built bitmap font atlases, while Dynamic Text actually internally uses the Unity's Font system meaning it renders the needed glyphs in needed sizes to font atlas texture run-time.
     
    dizzywhip likes this.
  38. dizzywhip

    dizzywhip

    Joined:
    Mar 17, 2014
    Posts:
    6
    No worries, thanks for checking it out, I really appreciate it!
     
  39. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    v1.0.4 has been submitted, with a bugfix and a new feature: letter spacing.
     
  40. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    ...and it blazed right through so the v1.0.4 is already available.
     
  41. Ippokratis

    Ippokratis

    Joined:
    Oct 13, 2008
    Posts:
    1,452
    Nice plugin, worth the money.
     
  42. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
  43. baneand

    baneand

    Joined:
    Dec 3, 2013
    Posts:
    6
    Hello, does your plugin work with custom, textured fonts? I have made a custom font which is basically a textured font. When I try to add it to dynamic text plugin it gives me errors "Font size and style overrides are only supported for dynamic fonts."
     
  44. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi @baneand. This asset is meant to be used only with fonts set to be "dynamic".

    The font needs to be dynamic because the actual final pixel size is only determined run-time, based on several affecting facotrs like actual screen resolution, camera type / position, requested text size (in world coordinate scale)... These can also be changed on-the-fly in which case text will need to be re-rendered with a different pixel size.

    So under the hood Dynamic Text requests Unity to render the given font in different pixel sizes based on what's needed at that time. Since the font is not set to be dynamic, that error message is actually given by Unity.

    Since getting pixel-perfect world-space text with a dynamic font is the "core feature" of this asset, there are tradeoffs like no support for custom-drawn fonts. There are plenty of other assets which provide some kind of support for custom-drawn bitmap fonts like that.

    That being said, it is possible to use a custom material with Dynamic Text. This custom material could add an additional texture mask, for example. This way it might be possible to get just what you wanted. If you try this, remember to uncheck the box "Auto Set Font Material". (There is no ready-made example for that kind of custom material, sorry for that. It'd be a nice addition, perhaps for some future update.)
     
  45. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    87
    Hi Tonic - nice work. I've been evaluating the Lorem Ipsum demo. Is there an API reference for DynamicText?
     
  46. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi @benthroop, please check out the included "Instructions_DynamicTextForUnity.pdf".

    There's no separate API doc, as there's not that much extra available via scripting than what you already see in the inspector. But that document has a chapter called "Fields and Methods of the Dynamic Text component explained". There's a table which lists what fields and methods you can access (and what name they have in inspector if shown).
     
  47. dizzlebomb

    dizzlebomb

    Joined:
    Sep 21, 2009
    Posts:
    9
    Hey Tonic, I just wanted to verify that it is a known issue that the Lorum Ipsum demo DOES NOT compile for iOS, but hoping the full version does? Let us know about the full version's iOS support. Thanks--
     
  48. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi @dizzlebomb, indeed the lorem ipsum demo version is built a bit differently, and not all platforms work with it (I should be more clear about this). Full version should work on iOS as well - at least I've been testing on it as well. :)
    (the demo is also actually a slightly older version and the asset store has latest version with some fixes; should try to remember update the demo as well next time I'm releasing a new version). Sorry for the confusion!
     
  49. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    87
    So, @dizzlebomb and I are working together and we purchased the asset. Nice stuff so far. Thanks for writing it. I have a few questions:

    - Why does the text disappear in some cases when approaching the edge of the screen? Is this a bug or expected behavior?
    - What' the best way to shut off the dynamic text reatlasing? Just set the min and max values to the same?
    - Would you consider a "mode" that doesn't rely on a camera? That would be useful to us.

    Essentially, we bought the asset to have a TextMesh where we could get at the generated mesh to do some fx on it. The built in Unity TextMesh completely hides that mesh. Curious, did you reimplement their mesh building routine or did you find a way to get at the mesh generated by TextMesh?

    And of course I would love a version with .cs source. I wanted to extend SetText() but it's not marked virtual so I worked around.
     
  50. tonic

    tonic

    Joined:
    Oct 31, 2012
    Posts:
    321
    Hi @benthroop.

    Does the text disappear when you move it in 2D plane, or are you e.g. rotating around a camera or so? If it's the latter case, I suspect you're maybe seeing actually just a drop to the min pix size what's done if the text position goes behind to camera plane or so. If it's not about that, I'm not sure what would cause that - only guessing it might be some culling problem, but even that'd be a bit weird as the Dynamic Text does instruct the mesh to recalculate its bounds.

    And yes I think you can turn off the automatic re-creation of the mesh by cam distance by setting min&max font px size to same. I guess I could consider adding a "mode" without the camera for next version, but that'd lose the possibility for the automatic text size updating and pixel perfect text (the main features I think). But, I see you're using the Dynamic Text for a different purpose than what it was built for, so I understand you have something different in mind. :)

    If you're interested in how the SetText is implemented internally, it's very straightforward:
    Code (CSharp):
    1.  
    2.     public void SetText(string newText)
    3.     {
    4.         if (newText == null)
    5.             newText = "";
    6.         textSB.EnsureCapacity(newText.Length);
    7.         textSB.Length = 0;
    8.         textSB.Append(newText);
    9.         FinishedTextSB();
    10.     }
    11.