public void Awake() { // parse font xml if (!useRexPaintFont) { string fontXmlText = bitmapFontXml.text; XmlReader reader = XmlReader.Create(new StringReader(fontXmlText)); while (reader.Read()) { // parse texture size if (reader.LocalName == "common") { textureSize = float.Parse(reader.GetAttribute("scaleW")); } // parse glyph else if (reader.LocalName == "char") { string glyphString = char.ConvertFromUtf32(int.Parse(reader.GetAttribute("id"))); // new glyph if (!glyphs.ContainsKey(glyphString)) { BitmapFontGlyph glyph = new BitmapFontGlyph(); glyph.glyphString = glyphString; glyph.x = float.Parse(reader.GetAttribute("x")); glyph.y = float.Parse(reader.GetAttribute("y")); glyph.xOffset = float.Parse(reader.GetAttribute("xoffset")); glyph.yOffset = float.Parse(reader.GetAttribute("yoffset")); glyph.width = float.Parse(reader.GetAttribute("width")); glyph.height = float.Parse(reader.GetAttribute("height")); glyphs.Add(glyphString, glyph); glyph.RecalculateGlyphMetrics(glyphWidth, glyphHeight, textureSize, 0f); } } } } // use REXPaint font instead else { // get ibmgraph mapping Dictionary <int, int> ibmGraphMapping = BitmapFont.GetIBMGRAPHMapping(IBMGRAPH); // set glyph size rexPaintGlyphSize = rexPaintTextureSize / (float)rexPaintGridSize; // set texture size textureSize = rexPaintTextureSize; // add glyphs for (int y = 0; y < rexPaintGridSize; y++) { for (int x = 0; x < rexPaintGridSize; x++) { string glyphString = CP437ToUnicode(Mathf.RoundToInt(y * rexPaintGridSize + x), ibmGraphMapping); // new glyph if (!glyphs.ContainsKey(glyphString)) { BitmapFontGlyph glyph = new BitmapFontGlyph(); glyph.glyphString = glyphString; glyph.x = x * rexPaintGlyphSize; glyph.y = y * rexPaintGlyphSize; glyph.xOffset = 0f; glyph.yOffset = 0f; glyph.width = rexPaintGlyphSize; glyph.height = rexPaintGlyphSize; glyphs.Add(glyph.glyphString, glyph); glyph.RecalculateGlyphMetrics( rexPaintGlyphSize, rexPaintGlyphSize, textureSize, rexPaintBleed); } } } } // finished loading font fontLoaded = true; Debug.Log("FONT TEXTURE SIZE: " + textureSize); Debug.Log(glyphs.Count + " GLYPHS LOADED!"); }
public void Update() { // finished initializing if (initialized) { // update cells LinkedListNode <Cell> cellNode = cellList.First; while (cellNode != null) { cellNode.Value.Update(); cellNode = cellNode.Next; } // update display meshes for (int y = 0; y < displayHeight; y++) { for (int x = 0; x < displayWidth; x++) { // get top layer for cell LinkedList <int> topLayersForCell = topLayers[x, y]; // get cell at top layer Cell cell = null; if (topLayersForCell.First != null) { cell = cells[topLayersForCell.Last.Value][x, y]; } // empty cell if (cell == null || cell.content == "") { for (int i = 0; i < 4; i++) { // update display mesh vertices, uvs and colors foreground.meshVertices[(y * displayWidth + x) * 4 + i] = zero3; foreground.meshUVs[(y * displayWidth + x) * 4 + i] = zero2; foreground.meshColors[(y * displayWidth + x) * 4 + i] = clearColor; background.meshColors[(y * displayWidth + x) * 4 + i] = cell != null ? cell.backgroundColor : clearColor; } } // filled cell else { BitmapFontGlyph glyph = font.GetGlyph(cell.content); for (int i = 0; i < 4; i++) { // update display mesh vertices, uvs and colors foreground.meshVertices[(y * displayWidth + x) * 4 + i] = new Vector3( x * quadWidth + glyph.vertices[i].x * quadWidth, -y * quadHeight + glyph.vertices[i].y * quadHeight - quadHeight, 0f); foreground.meshUVs[(y * displayWidth + x) * 4 + i] = glyph.uvs[i]; foreground.meshColors[(y * displayWidth + x) * 4 + i] = cell.color; background.meshColors[(y * displayWidth + x) * 4 + i] = cell.backgroundColor; } } } } // apply display mesh updates background.UpdateMesh(); foreground.UpdateMesh(); // capture screenshot if (Input.GetKeyDown(KeyCode.P)) { //ScreenCapture.CaptureScreenshot("ascii_" + Random.Range(0, int.MaxValue) + ".png"); } } }