public virtual void Update(UpdateContext context)
{
if (graphics != null)
{
graphics.alpha = context.alpha * _alpha;
graphics.grayed = context.grayed | _grayed;
graphics.UpdateMaterial(context);
}
if (_paintingMode != 0)
{
NTexture paintingTexture = paintingGraphics.texture;
if (paintingTexture != null && paintingTexture.disposed) //Texture可能已被Stage.MonitorTexture销毁
{
paintingTexture = null;
_paintingFlag = 1;
}
if (_paintingFlag == 1)
{
_paintingFlag = 0;
//从优化考虑,决定使用绘画模式的容器都需要明确指定大小,而不是自动计算包围。这在UI使用上并没有问题,因为组件总是有固定大小的
int textureWidth = Mathf.RoundToInt(_contentRect.width + _paintingMargin.left + _paintingMargin.right);
int textureHeight = Mathf.RoundToInt(_contentRect.height + _paintingMargin.top + _paintingMargin.bottom);
if (paintingTexture == null || paintingTexture.width != textureWidth || paintingTexture.height != textureHeight)
{
if (paintingTexture != null)
paintingTexture.Dispose(true);
if (textureWidth > 0 && textureHeight > 0)
{
paintingTexture = new NTexture(CaptureCamera.CreateRenderTexture(textureWidth, textureHeight, false));
Stage.inst.MonitorTexture(paintingTexture);
}
else
paintingTexture = null;
paintingGraphics.texture = paintingTexture;
}
if (paintingGraphics.material == null)
{
paintingGraphics.material = new Material(ShaderConfig.GetShader(ShaderConfig.imageShader));
paintingGraphics.material.hideFlags = DisplayOptions.hideFlags;
}
if (paintingTexture != null)
{
paintingGraphics.SetOneQuadMesh(
new Rect(-_paintingMargin.left, -_paintingMargin.top, paintingTexture.width, paintingTexture.height),
new Rect(0, 0, 1, 1), Color.white);
}
else
paintingGraphics.ClearMesh();
}
if (paintingTexture != null)
{
paintingTexture.lastActive = Time.time;
if (!(this is Container)) //如果是容器,这句移到Container.Update的最后执行,因为容器中可能也有需要Capture的内容,要等他们完成后再进行容器的Capture。
UpdateContext.OnEnd += _captureDelegate;
}
paintingGraphics.UpdateMaterial(context);
}
if (_filter != null)
_filter.Update();
Stats.ObjectCount++;
}