FairyGUI.DisplayObject.Update C# (CSharp) Method

Update() public method

public Update ( UpdateContext context ) : void
context UpdateContext
return void
        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++;
        }

Usage Example

示例#1
0
        override public void Update(UpdateContext context)
        {
            base.Update(context);

            if (_paintingMode != 0 && paintingGraphics.texture != null)
            {
                context.PushRenderTarget(paintingGraphics.texture, new Vector2(_renderRect.x, _renderRect.y));
            }

            if (_clipRect != null)
            {
                //在这里可以直接使用 _localToWorldMatrix, 因为已经更新
                Rect      clipRect = (Rect)_clipRect;
                Matrix4x4 mat      = Matrix4x4.Identity;
                ToolSet.TransformRect(ref clipRect, ref _localToWorldMatrix, ref mat);
                context.EnterClipping(this.id, clipRect);
            }

            float savedAlpha = context.alpha;

            context.alpha *= this.alpha;
            bool savedGrayed = context.grayed;

            context.grayed = context.grayed || this.grayed;

            int cnt = _children.Count;

            for (int i = 0; i < cnt; i++)
            {
                DisplayObject child = _children[i];
                if (child.visible)
                {
                    child.Update(context);
                }
            }

            if (_clipRect != null)
            {
                context.LeaveClipping();
            }

            if (_paintingMode != 0 && paintingGraphics.texture != null)
            {
                context.PopRenderTarget();
                paintingGraphics.Render(_renderRect, _renderScale, _renderRotation, 1, context);
            }

            context.alpha  = savedAlpha;
            context.grayed = savedGrayed;
        }
All Usage Examples Of FairyGUI.DisplayObject::Update