TextFields and bitmap fonts

TextFields and bitmap fonts

This tutorial assumes you have uniSWF added to the current unity project.

In this tutorial we will show how to export fonts using uniSWF, fonts are treated as bitmap fonts so for every size and style a new found has to be exported, fonts can be shared between assets which is the default option. Please note this tutorial is intended to introduce handling text in uniSWF and will export the same font multiple times per swf, see the next tutorial for exporting shared assets and fonts.

Step 1

Open flash and create a new Actionscript 3.0 document.

Step 2

Create a new MovieClip called SimpleText, tick export for ActionScript and export in frame 1

Step 3

Create a new text field with any font or size and change the type to dynamic. Set the property name to txt which is the variable name we will use to change the text from unityscript.

Step 4

Save the fla inside your unity project and publish the swf.

Step 5

Alt/cmd+tab to Unity and you should be presented with the initial swf import dialog, click "Export SWF" to add the asset to your project.

Step 6

By default fonts are not exported, to export all fonts used in any textfield you need to do the following. Open the project panel and select the published swf file.

Step 7

Once selected open the Export options panel from the Window->uniSWF->Export options menu.

Step 8

Expand the Fonts section and tick on "Export fonts", by default uniSWF exports a default set of characters which can be viewed in the Reference Manual.

Step 9

Click the Export button or re-publish in flash and the asset will be re-exported.

Step 10

Create a new Empty GameObject and attach a MovieClipBehaviour from the Components->uniSWF->MovieClipBehaviour.

Step 11

Expand the "Movie Clip Behaviour (Script)" section in the Inspector and click Change MovieClip

Step 12

Expand the tut05_Fonts (or the name of the source fla) then click on the SimpleText ( the name of the MovieClip in step 2 )

Step 13

Select the GameObject that you added the MovieClipBehaviour then in the scene view and press the F key to focus on the object, hopefully the text should appear in the viewport. If nothing appears double check the console for errors like "BitmapTextField() '' failed to find shared font 'Arial_55_c16737792', forget to MovieClip.preloadSWF() ?", double check the "Export fonts" checkbox on the Fonts section of the Export Options panel.