我正在创建一个系统来平衡EditorWindow的OnGUI方法内部的调用。我正在做以下工作:
public void Update()
{
Repaint();
}
在我的OnGUI方法里面我调用这个Balancer.我有一个回调列表(List).所以这个想法很简单,有些callvaxc我跳过了一些repaint帧,为有完整GUI的回调调用,并为其他回调调用每个repaint(例如,一个字幕标签或显示gif).
由于某种原因,发生了此错误"重新绘制时,在仅包含0个控件的组中获取控件0的位置"
private int m_repaintCounter;
public void Draw()
{
Event e = Event.current;
try
{
foreach (var action in m_actions)
{
try
{
// Test 1
// MainAction is a class that inherits from Action (class MainAction : Action)
if (action is MainAction)
{
bool isDesignedType = e.rawType == EventType.Repaint || e.rawType == EventType.Layout;
if (isDesignedType)
++m_repaintCounter;
if (!(m_repaintCounter == 20 && isDesignedType))
continue;
else
m_repaintCounter = 0;
}
// Test 2
action.Value();
}
catch (Exception ex)
{
Debug.LogException(ex);
}
}
}
catch
{
// Due to recompile the collection will modified, so we need to avoid the exception
}
}
但如果我评论"测试1",一切都很好。
在类的ctor
上,我们需要指定对GUI方法的回调,例如:
public Balancer(Action drawAction)
{
m_actions = new List<Action>();
m_actions.Add(drawAction);
}
因此,我们可以轻松地(在EditorWindow
内部):
一个三个三个一个
我想不出来。我在网上找不到任何信息。有人能帮我吗?
1条答案
按热度按时间8yparm6h1#
好吧,
OnGui
(IMGui)很难用,如果你不想用它来编辑脚本,那就用新的4.6 UI(UGui)来代替。好了,问题来了。
OnGui每帧至少被调用两次,其中一次是计算布局,另一次是实际绘制东西(“重画”)。
也就是说:在Layout之后和Repaint之前,您无法在IMGui系统中更改UI状态。
仅,仅,***仅***更改状态(从而绘制哪些对象),并且仅,仅,***仅***改变下一帧的状态(或者,在
Event.current == EventType.Layout
期间进行更改,前提是此相同的新状态将在重画期间导致相同的代码路径)。在任何情况下,在重画过程中进行先前布局中不存在的更改。