Last active
December 31, 2015 16:59
-
-
Save hww/8017276 to your computer and use it in GitHub Desktop.
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 System; | |
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
/* | |
* To use this object as 3D text mesh | |
* | |
* void AttachLabelToGameObject (GameObject obj, string font, string text) { | |
* | |
* Label3D label = new Label3D("Tondu", text); | |
* | |
* label.gameObject.transform.position = obj.transform.position; | |
* label.gameObject.transform.parent = obj.transform; | |
* label.gameObject.transform.localScale = new Vector3(0.01f,0.01f,0.01f); | |
* | |
* // N.B. scale could be calculated with Futile.screen.width | |
* } | |
*/ | |
public class Label3D : Entity | |
{ | |
public string fontName; | |
protected FLabelColorized label_; | |
protected string text_ = ""; | |
protected Color color_ = Color.white; | |
// GameObject | |
protected FShader shader_; | |
protected MeshFilter meshFilter_; | |
protected MeshRenderer meshRenderer_; | |
protected Mesh mesh_; | |
protected Material material_; | |
void Awake () { | |
Init(); | |
} | |
void Init() { | |
label_ = new FLabelColorized(fontName, "", new FTextParams()); | |
meshFilter_ = gameObject.AddComponent<MeshFilter>(); | |
meshFilter_.mesh = mesh_ = new Mesh(); | |
meshRenderer_ = gameObject.AddComponent<MeshRenderer>(); | |
meshRenderer_.castShadows = false; | |
meshRenderer_.receiveShadows = false; | |
shader_ = FShader.defaultShader; | |
material_ = new Material(shader_.shader); | |
material_.mainTexture = label_.element.atlas.texture; | |
meshRenderer_.renderer.material = material_; | |
#if UNITY_3_0 || UNITY_3_1 || UNITY_3_2 || UNITY_3_3 || UNITY_3_4 || UNITY_3_5 | |
gameObject.active = false; | |
#else | |
//gameObject.SetActive(false); | |
mesh_.MarkDynamic(); | |
#endif | |
label_.color = color_; | |
label_.richText = text_; | |
label_.UpdateMesh(mesh_); | |
} | |
public string text { | |
get { return text_; } | |
set { | |
if (text_ != value) { | |
text_ = value; | |
label_.richText = value; | |
label_.UpdateMesh(mesh_); | |
} | |
} | |
} | |
public Color color { | |
get { return color_; } | |
set { | |
if (color_ != value) { | |
color_ = value; | |
label_.color = value; | |
label_.UpdateMesh(mesh_); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment