void Update() { UpdateMesh(); if (mesh != null) { UpdateMaterial(); var mtx = transform.localToWorldMatrix; var scale = EasyFontUtilities.kScaleFactor * characterSize; var offset = EasyFontUtilities.CalcAnchorOffset(mesh, anchor); offset.y = -offset.y; var offsetMat = Matrix4x4.TRS(offset, Quaternion.identity, Vector3.one); var scaleMat = Matrix4x4.Scale(new Vector3(scale, -scale, scale)); Graphics.DrawMesh(mesh, mtx * scaleMat * offsetMat, mat, gameObject.layer); } }
void RenderText(Camera cam) { // don't render if no GUILayer var guiLayer = cam.GetComponent <GUILayer>(); if (guiLayer == null || !guiLayer.enabled) { return; } // our layer is culled if ((cam.cullingMask & (1 << gameObject.layer)) == 0) { return; } UpdateMesh(); if (mesh == null) { return; } UpdateMaterial(); GL.PushMatrix(); GL.LoadPixelMatrix(); mat.SetPass(0); var camRect = cam.pixelRect; var pos = transform.position; pos.x = camRect.x + pos.x * camRect.width + pixelOffset.x; pos.y = camRect.y + pos.y * camRect.height + pixelOffset.y; pos.z = 0; pos += EasyFontUtilities.CalcAnchorOffset(mesh, anchor); pos.x = Mathf.Round(pos.x); pos.y = Mathf.Round(pos.y); var scale = characterSize; var mtx = Matrix4x4.TRS(pos, Quaternion.identity, new Vector3(scale, -scale, scale)); // Note: DrawMeshNow sets up current camera's view matrix; // so make sure that's identity and reset it afterwards cam.worldToCameraMatrix = Matrix4x4.identity; Graphics.DrawMeshNow(mesh, mtx); cam.ResetWorldToCameraMatrix(); GL.PopMatrix(); }