Created
March 28, 2012 02:37
-
-
Save asus4/2223039 to your computer and use it in GitHub Desktop.
SystemFontRenderer utility for nGUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
//[ExecuteInEditMode] | |
[RequireComponent(typeof(SystemFontRenderer))] | |
[AddComponentMenu("NGUI/Interaction/Ex/System Font")] | |
public class UISystemFont : MonoBehaviour { | |
SystemFontRenderer fontRenderer; | |
#if UNITY_EDITOR | |
void Awake () { | |
fontRenderer = GetComponent<SystemFontRenderer>(); | |
makeSprite(); | |
} | |
#endif | |
void Start () { | |
fontRenderer = GetComponent<SystemFontRenderer>(); | |
fontRenderer.BindMaterial(renderer.material); | |
} | |
void makeSprite() { | |
float w = fontRenderer.textureWidth; | |
float h = fontRenderer.textureHeight; | |
Vector3[] vertices = new Vector3[] {new Vector3(0,0,0), new Vector3(0,h,0), new Vector3(w,h,0), new Vector3(w,0,0)}; | |
Vector2[] uv = new Vector2[] {new Vector2(0,0), new Vector2(0,1), new Vector2(1,1), new Vector2(1,0)}; | |
int[] triangles = new int[] {0, 1, 2, 0, 2, 3}; | |
/* make sprite like.. | |
0 - 3 | |
| \ | | |
1 - 2 | |
*/ | |
Mesh mesh = GetComponent<MeshFilter>().sharedMesh; | |
mesh.Clear(); | |
mesh.vertices = vertices; | |
mesh.uv = uv; | |
mesh.triangles = triangles; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment