void Awake() { tiles_ = new Array2D<char>( size_ ); colors_ = new Array2D<Color32>( size_ ); mesh_ = GetComponent<FontMesh>(); }
public void CreateFont(int type, int value, Vector3 pos) { FontMesh mf = fonts[type].pools.Get(); mf.SetValue(value, fonts[type].fonts); mf.pools = fonts[type].pools; mf.curTime = 0f; mf.transform.position = pos; mf.gameObject.SetActive(true); }
public override void OnRender() { //Console.WriteLine("LineEditBase render"); int selection1x = LEFont.Width(CurrentString.Substring(0, Selection1)) + 2; int selection2x = LEFont.Width(CurrentString.Substring(0, Selection2)) + 2; int pselection1x = selection1x; int pselection2x = selection2x; if (pselection2x < pselection1x) { pselection2x = selection1x; pselection1x = selection2x; } if (selection1x != selection2x) { byte sr = 0; byte sg = 0; byte sb = 0; SelectionMesh.SetVertex(0, selection1x, 0, 0, 0, 0, sr, sg, sb, 255); SelectionMesh.SetVertex(1, selection2x, 0, 0, 0, 0, sr, sg, sb, 255); SelectionMesh.SetVertex(2, selection2x, Height, 0, 0, 0, sr, sg, sb, 255); SelectionMesh.SetVertex(3, selection1x, Height, 0, 0, 0, sr, sg, sb, 255); AllodsWindow.SetTranslation(GlobalX, GlobalY, 0f); SelectionMesh.Render("notex"); } if (CurrentStringOld != CurrentString) { if (CurrentMesh != null) { CurrentMesh.Dispose(); } CurrentMesh = LEFont.Render(CurrentString, Font.Align.Left, Width, Height, false); CurrentStringOld = CurrentString; } CurrentMesh.Render(GlobalX + 2, GlobalY + 2, 1, 255, 255, 255, 255); if (CursorVisible) { CursorMesh.SetVertex(0, selection2x, 0, 0, 0, 0, 255, 255, 255, 255); CursorMesh.SetVertex(1, selection2x, Height, 0, 0, 0, 255, 255, 255, 255); AllodsWindow.SetTranslation(GlobalX, GlobalY, 0f); CursorMesh.Render("notex"); } }
void Awake() { mesh_ = GetComponent<FontMesh>(); mesh_.SetData( new SUtil.Common.IntVector2(1,1), new char[]{char_[0]}, new Color32[]{color_} ); }
public void Build(FontMesh mesh, string text) { List <Vector2> vertexBuffer = new List <Vector2>(); List <Vector2> textureCoordBuffer = new List <Vector2>(); Vector2 cursor = Vector2.Zero; var font = mesh.Font; foreach (var character in text) { if (character == '\n') { cursor.X = 0; cursor.Y -= (float)font.LineHeight / (float)font.GivenSize; continue; } var data = font.Data[character]; //// WORKING WITHOUT SCALING, DON'T TOUCH ////vertexBuffer.Add(new Vector2(cursor + data.Offset.X, font.GivenSize - data.Offset.Y)); // top left ////vertexBuffer.Add(new Vector2(cursor + data.Offset.X, font.GivenSize - data.Offset.Y - data.Height)); // bottom left ////vertexBuffer.Add(new Vector2(cursor + data.Offset.X + data.Width, font.GivenSize - data.Offset.Y - data.Height)); // bottom right ////vertexBuffer.Add(new Vector2(cursor + data.Offset.X + data.Width, font.GivenSize - data.Offset.Y)); // top right //var localOffset = new Vector2(data.Offset.X / (float)font.GivenSize, data.Offset.Y / (float)font.GivenSize); //var localHeight = (float)data.Height / (float)font.GivenSize; //var localWidth = (float)data.Width / (float)font.GivenSize; //vertexBuffer.Add(new Vector2(cursor.X + localOffset.X, cursor.Y - localOffset.Y)); // top left //vertexBuffer.Add(new Vector2(cursor.X + localOffset.X, cursor.Y - localOffset.Y - localHeight)); // bottom left //vertexBuffer.Add(new Vector2(cursor.X + localOffset.X + localWidth, cursor.Y - localOffset.Y - localHeight)); // bottom right //vertexBuffer.Add(new Vector2(cursor.X + localOffset.X + localWidth, cursor.Y - localOffset.Y)); // top right //Vector2 texturePosition = new Vector2(data.Position.X / font.AtlasWidth, data.Position.Y / font.AtlasHeight); //float textureWidth = (float)data.Width / (float)font.AtlasWidth; //float textureHeight = (float)data.Height / (float)font.AtlasHeight; //textureCoordBuffer.Add(new Vector2(texturePosition.X, texturePosition.Y)); // top left //textureCoordBuffer.Add(new Vector2(texturePosition.X, texturePosition.Y + textureHeight)); // bottom left //textureCoordBuffer.Add(new Vector2(texturePosition.X + textureWidth, texturePosition.Y + textureHeight)); // bottom right //textureCoordBuffer.Add(new Vector2(texturePosition.X + textureWidth, texturePosition.Y)); // top right // VERTICES vertexBuffer.Add(new Vector2(cursor.X + data.LocalOffset.X, cursor.Y - data.LocalOffset.Y)); // top left vertexBuffer.Add(new Vector2(cursor.X + data.LocalOffset.X, cursor.Y - data.LocalOffset.Y - data.LocalHeight)); // bottom left vertexBuffer.Add(new Vector2(cursor.X + data.LocalOffset.X + data.LocalWidth, cursor.Y - data.LocalOffset.Y - data.LocalHeight)); // bottom right vertexBuffer.Add(new Vector2(cursor.X + data.LocalOffset.X + data.LocalWidth, cursor.Y - data.LocalOffset.Y)); // top right // TEXTURE COORDS Vector2 texturePosition = new Vector2(data.Position.X / font.AtlasWidth, data.Position.Y / font.AtlasHeight); float textureWidth = (float)data.LocalWidth * font.GivenSize / (float)font.AtlasWidth; float textureHeight = (float)data.LocalHeight * font.GivenSize / (float)font.AtlasHeight; textureCoordBuffer.Add(new Vector2(texturePosition.X, texturePosition.Y)); // top left textureCoordBuffer.Add(new Vector2(texturePosition.X, texturePosition.Y + textureHeight)); // bottom left textureCoordBuffer.Add(new Vector2(texturePosition.X + textureWidth, texturePosition.Y + textureHeight)); // bottom right textureCoordBuffer.Add(new Vector2(texturePosition.X + textureWidth, texturePosition.Y)); // top right //cursor.X += (float)data.Xadvance / (float)font.GivenSize; cursor.X += data.LocalXadvance; } float[] vertices = new float[vertexBuffer.Count * 2]; float[] textureCoords = new float[textureCoordBuffer.Count * 2]; int vertexIndex = 0; foreach (var vertex in vertexBuffer) { vertices[vertexIndex++] = vertex.X; vertices[vertexIndex++] = vertex.Y; } int textureCoordIndex = 0; foreach (var textureCoord in textureCoordBuffer) { textureCoords[textureCoordIndex++] = textureCoord.X; textureCoords[textureCoordIndex++] = textureCoord.Y; } vertexBuffer.Clear(); textureCoordBuffer.Clear(); mesh.UpdateCoords(vertices, textureCoords); //return new FontMesh(vertices, textureCoords, font); }