@Patyrn, check the demo scene called multiple atlas demo. You will have one root GameObject with the UI script then one child on that GO for each atlas that has the UIToolkit script on it.
I'm finding how the text works fairly confusing. Browsing the example project you suggest I find you create your UIText with "prototype" and "prototype.png", yet the atlas name is "textDemoSheet". textDemoSheet appears to point at prototype.png, but there is no prototype.png in the resources folder. Could you enlighten me a little bit on what's going on here.
PS: Sorry for all the questions.
@Patyrn, the readme file on Githib has a walkthrough for setting up text. Basically, you export from the program of your choosing a .png and a .fnt file. Rename the .fnt to .txt and dump it in the resources folder then add the exported .png to your normal atlas.
Do you mean this readme:
This doesn't say anything about which files to reference where, and what they have to be named. For example:Text support is included with the UIText class. Your font bitmap can be created with Hiero, Angelcode or Glyph. If you want to support both HD and SD resolutions you will need to export a .fnt file for both resolutions. Both files should be placed in a Resources folder in your project and the HD version should have "2x" appended to the name to take part in auto HD switching at runtime. Add the exported bitmap font png to your texture atlas in Texture Packer and you are good to go, just be sure the image name is the same as the .fnt filename. Note: you must rename the .fnt file to .txt. Unity currently will not recognize .fnt files as TextAssets.
- var text = new UIText( "prototype", "prototype.png" );
Is the first value the path + filename to the .fnt file (renamed .txt?).
Is the second value the path + filename to the exported bitmap font png, or the sprite sheet png?
I'm setting it up with my best guess, and getting this error:
Exception: can't find texture details for texture packer sprite:Textures/UI/Text/geo.png
UISpriteManager.frameForFilename (System.String filename) (at Assets/Plugins/UIToolkit/BaseElements/UISpriteManager.cs:171)
UIText..ctor (.UIToolkit manager, System.String fontFilename, System.String textureFilename) (at Assets/Plugins/UIToolkit/UIElements/UIText.cs:11
UIText..ctor (System.String fontFilename, System.String textureFilename)
BuildShips.Start () (at Assets/Scripts/UI/BuildShips.cs:14)
@Patyrn, no paths are required. Everything is loaded using the standard Resources.Load. Use the sample scene as a template for how to do things.
Ok I got it to load without an error, but it's using my buttons sprite sheet instead of my text sprite sheet. I've tripple checked that I'm passing it the right one as the first parameter when creating my UItext.
Last edited by Patyrn; 05-30-2011 at 05:20 PM.
The first parameter to UIText is not an atlas. It is the image exported from the font generator program which should be added to your actual sprite atlas.
I'm using this constructor:
public UIText( UIToolkit manager, string fontFilename, string textureFilename )
First param is the UIToolkit (I'm using multiple atlases).
My second parameter is the name of the .fnt file (renamed to .txt), and my third parameter is the name of the png that my bitmap font generator exported. It's still showing random slices of an atlas I didn't even pass it.
Edit: Some more info. If I delete the other atlas so I have ONLY the text atlas, it works. I'm not sure that the UIText class is respecting the atlas parameter, though I can't see anything obviously wrong with it.
Last edited by Patyrn; 05-31-2011 at 01:39 AM.
@Patyrn, do you have a simplified sample project you can export and send my way so I can give it a look?
This one is the opposite, with the text sheet being used for the buttons instead of vice-versa. I'm sure it's the same underlying problem though.
Hi There Prime31
Excellent plugin, very useful, but got a minor problemo.
I wanted to use this for both an iPhone project & a Browser project but I'm getting failures all over
everything is fine in the unity editor coz the compiler directives are gated for UNITY_EDITOR however that obviously prevents that code from going into the WebBrowser compilation.
As I've tried & failed to modify the directives to also select UNITY_WEBPLAYER and its failing all over the shop, I'm guessing that it's not that simple?
@jon, UIToolkit works fine in a web player. I'm not sure if you have a modified version or not but all the compiler directives are pretty clear:
- #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN || UNITY_WEBPLAYER
Possible I have an older version then as the directives were only for #if UNITY_EDITOR
Yep a pretty early version just redownloaded and theres Lots more goodies to play with
Thanks for some great work
@Patyrn, it looks like you are using the same Material for both instances of your UIToolkits. Each one needs to have a unique material so that it can house it's own texture.
@Prime31, damn I really should have noticed that. Works now. Thanks!
Did you use BMFont or one of the others? I can't seem to actually create transparent fonts in BMFont.
I use Hiero and it seems to work well except for purporting everything flipped.
Sucks cause I'm on windows and seem to be stuck with BMFont. Anyone else on windows in here want to chime in on their BMFont experiences?
@Patryn I've found that BMFont doesn't work properly with padding for some reason. If you set the padding high, your letters end up over each other, if you set it low, you end up with parts of your font being clipped off. Weird, as I've used BMFont at work on a professional project with no problems.
So now I'm stuck with Hiero - which does work on windows by the way - but perhaps using the term "works" is being overly generous. On my machine it doesn't update the exported bitmap until you restart it and it crashes everytime you shut it down. Also, when you finally get something usable out of it you have to manually flip the exported bitmap in your image editor of choice. It took me an entire weekend to finally get some text in my game, though now I've mapped out the myriad bugs and gotcha's the pipeline is more or less usable.
I was very surprised not to read of anyone else's issues in this matter. Are they software gremlins specific to my setup? I'm running windows 7.
Oh, and a big thanks to Prime 31 for releasing a powerful, usable and free UI solution for Unity.