Unity-自定义编辑器-数据刷新

时间:2020-09-01 08:44:08

标签: unity3d unity-editor

我在编辑器中创建了一个新窗口。它用于调试和创建一些小型测试方案。例如,减少或增加敌人的生命值,减少资源等。 在OnGUI方法中,我创建了一个循环,遍历对手列表并收集有关HP,弹药等的信息。通过GUILayout.Label显示此信息。 不幸的是,该数据不会动态刷新。然后每隔几秒钟或单击一次窗口。 我不知道我是否在使用该编辑器。但是我想有一个部分,该数据将为我动态刷新-并将成为UnityEditor UI的一部分,而不是Game本身。

Editor window screenshoot

2 个答案:

答案 0 :(得分:0)

您可以使用Update

每秒在所有可见窗口上调用多次。

喜欢

when: PX_HOSTNAME|length > 0

但是这可能会变得非常昂贵,我想您也可以使用OnInspectorUpdate

private void Update() { Repaint(); } 以每秒10帧的速度被调用,以使检查员有机会进行更新。

像示例中一样:

OnInspectorUpdate

因此它仅以10帧/秒的速度运行,但是连续运行,如果您不这样做,也是如此。移动鼠标。

Repaint基本上会强制执行一次新的void OnInspectorUpdate() { // Call Repaint on OnInspectorUpdate as it repaints the windows // less times as if it was OnGUI/Update Repaint(); } 运行。

答案 1 :(得分:0)

您可以使用OnInsepctorUpdate(),或者如果您希望某些东西以与游戏相同的速度运行,则可以通过Repaint()方法调用Update()

// This will update your GUI on every frame.
private void Update() => Repaint();
相关问题