Preview窗口除了可以预览模型之外,我们还可以做别的操作。
今天我们来写个小工具在Preview窗口中显示调试信息。
可以看下面的图,同样是打印 health 和 power 的日志,在 Preview 中显示比在 Console 中显示舒服多了。
左边是Console中显示,右边是Preview窗口中显示。
创建Editor目录,然后把下面的脚本放进去
using UnityEngine;
using UnityEditor;
[CustomEditor(typeof(Object), true)]
public class PreviewGUIEditor : Editor {
/** Update every 15th frame. */
private const int updateOnFrame = 15;
private GUIStyle _previewLabelStyle;
private GUIStyle previewLabelStyle {
get {
if (_previewLabelStyle == null) {
_previewLabelStyle = new GUIStyle("PreOverlayLabel") {
richText = false,
alignment = TextAnchor.UpperLeft,
fontStyle = FontStyle.Normal
};
// Try to get a