一、新建两个脚本
using UnityEngine; using System.Collections; [ExecuteInEditMode] public class UILabel : MonoBehaviour { [HideInInspector] [SerializeField] public string text; void OnGUI() { GUI.Label(new Rect(0, 0, 200, 200), text); } }
using UnityEngine; using UnityEditor; using System.Collections; [CustomEditor(typeof(UILabel))] [CanEditMultipleObjects] public class UILabelInspector : Editor { protected UILabel mLabel; protected virtual void OnEnable() { mLabel = target as UILabel; } public override void OnInspectorGUI() { string text = EditorGUILayout.TextArea(mLabel.text, GUI.skin.textArea, GUILayout.Height(100f)); if (!text.Equals(mLabel.text)) { mLabel.text = text; } } }
1.把UILabel脚本挂在一个GameObject上
2.UILabelInspector脚本必须放在Editor目录下
工程结构
编辑效果