void Start() { /* * Create BitmapFont.Renderer instance. */ mRenderer = new BitmapFont.Renderer( "BitmapFont/" + font, size, width, 0, align); mRenderer.SetText(text, color); /* * Set the Mesh to MeshFilter and set the Material to MeshRenderer. */ MeshFilter meshFilter = gameObject.AddComponent<MeshFilter>(); meshFilter.sharedMesh = mRenderer.mesh; MeshRenderer meshRenderer = gameObject.AddComponent<MeshRenderer>(); meshRenderer.sharedMaterial = mRenderer.material; }
public TextContext(Factory f, GameObject p, Data data, Format.Text text) { factory = f; parent = p; Format.TextProperty textProperty = data.textProperties[text.textPropertyId]; Format.Font fontProperty = data.fonts[textProperty.fontId]; color = factory.ConvertColor(data.colors[text.colorId]); string str = data.strings[text.stringId]; string fontName = data.strings[fontProperty.stringId]; string fontPath = factory.fontPrefix + fontName; float fontHeight = (float)textProperty.fontHeight; float width = (float)text.width; float height = (float)text.height; float lineSpacing = 1.0f + (float)textProperty.leading / fontHeight; float letterSpacing = (float)fontProperty.letterspacing / fontHeight; float tabSpacing = 4.0f; float leftMargin = textProperty.leftMargin / fontHeight; float rightMargin = textProperty.rightMargin / fontHeight; if (fontName.StartsWith("_")) { ISystemFontRenderer.Style style = ISystemFontRenderer.Style.NORMAL; ISystemFontRenderer.Align align; int a = textProperty.align & (int)Align.ALIGN_MASK; switch (a) { default: case (int)Align.LEFT: align = ISystemFontRenderer.Align.LEFT; break; case (int)Align.RIGHT: align = ISystemFontRenderer.Align.RIGHT; break; case (int)Align.CENTER: align = ISystemFontRenderer.Align.CENTER; break; } ISystemFontRenderer.VerticalAlign valign; int va = textProperty.align & (int)Align.VERTICAL_MASK; switch (va) { default: valign = ISystemFontRenderer.VerticalAlign.TOP; break; case (int)Align.VERTICAL_BOTTOM: valign = ISystemFontRenderer.VerticalAlign.BOTTOM; break; case (int)Align.VERTICAL_MIDDLE: valign = ISystemFontRenderer.VerticalAlign.MIDDLE; break; } systemFontRendererParameter = new ISystemFontRenderer.Parameter( fontHeight, width, height, style, align, valign, lineSpacing, letterSpacing, leftMargin, rightMargin); systemFontRenderer = ISystemFontRenderer.Construct(); systemFontRenderer.SetText(str, color); } else { BitmapFont.Renderer.Align align; int a = textProperty.align & (int)Align.ALIGN_MASK; switch (a) { default: case (int)Align.LEFT: align = BitmapFont.Renderer.Align.LEFT; break; case (int)Align.RIGHT: align = BitmapFont.Renderer.Align.RIGHT; break; case (int)Align.CENTER: align = BitmapFont.Renderer.Align.CENTER; break; } BitmapFont.Renderer.VerticalAlign valign; int va = textProperty.align & (int)Align.VERTICAL_MASK; switch (va) { default: valign = BitmapFont.Renderer.VerticalAlign.TOP; break; case (int)Align.VERTICAL_BOTTOM: valign = BitmapFont.Renderer.VerticalAlign.BOTTOM; break; case (int)Align.VERTICAL_MIDDLE: valign = BitmapFont.Renderer.VerticalAlign.MIDDLE; break; } bitmapFontRenderer = new BitmapFont.Renderer(fontPath, fontHeight, width, height, align, valign, 0.25f, lineSpacing, letterSpacing, tabSpacing, leftMargin, rightMargin); bitmapFontRenderer.SetText(str, color); } }
public TextContext(Factory f, GameObject p, Data data, int objectId) { factory = f; parent = p; Format.Text text = data.texts[objectId]; Format.TextProperty textProperty = data.textProperties[text.textPropertyId]; Format.Font fontProperty = data.fonts[textProperty.fontId]; color = factory.ConvertColor(data.colors[text.colorId]); string fontName = data.strings[fontProperty.stringId]; string fontPath = factory.fontPrefix + fontName; float fontHeight = (float)textProperty.fontHeight; float width = (float)text.width; float height = (float)text.height; float lineSpacing = 1.0f + (float)textProperty.leading / fontHeight; float letterSpacing = fontProperty.letterspacing; float tabSpacing = 4.0f; float leftMargin = textProperty.leftMargin / fontHeight; float rightMargin = textProperty.rightMargin / fontHeight; if (fontName.StartsWith("_")) { ISystemFontRenderer.Style style; if (fontName == "_bold") { style = ISystemFontRenderer.Style.BOLD; } else if (fontName == "_italic") { style = ISystemFontRenderer.Style.ITALIC; } else if (fontName == "_bold_italic") { style = ISystemFontRenderer.Style.BOLD_ITALIC; } else { style = ISystemFontRenderer.Style.NORMAL; } ISystemFontRenderer.Align align; int a = textProperty.align & (int)Align.ALIGN_MASK; switch (a) { default: case (int)Align.LEFT: align = ISystemFontRenderer.Align.LEFT; break; case (int)Align.RIGHT: align = ISystemFontRenderer.Align.RIGHT; break; case (int)Align.CENTER: align = ISystemFontRenderer.Align.CENTER; break; } ISystemFontRenderer.VerticalAlign valign; int va = textProperty.align & (int)Align.VERTICAL_MASK; switch (va) { default: valign = ISystemFontRenderer.VerticalAlign.TOP; break; case (int)Align.VERTICAL_BOTTOM: valign = ISystemFontRenderer.VerticalAlign.BOTTOM; break; case (int)Align.VERTICAL_MIDDLE: valign = ISystemFontRenderer.VerticalAlign.MIDDLE; break; } systemFontRendererParameter = new ISystemFontRenderer.Parameter( fontHeight, width, height, style, align, valign, lineSpacing, letterSpacing, leftMargin, rightMargin); systemFontRenderer = ISystemFontRenderer.Construct(); } else { BitmapFont.Renderer.Align align; int a = textProperty.align & (int)Align.ALIGN_MASK; switch (a) { default: case (int)Align.LEFT: align = BitmapFont.Renderer.Align.LEFT; break; case (int)Align.RIGHT: align = BitmapFont.Renderer.Align.RIGHT; break; case (int)Align.CENTER: align = BitmapFont.Renderer.Align.CENTER; break; } BitmapFont.Renderer.VerticalAlign valign; int va = textProperty.align & (int)Align.VERTICAL_MASK; switch (va) { default: valign = BitmapFont.Renderer.VerticalAlign.TOP; break; case (int)Align.VERTICAL_BOTTOM: valign = BitmapFont.Renderer.VerticalAlign.BOTTOM; break; case (int)Align.VERTICAL_MIDDLE: valign = BitmapFont.Renderer.VerticalAlign.MIDDLE; break; } bitmapFontRenderer = new BitmapFont.Renderer(fontPath, fontHeight, width, height, align, valign, 0.25f, lineSpacing, letterSpacing, tabSpacing, leftMargin, rightMargin); } }