Created
January 21, 2015 10:43
-
-
Save asus4/e220f823693767a5f12a to your computer and use it in GitHub Desktop.
Enable to edit 3D Text mesh in Unity3D
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; | |
namespace Sample | |
{ | |
[RequireComponent(typeof(Collider))] | |
[RequireComponent(typeof(TextMesh))] | |
public class Editable3DText : MonoBehaviour { | |
TextMesh label; | |
TouchScreenKeyboard keyboard; | |
void Start() | |
{ | |
label = GetComponent<TextMesh>(); | |
} | |
void Update() | |
{ | |
if(isEditing) { | |
if(!isMobileRuntime) { | |
foreach (char c in Input.inputString) { | |
if (c == "\b"[0]) { | |
if (keyboard.text.Length != 0) { | |
keyboard.text = keyboard.text.Substring(0, keyboard.text.Length - 1); | |
} | |
} | |
else if (c == "\n"[0] || c == "\r"[0]){ | |
isEditing = false; | |
return; | |
} | |
else { | |
keyboard.text += c; | |
} | |
} | |
} | |
label.text = keyboard.text; | |
} | |
} | |
void OnMouseUpAsButton() | |
{ | |
isEditing = !isEditing; | |
} | |
bool isEditing { | |
get { | |
return keyboard != null; | |
} | |
set { | |
if( value ) { | |
keyboard = TouchScreenKeyboard.Open(label.text); | |
} | |
else { | |
keyboard.active = false; | |
keyboard = null; | |
} | |
} | |
} | |
bool isMobileRuntime { | |
get { | |
return (Application.platform == RuntimePlatform.Android) || (Application.platform == RuntimePlatform.IPhonePlayer); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I found it's not working on PC....