require 'erb'
HEADER = <<EOD %YAML 1.1 %TAG !u! tag:unity3d.com,2011: --- !u!128 &12800000 Font: m_ObjectHideFlags: 0 m_PrefabParentObject: {fileID: 0} m_PrefabInternal: {fileID: 0} m_Name: <%=name%> serializedVersion: 4 m_AsciiStartOffset: 0 m_Kerning: .100000001 m_LineSpacing: .100000001 m_CharacterSpacing: 1 m_CharacterPadding: 0 m_ConvertCase: 0 m_DefaultMaterial: m_CharacterRects: EOD
FOOTER = <<EOD m_Texture: {fileID: 0} m_KerningValues: [] m_PixelScale: .100000001 m_FontData: m_FontSize: 0 m_Ascent: 0 m_DefaultStyle: 0 m_FontNames: [] m_FallbackFonts: [] m_FontRenderingMode: 0 EOD
RECT_TEMPLATE = <<EOD - serializedVersion: 2 index: <%=char_code%> uv: serializedVersion: 2 x: <%=uv_x%> y: <%=uv_y%> width: <%=uv_w%> height: <%=uv_h%> vert: serializedVersion: 2 x: <%=vert_x%> y: <%=vert_y%> width: <%=vert_w%> height: <%=vert_h%> width: <%=width%> flipped: 0 EOD
def main(name, w, h, start) print ERB.new(HEADER).result(binding)
vert_x = vert_y = 0 vert_w = 16 vert_h = -16 width = 160 uv_w = 1.0 / w uv_h = 1.0 / h rect_erb = ERB.new(RECT_TEMPLATE) h.times do |iy| uv_y = (h - 1 - iy) * uv_h w.times do |ix| uv_x = ix * uv_w char_code = ix + iy * w + start print rect_erb.result(binding) end end
print ERB.new(FOOTER).result(binding) end
if $0 == __FILE__ main('BitmapFont', 16, 8, 32) end
|