Search Unity

Text Box 2 beta

Discussion in 'Works In Progress - Archive' started by Jasper-Flick, Mar 5, 2014.

  1. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @imtrobin: You typically only include those characters that you need, and when using distance maps you can get away with quite small single-channel textures. For example, you can easily fit a very high quality ASCII set on a 256x256 Alpha-8 texture, which is 64KB, or 85.3KB with mipmaps. Jumping to four times that size - 512x512 - you could include a few hundred more characters before you'd need to reduce the quality. However, it will become troublesome when you want access to thousands of Chinese characters.

    @rocki: I really want it to, but Unity's current dynamic text API is simply not up to the task. It's not flexible enough, lacks basic font data, and cannot be dynamic without memory pollution and thus causing Garbage Collection woes. I have reasons to believe that Unity 4.6 will bring us improved dynamic text along with the new GUI. I will reassess the possibilities when that happens.
     
  2. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    I plan to use in chatting text box so it can include thousands of characters. So perhaps a method to runtime generate it?
     
  3. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @imtrobin: Let's make sure we don't mix up two different things. There's how many symbols you put in the bitmap font (variety), and how many characters you put in the text box (quantity). These two are independent.

    You can put thousands of characters in a box, but the more you put in the more resources you'll use, just like creating bigger and bigger meshes does. You need to limit yourself somewhere or you'll run into trouble. Like for a chat log you'd only keep the last 100 entries or so.
     
  4. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    Symbols in the bitmap (or memory) of course, not the number of words in the chat.
     
  5. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @imtrobin: Unless you're chatting in Chinese, you don't need thousands of different symbols. You'd need the alphabet, numbers, punctuation, maybe extended Latin, Cyrillic or Greek symbols, or some emotes too. As a fixed distance map texture plus font data, that's a few hundred KB to one MB depending on quality.
     
  6. imtrobin

    imtrobin

    Joined:
    Nov 30, 2009
    Posts:
    1,548
    It's chatting in chinese, that's what I said from the start
     
  7. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @imtrobin: Ah, that explains. You mentioned Unicode but not specifically Chinese, so I was left guessing. As I mentioned to rocki a few posts back, dynamic fonts - runtime font generation - is currently out, but Unity 4.6 might change this.
     
  8. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    It would be so perfect if dynamic fonts is supported. Let's hope 4.6 provides the means to achieve the dream.
     
  9. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    Good progress is being made, but there's not much to show. I'm working on the code, making it faster, shorter, and more readable.

    I made a slight change in how the scene view shows the box's lines. Now they match the contours. You might now be able to see that the lines follow the contours at the height or their baseline.

    $text-box-progress.png
     
    Last edited: Apr 18, 2014
  10. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Nice One , looking good!

    Makes sense for the baselines to match up with the contour points.
     
  11. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Jasper,

    I'm making a text based adventure, and I'd like to have actionable words in certain colors, and also have those specific words be tap-able. If I read this thread right, this next version will support that, right? Or is that something that the existing version can handle as well?
     
  12. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @riot9: The existing version could do it, but needs quite some custom work to pull it off. It will be a whole lot easier with version 2.
     
  13. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Thanks for the quick reply!

    Do you have any estimate on how long it will be before version 2 hits?
     
  14. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @riot9: I will release as beta before the end of this month.
     
  15. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    Just a quick update to tell you all that I've basically completed the core functionality of version 2. This is the minimum to get text running and doesn't yet include stuff like scrolling and text editing. While that stuff has already been working for a while, I don't consider it beta-level shippable yet. Instead I'll see if I can push the core to the store soon so people can get their hands on it earlier rather than later.
     
  16. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
  17. africanrhino

    africanrhino

    Joined:
    Aug 15, 2013
    Posts:
    11
    hi,
    i just bought this asset. good job.
    how do i encapsulate the text in a box? i want a paragraph on a sheet of paper(plane or cube).. the paragraph is of variable length. the plane/cube should ideally grow/shrink to fit the text or vice versa .. like a textbox, i want a border / background. (literally a floating text box. )
     
  18. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @africanrhino: You can control the box size by adjusting width and maxHeight so you can make it match your background rectangle. You can also set padding on all sides to keep some space between the text and the edge.

    To make your cube fit the text box, you can use the four bounds variables to figure out the box's shape. The bounds depend on the anchor settings, the width, and the height used by the text.
     
  19. d0n3val

    d0n3val

    Joined:
    Feb 3, 2014
    Posts:
    1
    Jasper,

    I need the text to appear slowly, ideally fading in one character at a time. Any idea how I could do that ? I've tried hacking my way around your code but calling RefreshText() every frame is (as expected) an overkill.

    I am trying to move from "Text FX" plugin to yours because of the superior formatting text capabilities but I need a simple fadein animation :(

    NOTE: my last solution would be rendering in a separate camera to texture and making it appear slowly, but doesn´t sound very elegant.

    Ideas ?
    Thanks in advance! ;)
     
  20. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    269
    How 'overkill' is it? This solution seems by far the best available, but it would only really be useful if I can be updating a text box once a frame.

    I agree though, being able to set character alpha without setting it's own style would be super useful.
     
    Last edited: May 18, 2014
  21. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @d0n3val @Doddler: There's no API yet to control characters from outside the box. Looks like that might be a good idea to add!

    Currently a very simple fade-in reveal can be the job of a custom renderer. Here is a quick example of one that will start fading in characters immediately after the text box is refreshed.

    Code (csharp):
    1. using UnityEngine;
    2. using CatlikeCoding.TextBox;
    3.  
    4. public class RevealingRenderer : TextMeshRenderer {
    5.  
    6.     public float charactersRevealedPerSecond = 10f;
    7.  
    8.     private int revealingCharIndex;
    9.     private float revealProgress;
    10.    
    11.     public override void Add (CharMetaData meta, Vector2 offset) {
    12.         meta.color.a = 0;
    13.         base.Add(meta, offset);
    14.     }
    15.  
    16.     public override void Apply () {
    17.         base.Apply();
    18.         revealingCharIndex = 0;
    19.         revealProgress = 0f;
    20.         enabled = renderedCharCount > 0;
    21.     }
    22.  
    23.     private void Update () {
    24.         revealProgress += charactersRevealedPerSecond * Time.deltaTime;
    25.         int i = revealingCharIndex * 4;
    26.         Color32 c = colors[i];
    27.         if (revealProgress >= 1f) {
    28.             revealProgress -= 1f;
    29.             c.a = 255;
    30.             enabled = ++revealingCharIndex < renderedCharCount;
    31.         }
    32.         else {
    33.             c.a = (byte)(255f * revealProgress);
    34.         }
    35.         colors[i] = colors[i + 1] = colors[i + 2] = colors[i + 3] = c;
    36.         mesh.colors32 = colors;
    37.     }
    38. }
    Simply use this renderer instead of a TextMeshRenderer for your renderer prefab, set its speed as desired, and it'll work. However, the effect is applied per renderer, so it won't work right across different renderers and boxes.
     
  22. riot9

    riot9

    Joined:
    May 6, 2014
    Posts:
    35
    Jasper,

    Congrats on getting the beta out! So I am still working on that text based adventure I mentioned earlier and am looking at using text box 2. Just to be absolutely sure I understand correctly, I could have a paragraph of text with certain words that, when those words are trapped, would be able to fire of different events or run methods or something like that?

    And right now there is no scrolling built in, so I would need to put the text box in a scroll view or something and handle touch input manually, right?
     
  23. africanrhino

    africanrhino

    Joined:
    Aug 15, 2013
    Posts:
    11
    thank you . i'll give that a try. any idea if this will become a feature that doesn't require a hack? (i would would imagine others also wanting to be able to decorate borders, backgrounds etc. based on parents gameobjects.)
     
  24. Doddler

    Doddler

    Joined:
    Jul 12, 2011
    Posts:
    269
    That's quite amazing! I've been using Text Box 2 for a little bit now, and while it took a bit of figuring out, I'm really enjoying how well it works. Thanks for such a good tool. :)
     
    Last edited: May 21, 2014
  25. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    Right now I'm working on getting some more documentation online. Once that's done I'll proceed with beta 2. It might be released at the end of the month.

    @riot9: Thanks! Beta 1 is just the basics. Beta 2 will add scrolling and clicking on top of that. It won't work with Unity's scroll view because the text box is a proper 3D object, not part of Unity's old GUI solution. What happens when a word is clicked would differ per app. The text box allows you to retrieve the relevant data, and I'll add some simple examples. In fact I think a mini text adventure would be an excellent example, so I'll probably do that.

    @africanrhino: It's not so much a hack as it's text box giving you the means to do you own thing. There's no universal way to make a text box background or border, I can think of many different ways to do it. Having said that, it's a good idea to include some basic solutions for it, so I put that on my to-do list.

    @Doddler: My pleasure! I'm really going for a component-based approach this time. That way it should be much easier to make it fit your own requirements and leave out stuff that you don't need.
     
  26. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    Beta 1.1 just became available on the asset store. It fixes a bug that only happened in builds, not the editor. You can now also retrieve the renderers used by a text box through scripting, instead of having to look for its children.
     
  27. virtues

    virtues

    Joined:
    Jun 10, 2014
    Posts:
    1
    Hi Jasper. Thanks for TextBox. I use the CCTextTorusWrapper from TextBox 1. Are modifiers gone in Text Box 2? Is there a suggested alternative available or should I stick with TextBox 1 for now?
     
  28. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @virtues: Modifiers are indeed gone. There are now dedicated text renderers, which have taken over the responsibilities of modifiers. The current release doesn't have any modifying examples yet. I'll include some in the next release.
     
  29. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    A new update is now on the store, beta 1.2. This fixes an alignment problem and adds two renderers that reintroduce old modifier behavior.

    a2-torus.jpg
    a3-cylinder.jpg
    You create these wrapping renderers using the same prefab approach as the regular renderers. There are also special settings components that you can attach to text boxes, which allow you to control the shape settings per instance.
     
  30. Damocles

    Damocles

    Joined:
    Jul 21, 2012
    Posts:
    46
    Hi Jasper, this looks great, but is there a web demo anywhere of TB2? In particular I'm interested in testing out the text input stuff. Many other assets have claimed to do text input in the past, but every one of them has either been terrible or really buggy.

    I really need decent text input for my current game - is Text Box 2 going to have a full-featured text input system? Is there going to be a web demo? (this is a deal breaker for me - no demo, no sale. I've been burned once too often by terrible assets before)
     
  31. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @Damocles I understand where you're coming from. To give you an idea of where Text Box is right now, I planned to release beta 2 last month, but I got delayed and now plan to do so next week. Beta 2 will include clipping and scrolling, and it will have a web demo too. I will release text input shortly after that. So to be safe, wait about two weeks for a web demo with text input. Or buy anyway and ask me for a refund if the text input turns out not to your liking.

    The text input will start out supporting what you can see in the videos. So click in the area to place a cursor, move with arrows, type basic characters, and delete. I want to stick to the basics first and get them right. What I'll build on top of that will depend on people's needs, so I can't really predict that.
     
  32. highlyinteractive

    highlyinteractive

    Joined:
    Sep 6, 2012
    Posts:
    116
    Hi Jasper, this is looking great!

    I'm struggling to generate a Textbox purely through code. Is it possible? Any chance you could post a snippet showing how?

    Thanks & keep up the fantastic work
     
  33. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @emsee Sure, here's a minimal component script that turns itself into a text box.

    Code (CSharp):
    1. using UnityEngine;
    2. using CatlikeCoding.TextBox;
    3.  
    4. public class AddTextBoxComponent : MonoBehaviour {
    5.  
    6.     public TextStyleCollection styleCollection;
    7.  
    8.     private void Start () {
    9.         TextBox box = gameObject.AddComponent<TextBox>();
    10.         box.styleCollection = styleCollection;
    11.         box.SetText("Hello There!");
    12.         box.RenderText();
    13.     }
    14. }
    You need to give the box a style collection so it knows how to render itself. So you must have a reference to a style collection asset somewhere. Also, after setting the box's text you need to explicitly tell it to render itself.
     
    highlyinteractive likes this.
  34. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    There's now a demo online showing the new clipping features of the upcoming beta 2.

     
  35. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    Text Box 2 beta 2.0 is now available, adding the Clipping and EventSystem, which make nested clipping and scrolling possible.

    Minimum Unity version is now 4.5.2.
    New: Included Clipping library, which introduces clipping functionality.
    New: Icluded EventSystem library, which handles user input. It supports a subset of what Unity 4.6 uGUI might have.
    New: TextBox now has a textScale variable, which allows text scaling without changing text styles.
    New: TextBox now has a Rendered event.
    New: TextRenderer now has a textBox variable, so subclasses can easily access their parent box in case they need to query it.
    New: TextMeshRenderer now has a uv2Mode, which can be used to generate secondary uv coordinates.
    New: Added ClippedTextBox component, which adds clipping support to TextBox.
    New: TextRenderer now support clipping.
    New: Text Box Smooth shaders can now support clipping.
    New: Text Box Smooth shaders can now support a mask texture, using secondary uv.
    New: Added reasonable default configuration for some components.
    New: Added Text Box and Clipping menu items under Assets and GameObject editor menus.
    Fix: TextBox.textRenderers array is no longer public.
    Fix: Worked around a Unity bug that causes a console warning message when a text style collection asset is selected.
    Obsoleted: AutomaticParentSelector has been superceded by the SelectionBase attribute. The components should remove themselves.

    Check the code documentation to find out how the new Clipping and EventSystem stuff works. I will make separate written documentation available later as well.

    The next big thing on the roadmap is getting feedback on where and what in the text you clicked or touched. And don't hesitate to ask for specific features, because that's how they get on the roadmap!
     
    Last edited: Jul 23, 2014
  36. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    I have released a small update, version 2 beta 2.0.1.

    I was using material blocks in the editor to get the clipping working. However, due to some weird performance degradations I didn't use the blocks in play mode, until now.

    Turns out you need to call Clear on MaterialPropertyBlock when replacing an old value, otherwise the old values stick around and do nothing but slow the whole system down. While having to reset the whole block is silly, at least it works and performance is good.
     
  37. immerse

    immerse

    Joined:
    Mar 4, 2014
    Posts:
    5
    Hey Jasper,

    I've purchased your Version 2 beta on the asset store. Really great project by the way, love the crisp text.

    Question - how do I find out the actual width of text rendered? (I can query the width/height, but what I would like is the actual bounding box of "rendered" text). I had a poke around TextBox.cs, however I couldn't see anything too obvious in there.

    Thanks!
     
  38. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @immerse Glad you like it! To know the real bounds, you have to query the text renderers. If you're using TextMeshRenderer components, you can grab their mesh bounds. Give me a moment and I'll add an easy property for it to TextBox.
     
  39. immerse

    immerse

    Joined:
    Mar 4, 2014
    Posts:
    5
    @Jasper Flick Thanks for the super fast reply. I'll wait for your property while I'm working on some other things. Otherwise I'll add it myself, cheers!
     
  40. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @immerse Your property is now available. Everything for a good asset store rating and review! ;)

    Here is the full change log of Version 2, beta 2.1:

    New: Added Bounds property to TextRenderer and TextMeshRenderer, to get their 3D bounds.
    New: Added TextRendererBounds property to TextBox, to get the combined 3D bounds of its renderers.
    New: Added supersample option to Text Box Smooth Auto shader.

    The new supersample option helps when working with small text. Here is a comparison with double-size images.

    No mipmaps, no SS:

    no-ss-no-mips.png

    Anisotropic mipmaps, no SS:

    no-ss-mips.png

    No mipmaps, with SS:

    ss-no-mips.png

    You should turn off mipmapping when using supersampling, because it needs the full-size texture data to do its work.
     
  41. immerse

    immerse

    Joined:
    Mar 4, 2014
    Posts:
    5
    @Jasper Flick Thanks for this, giving it a go now, should all be good and I can look at writing up a review too.
     
  42. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @immerse Thanks!

    A new version, Text Box 2 beta 3 is now available for download.

    Now you're able to query TextBox for character, string, and meta tag data relative to a point in world space. This allows for clickable text and such. Included is a new Clickable example, which is a little story that you can navigate through by clicking on the text. You can try it online.

    text-box-clickable.jpg

    Text Box 2 beta 3.0

    New: Added GetCharInfo, GetVisibleCharSequence, and GetInnermostMetaTag methods to TextBox. You can use these to support clickable text.
    New: TextBoxCharInfo struct, to provide some useful info about characters.
    New: Added Clickable example, which is a small text adventure.
    New: Added SetViewportOffsetFactorClamped method to ClipBox.
    New: ClippedTextBoxCollider3D component, for detecting 3D input on TextBox.
    Fix: ClipBox no longer allows scrolling when content is smaller than the viewport.
    Fix: ClippedTextBoxInspector now also shows Ignore Overflox Box toggle.
    Fix: Getting ClipBox.ViewportOffsetFactor when it hasn’t been initialized yet no longer throws an exception.
    Fix: Text Box style scopes now correctly work in combination with non-style meta tags.
    Fix: Eliminated shader warnings for Text Box Smooth Auto.
    Change: Restructured Text Box examples. Please remove the old Example folder.
    Change: Renamed CharType.Style to CharType.Meta.
    Change: Renamed Scrollbar3DInput to ScrollbarInput3D.
    Change: Renamed Mouse3DCameraToucher to MouseCameraToucher3D.
    Change: Moved material and texture from Clipping to Examples folder.
    Change: ClippedTextBox is now extendable.
    Change: ClipBoxScrollbar no longer overshoots when clicking the track.
    Removed: AutomaticParentSelector, which was already obsoleted and stripped from objects.
    Removed: Materials folder in Clipping, along with a pointless material inside it.
    Removed: Old debug statement from ClipBox.
     
  43. Sachs3n

    Sachs3n

    Joined:
    Aug 24, 2014
    Posts:
    4
    Does Text Box 2 Beta 3 work with Unity 4.6?

    I'm specifically trying to figure out if Text Box 2 text will adhere to anchors in 4.6 (either inside a panel or separate Text objects). What I'd prefer to do is allow my Text or Panels to be handled by the UI in 4.6 so that the size of the Text or Panel box dynamically expands or contracts based on screen resolution. Hopefully, I could then use your product to have overflow text dynamically move into the next text box.

    Is there a way to make Text Box 2 work with the 4.6 anchors now, or is there a forthcoming release?
     
  44. NazimR

    NazimR

    Joined:
    Mar 12, 2014
    Posts:
    17
    Hey Jasper, I'm wondering about the new UV2 and mask feature. In order to get it working do I need to specify UV coordinates? How do I set the mask texture for my shader?
     
  45. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @Sachs3n I am going to integrate Text Box 2 so it will work with the new uGUI. So it will work with anchors and sizing and everything. I am currently on vacation (sort-of, not really) but I'll get a new release ready once I get home next week. I'm not sure when 4.6 is officially released and no longer in beta, but I want to have it ready when that happens.

    @SomerSet The uv2 coordinates are a feature of the TextMeshRenderer. Right now the only option is either no uv2 or so the uv2 range covers the entire rectangle of the box. The smooth shaders have a mask mode option. When set to something other than none, you should be able to assign a mask texture. It will cover the entire text box.

    I can add more UV2 modes. If you want a specific one just let me know and I'll put it on my to-do list.
     
  46. NazimR

    NazimR

    Joined:
    Mar 12, 2014
    Posts:
    17
    I'm currently trying to create a way where I can have scrolling text that fades at the top and bottom. I was thinking that if I could use a mask I could combine it with scrolling/clipping to create that effect.
     
  47. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @SomerSet It is easiest to do that by putting the text box inside a clip box with a material that uses smooth clipping. The mask doesn't really work with scrolling.
     
  48. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Hey Jasper,

    Been playing with the new version and it's really awesome.
    I'm trying to integrate the excellent open source TouchScript gesture to work with TextBox2 and wondering if you could provide some tips as to how it can be done. The reason is that the MouseCameraToucher3D script is taking all of the input which means that touchscript cannot interact with textbox content. If you have time, it would be really great if you could look into this.

    Cheers.
     
  49. Jasper-Flick

    Jasper-Flick

    Joined:
    Jan 17, 2011
    Posts:
    959
    @rocki I'm currently not at home and not really able to check out TouchScript, will do so later.

    Because there are so many different UI solutions, I made sure to separate input logic from the core components. MouseCameraToucher3D and the input components that implement event system interfaces form just a basic solution. The quickest way to make it work with TouchScript is probably to write your own small components that respond to TouchScript events and control the scrollbars and such, and not use MouseCameraToucher3D.
     
  50. EmeralLotus

    EmeralLotus

    Joined:
    Aug 10, 2012
    Posts:
    1,462
    Not a problem, I managed to get the two working well.