/// <summary> /// /// </summary> public void Begin() { current = this; frameId++; if (frameId == 0) frameId = 1; renderingOrder = 0; batchingDepth = 0; rectMaskDepth = 0; stencilReferenceValue = 0; alpha = 1; grayed = false; clipped = false; _clipStack.Clear(); Stats.ObjectCount = 0; Stats.GraphicsCount = 0; _tmpBegin = OnBegin; OnBegin = null; //允许OnBegin里再次Add,这里没有做死锁检查 while (_tmpBegin != null) { _tmpBegin.Invoke(); _tmpBegin = OnBegin; OnBegin = null; } working = true; }
public void Update(MovieClip mc, UpdateContext context) { if (_lastUpdateSeq == context.workCount) //PlayState may be shared, only update once per frame return; _lastUpdateSeq = context.workCount; float time = Time.time; float elapsed = time - _lastTime; _lastTime = time; reachEnding = false; frameStarting = false; _curFrameDelay += elapsed; int realFrame = reversed ? mc.frameCount - _curFrame - 1 : _curFrame; float interval = mc.interval + mc.frames[realFrame].addDelay + ((realFrame == 0 && repeatedCount > 0) ? mc.repeatDelay : 0); if (_curFrameDelay < interval) return; _curFrameDelay = 0; _curFrame++; frameStarting = true; if (_curFrame > mc.frameCount - 1) { _curFrame = 0; repeatedCount++; reachEnding = true; if (mc.swing) { reversed = !reversed; _curFrame++; } } }
public override void Update(UpdateContext context, float parentAlpha) { if (_needRebuild) Rebuild(); if (quadBatch != null) quadBatch.Update(context, parentAlpha * alpha); }
public Stage() : base() { _inst = this; soundVolume = 1; _updateContext = new UpdateContext(); stageWidth = Screen.width; stageHeight = Screen.height; _frameGotHitTarget = -1; touchScreen = Input.touchSupported; _touches = new TouchInfo[5]; for (int i = 0; i < _touches.Length; i++) _touches[i] = new TouchInfo(); if (!touchScreen) _touches[0].touchId = 0; _rollOutChain = new List<DisplayObject>(); _rollOverChain = new List<DisplayObject>(); onStageResized = new EventListener(this, "onStageResized"); onTouchMove = new EventListener(this, "onTouchMove"); onCopy = new EventListener(this, "onCopy"); onPaste = new EventListener(this, "onPaste"); StageEngine engine = GameObject.FindObjectOfType<StageEngine>(); if (engine != null) this.gameObject = engine.gameObject; else { int layer = LayerMask.NameToLayer(StageCamera.LayerName); this.gameObject = new GameObject("Stage"); this.gameObject.hideFlags = HideFlags.None; this.gameObject.layer = layer; this.gameObject.AddComponent<StageEngine>(); this.gameObject.AddComponent<UIContentScaler>(); } this.cachedTransform = gameObject.transform; this.cachedTransform.localScale = new Vector3(StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel, StageCamera.UnitsPerPixel); this.gameObject.SetActive(true); UnityEngine.Object.DontDestroyOnLoad(this.gameObject); EnableSound(); inputCaret = new InputCaret(); highlighter = new Highlighter(); Timers.inst.Add(5, 0, RunTextureCollector); #if UNITY_WEBPLAYER || UNITY_WEBGL || UNITY_STANDALONE_WIN || UNITY_STANDALONE_OSX || UNITY_EDITOR CopyPastePatch.Apply(); #endif }
public void Update(MovieClip mc, UpdateContext context) { if (_lastUpdateFrameId == UpdateContext.frameId) //PlayState may be shared, only update once per frame return; _lastUpdateFrameId = UpdateContext.frameId; float time = Time.time; float elapsed = time - _lastTime; if (ignoreTimeScale && Time.timeScale != 0) elapsed /= Time.timeScale; _lastTime = time; reachEnding = false; _curFrameDelay += elapsed; float interval = mc.interval + mc.frames[_curFrame].addDelay + ((_curFrame == 0 && repeatedCount > 0) ? mc.repeatDelay : 0); if (_curFrameDelay < interval) return; _curFrameDelay = 0; if (mc.swing) { if (reversed) { _curFrame--; if (_curFrame < 0) { _curFrame = Mathf.Min(1, mc.frameCount - 1); repeatedCount++; reversed = !reversed; } } else { _curFrame++; if (_curFrame > mc.frameCount - 1) { _curFrame = Mathf.Max(0, mc.frameCount - 2); repeatedCount++; reachEnding = true; reversed = !reversed; } } } else { _curFrame++; if (_curFrame > mc.frameCount - 1) { _curFrame = 0; repeatedCount++; reachEnding = true; } } }
static public int LeaveClipping(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); self.LeaveClipping(); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int get_clipped(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); pushValue(l, true); pushValue(l, self.clipped); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int constructor(IntPtr l) { try { FairyGUI.UpdateContext o; o = new FairyGUI.UpdateContext(); pushValue(l, true); pushValue(l, o); return(2); } catch (Exception e) { return(error(l, e)); } }
static public int set_clipped(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); System.Boolean v; checkType(l, 2, out v); self.clipped = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_stencilReferenceValue(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); System.Int32 v; checkType(l, 2, out v); self.stencilReferenceValue = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_alpha(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); System.Single v; checkType(l, 2, out v); self.alpha = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static public int set_clipInfo(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); FairyGUI.UpdateContext.ClipInfo v; checkValueType(l, 2, out v); self.clipInfo = v; pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
static int EM_Update(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); FairyGUI.UIPainter obj = (FairyGUI.UIPainter)ToLua.CheckObject(L, 1, typeof(FairyGUI.UIPainter)); FairyGUI.UpdateContext arg0 = (FairyGUI.UpdateContext)ToLua.CheckObject(L, 2, typeof(FairyGUI.UpdateContext)); obj.EM_Update(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Update(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); FairyGUI.Container obj = (FairyGUI.Container)ToLua.CheckObject <FairyGUI.Container>(L, 1); FairyGUI.UpdateContext arg0 = (FairyGUI.UpdateContext)ToLua.CheckObject <FairyGUI.UpdateContext>(L, 2); obj.Update(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Update(IntPtr L) { try { ToLua.CheckArgsCount(L, 3); FairyGUI.PlayState obj = (FairyGUI.PlayState)ToLua.CheckObject <FairyGUI.PlayState>(L, 1); FairyGUI.MovieClip arg0 = (FairyGUI.MovieClip)ToLua.CheckObject <FairyGUI.MovieClip>(L, 2); FairyGUI.UpdateContext arg1 = (FairyGUI.UpdateContext)ToLua.CheckObject <FairyGUI.UpdateContext>(L, 3); obj.Update(arg0, arg1); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static public int EnterClipping(IntPtr l) { try { FairyGUI.UpdateContext self = (FairyGUI.UpdateContext)checkSelf(l); System.UInt32 a1; checkType(l, 2, out a1); System.Nullable <UnityEngine.Rect> a2; checkNullable(l, 3, out a2); System.Nullable <UnityEngine.Vector4> a3; checkNullable(l, 4, out a3); self.EnterClipping(a1, a2, a3); pushValue(l, true); return(1); } catch (Exception e) { return(error(l, e)); } }
public override void Update(UpdateContext context) { if (_requireUpdateMesh) { _requireUpdateMesh = false; if (_type != 0) { if (_contentRect.width > 0 && _contentRect.height > 0) { if (_type == 1) graphics.DrawRect(_contentRect, _lineSize, _lineColor, _fillColor); else graphics.DrawEllipse(_contentRect, _fillColor); } else graphics.ClearMesh(); } } base.Update(context); }
private void SetRenderingOrder(UpdateContext context) { if (_fBatchingRequested) DoFairyBatching(); if (_mask != null) _mask.renderingOrder = context.renderingOrder++; int cnt = _descendants.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _descendants[i]; if (child != _mask) child.renderingOrder = context.renderingOrder++; if ((child is Container) && ((Container)child)._fBatchingRoot) ((Container)child).SetRenderingOrder(context); } if (_mask != null && _mask.graphics != null) _mask.graphics.SetStencilEraserOrder(context.renderingOrder++); }
public Material GetContextMaterial(UpdateContext context) { if (!context.clipped) return sharedMaterial; Material mat; if (context.clipInfo.soft) { if (context.workCount != _softUpdateSeq) { _softUpdateSeq = context.workCount; _softClipId = context.clipInfo.clipId; _softNextIndex = 0; } else if (_softClipId != context.clipInfo.clipId) { _softNextIndex++; _softClipId = context.clipInfo.clipId; } if (_softClippedMaterials == null) _softClippedMaterials = new List<Material>(); if (_softNextIndex < _softClippedMaterials.Count) mat = _softClippedMaterials[_softNextIndex]; else { Shader shader = ShaderConfig.Get(sharedMaterial.shader.name + ShaderConfig.softClipShaderSuffix); if (shader == null) { Debug.LogWarning("FairyGUI: " + sharedMaterial.shader.name + " doesn't have a soft clipped shader version for clipping"); shader = sharedMaterial.shader; } mat = new Material(shader); mat.mainTexture = sharedMaterial.mainTexture; if (_owner.alphaTexture != null) mat.SetTexture("_AlphaTex", _owner.alphaTexture); _softClippedMaterials.Add(mat); } mat.mainTextureOffset = context.clipInfo.offset; mat.mainTextureScale = context.clipInfo.scale; mat.SetVector("_ClipSharpness", context.clipInfo.softness); } else { if (context.workCount != _updateSeq) { _updateSeq = context.workCount; _clipId = context.clipInfo.clipId; _nextIndex = 0; } else if (_clipId != context.clipInfo.clipId) { _nextIndex++; _clipId = context.clipInfo.clipId; } if (_clippedMaterials == null) _clippedMaterials = new List<Material>(); if (_nextIndex < _clippedMaterials.Count) mat = _clippedMaterials[_nextIndex]; else { Shader shader = ShaderConfig.Get(sharedMaterial.shader.name + ShaderConfig.alphaClipShaderSuffix); if (shader == null) { Debug.LogWarning("FairyGUI: " + sharedMaterial.shader.name + " doesn't have a clipped shader version for clipping"); shader = sharedMaterial.shader; } mat = new Material(shader); mat.mainTexture = sharedMaterial.mainTexture; if (_owner.alphaTexture != null) mat.SetTexture("_AlphaTex", _owner.alphaTexture); _clippedMaterials.Add(mat); } mat.mainTextureOffset = context.clipInfo.offset; mat.mainTextureScale = context.clipInfo.scale; } return mat; }
public override void Update(UpdateContext context) { if (_disabled) return; if (onUpdate != null) onUpdate(); base.Update(context); if (_mask != null) context.EnterClipping(this.id, null, null); else if (_clipRect != null) context.EnterClipping(this.id, this.TransformRect((Rect)_clipRect, null), clipSoftness); float savedAlpha = context.alpha; context.alpha *= this.alpha; bool savedGrayed = context.grayed; context.grayed = context.grayed || this.grayed; if (_fBatching) context.batchingDepth++; if (context.batchingDepth > 0) { if (_mask != null) _mask.graphics.maskFrameId = UpdateContext.frameId; int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) child.Update(context); } } else { if (_mask != null) { _mask.graphics.maskFrameId = UpdateContext.frameId; _mask.renderingOrder = context.renderingOrder++; } int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) { if (child != _mask) child.renderingOrder = context.renderingOrder++; child.Update(context); } } if (_mask != null) _mask.graphics.SetStencilEraserOrder(context.renderingOrder++); } if (_fBatching) { if (context.batchingDepth == 1) SetRenderingOrder(context); context.batchingDepth--; } context.alpha = savedAlpha; context.grayed = savedGrayed; if (_clipRect != null || _mask != null) context.LeaveClipping(); if (_paintingMode > 0 && paintingGraphics.texture != null) UpdateContext.OnEnd += _captureDelegate; }
public virtual void Update(UpdateContext context, float parentAlpha) { }
public override void Update(UpdateContext context) { if (_mobileInputAdapter != null) { if (_mobileInputAdapter.done) { UpdateContext.OnEnd += () => { //将促使一个onFocusOut事件的调用。如果不focus-out,则在键盘关闭后,玩家再次点击文本,focus-in不会触发,键盘不会打开 //另外也使开发者有机会得到一个键盘关闭的通知 Stage.inst.focus = null; }; } string s = _mobileInputAdapter.GetInput(); if (s != null && s != _text) { if (s.Length > _maxLength) s = s.Substring(0, _maxLength); this.text = s; UpdateContext.OnEnd += () => { onChanged.Call(); }; } } if (_caret != null) { string s = Input.inputString; if (!string.IsNullOrEmpty(s)) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.Length; ++i) { char ch = s[i]; if (ch >= ' ') sb.Append(ch.ToString()); } if (sb.Length > 0) { s = sb.ToString(); if (_text.Length + s.Length > _maxLength) s = s.Substring(0, _text.Length - maxLength); InsertText(s); } } } if (_font != null) { if (_font.mainTexture != graphics.texture) { if (!_textChanged) RequestText(); graphics.texture = _font.mainTexture; _requireUpdateMesh = true; } if (_textChanged) BuildLines(); if (_requireUpdateMesh) BuildMesh(); } if (_input) { Rect rect = _contentRect; rect.x += GUTTER_X; rect.y += GUTTER_Y; rect.width -= GUTTER_X * 2; rect.height -= GUTTER_Y * 2; context.EnterClipping(this.id, this.TransformRect(rect, null), null); base.Update(context); if (_highlighter != null) _highlighter.grahpics.UpdateMaterial(context); context.LeaveClipping(); if (_caret != null) //不希望光标发生剪切,所以放到LeaveClipping后 { _caret.grahpics.UpdateMaterial(context); _caret.Blink(); } } else base.Update(context); }
void CaptureInEditMode() { if (!EMRenderSupport.packageListReady || UIPackage.GetByName(packageName) == null) return; _captured = true; UIObjectFactory.packageItemExtensions.Clear(); UIObjectFactory.loaderConstructor = null; DisplayOptions.SetEditModeHideFlags(); GComponent view = (GComponent)UIPackage.CreateObject(packageName, componentName); if (view != null) { DestroyTexture(); _texture = CaptureCamera.CreateRenderTexture(Mathf.RoundToInt(view.width), Mathf.RoundToInt(view.height), false); Container root = (Container)view.displayObject; root.layer = CaptureCamera.layer; root.SetChildrenLayer(CaptureCamera.layer); root.gameObject.hideFlags = HideFlags.None; root.gameObject.SetActive(true); GameObject cameraObject = new GameObject("Temp Capture Camera"); Camera camera = cameraObject.AddComponent<Camera>(); camera.depth = 0; camera.cullingMask = 1 << CaptureCamera.layer; camera.clearFlags = CameraClearFlags.Depth; camera.orthographic = true; camera.nearClipPlane = -30; camera.farClipPlane = 30; camera.enabled = false; camera.targetTexture = _texture; float halfHeight = (float)_texture.height / 2; camera.orthographicSize = halfHeight; cameraObject.transform.localPosition = root.cachedTransform.TransformPoint(halfHeight * camera.aspect, -halfHeight, 0); UpdateContext context = new UpdateContext(); //run two times context.Begin(); view.displayObject.Update(context); context.End(); context.Begin(); view.displayObject.Update(context); context.End(); RenderTexture old = RenderTexture.active; RenderTexture.active = _texture; GL.Clear(true, true, Color.clear); camera.Render(); RenderTexture.active = old; camera.targetTexture = null; view.Dispose(); GameObject.DestroyImmediate(cameraObject); if (_renderer != null) _renderer.sharedMaterial.mainTexture = _texture; } }
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++; }
public override void Update(UpdateContext context) { if (_mobileInputAdapter != null) { if (_mobileInputAdapter.done) UpdateContext.OnEnd += inputCompleteDelegate; string s = _mobileInputAdapter.GetInput(); if (s != null && s != _text) { s = ValidateInput(s); if (s.Length > _maxLength) s = s.Substring(0, _maxLength); this.text = s; UpdateContext.OnEnd += _onChangedDelegate; } } if (_caret != null) { if (!string.IsNullOrEmpty(Input.inputString)) { StringBuilder sb = new StringBuilder(); int len = Input.inputString.Length; for (int i = 0; i < len; ++i) { char ch = Input.inputString[i]; if (ch >= ' ') sb.Append(ch.ToString()); } if (sb.Length > 0) { InsertText(sb.ToString()); UpdateContext.OnEnd += _onChangedDelegate; } } } if (_font != null) { if (_font.mainTexture != graphics.texture) { if (!_textChanged) RequestText(); graphics.texture = _font.mainTexture; _requireUpdateMesh = true; } if (_textChanged) BuildLines(); if (_requireUpdateMesh) BuildMesh(); } if (_input && richTextField == null) { _BeforeClip(context); base.Update(context); _AfterClip(context); } else base.Update(context); }
public void EM_Update(UpdateContext context) { DisplayOptions.SetEditModeHideFlags(); container.Update(context); if (setNativeChildrenOrder) { CacheNativeChildrenRenderers(); int cnt = _renders.Count; int sv = context.renderingOrder++; for (int i = 0; i < cnt; i++) { Renderer r = _renders[i]; if (r != null) r.sortingOrder = sv; } } }
/// <summary> /// /// </summary> /// <param name="context"></param> public void UpdateMaterial(UpdateContext context) { Stats.GraphicsCount++; NMaterial nm = null; if (_manager != null && !_customMatarial) { nm = _manager.GetMaterial(this, context); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial && (object)_material.mainTexture != null) meshRenderer.sharedMaterial = _material; if (nm.combined) _material.SetTexture("_AlphaTex", _manager.texture.alphaTexture.nativeTexture); } if (maskFrameId != 0 && maskFrameId != UpdateContext.frameId) { //曾经是遮罩对象,现在不是了 if (_stencilEraser != null) _stencilEraser.enabled = false; } if (_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 BlendModeUtils.Apply(_material, blendMode); bool clearStencil = false; if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) //在矩形剪裁下,且不是遮罩对象 { _material.SetVector("_ClipBox", context.clipInfo.clipBox); if (context.clipInfo.soft) _material.SetVector("_ClipSoftness", context.clipInfo.softness); } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) //是遮罩 { if (context.stencilReferenceValue == 1) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 1); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 0); } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", context.stencilReferenceValue - 1); _material.SetInt("_ColorMask", 0); } //设置擦除stencil的drawcall if (_stencilEraser == null) { _stencilEraser = new StencilEraser(gameObject.transform); _stencilEraser.meshFilter.mesh = mesh; } else _stencilEraser.enabled = true; if (nm != null) { NMaterial eraserNm = _manager.GetMaterial(this, context); eraserNm.stencilSet = true; Material eraserMat = eraserNm.material; if ((object)eraserMat != (object)_stencilEraser.meshRenderer.sharedMaterial) _stencilEraser.meshRenderer.sharedMaterial = eraserMat; int refValue = context.stencilReferenceValue - 1; eraserMat.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); eraserMat.SetInt("_Stencil", refValue); eraserMat.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); eraserMat.SetInt("_StencilReadMask", refValue); eraserMat.SetInt("_ColorMask", 0); } } else { int refValue = context.stencilReferenceValue | (context.stencilReferenceValue - 1); _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", refValue); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", refValue); _material.SetInt("_ColorMask", 15); } if (nm != null) nm.stencilSet = true; } else clearStencil = nm == null || nm.stencilSet; } else clearStencil = nm == null || nm.stencilSet; if (clearStencil) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); } } }
override public void Update(UpdateContext context) { if (_disabled) { return; } if (onUpdate != null) { onUpdate(); } base.Update(context); if (_mask != null) { context.EnterClipping(this.id, null, null); } else if (_clipRect != null) { context.EnterClipping(this.id, this.TransformRect((Rect)_clipRect, null), clipSoftness); } float savedAlpha = context.alpha; context.alpha *= this.alpha; bool savedGrayed = context.grayed; context.grayed = context.grayed || this.grayed; if (_fBatching) { context.batchingDepth++; } if (context.batchingDepth > 0) { if (_mask != null) { _mask.graphics.maskFrameId = UpdateContext.frameId; } int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) { child.Update(context); } } } else { if (_mask != null) { _mask.graphics.maskFrameId = UpdateContext.frameId; _mask.renderingOrder = context.renderingOrder++; } int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if (child.visible) { if (child != _mask) { child.renderingOrder = context.renderingOrder++; } child.Update(context); } } if (_mask != null) { _mask.graphics.SetStencilEraserOrder(context.renderingOrder++); } } if (_fBatching) { if (context.batchingDepth == 1) { SetRenderingOrder(context); } context.batchingDepth--; } context.alpha = savedAlpha; context.grayed = savedGrayed; if (_clipRect != null || _mask != null) { context.LeaveClipping(); } if (_paintingMode > 0 && paintingGraphics.texture != null) { UpdateContext.OnEnd += _captureDelegate; } }
public override void Update(UpdateContext context) { if (_requireUpdateMesh) Rebuild(); base.Update(context); }
internal void _AfterClip(UpdateContext context) { if (_highlighter != null) _highlighter.grahpics.UpdateMaterial(context); context.LeaveClipping(); if (_caret != null) //不希望光标发生剪切,所以放到LeaveClipping后 { _caret.grahpics.UpdateMaterial(context); _caret.Blink(); } }
override public void Update(UpdateContext context) { if ((_flags & Flags.UserGameObject) != 0 && !gameObject.activeInHierarchy) { return; } base.Update(context); if (_paintingMode != 0) { if ((_flags & Flags.CacheAsBitmap) != 0 && _paintingInfo.flag == 2) { if (onUpdate != null) { onUpdate(); } return; } context.EnterPaintingMode(); } if (_mask != null) { context.EnterClipping(this.id, reversedMask); if (_mask.graphics != null) { _mask.graphics._PreUpdateMask(context, _mask.id); } } else if (_clipRect != null) { context.EnterClipping(this.id, this.TransformRect((Rect)_clipRect, null), clipSoftness); } float savedAlpha = context.alpha; context.alpha *= this.alpha; bool savedGrayed = context.grayed; context.grayed = context.grayed || this.grayed; if ((_flags & Flags.FairyBatching) != 0) { context.batchingDepth++; } if (context.batchingDepth > 0) { int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if ((child._flags & Flags.GameObjectDisposed) != 0) { child.DisplayDisposedWarning(); continue; } if (child.visible) { child.Update(context); } } } else { if (_mask != null) { _mask.renderingOrder = context.renderingOrder++; } int cnt = _children.Count; for (int i = 0; i < cnt; i++) { DisplayObject child = _children[i]; if ((child._flags & Flags.GameObjectDisposed) != 0) { child.DisplayDisposedWarning(); continue; } if (child.visible) { if (!(child.graphics != null && child.graphics._maskFlag == 1)) //if not a mask { child.renderingOrder = context.renderingOrder++; } child.Update(context); } } if (_mask != null) { if (_mask.graphics != null) { _mask.graphics._SetStencilEraserOrder(context.renderingOrder++); } } } if ((_flags & Flags.FairyBatching) != 0) { if (context.batchingDepth == 1) { SetRenderingOrder(context); } context.batchingDepth--; } context.alpha = savedAlpha; context.grayed = savedGrayed; if (_clipRect != null || _mask != null) { context.LeaveClipping(); } if (_paintingMode != 0) { context.LeavePaintingMode(); UpdateContext.OnEnd += _paintingInfo.captureDelegate; } if (onUpdate != null) { onUpdate(); } }
public NMaterial GetMaterial(NGraphics grahpics, UpdateContext context) { frameId = UpdateContext.frameId; blendMode = grahpics.blendMode; int pool; if (context.clipped) { clipId = context.clipInfo.clipId; if (grahpics.maskFrameId == UpdateContext.frameId) pool = 6; else if (context.rectMaskDepth == 0) { if (grahpics.grayed) pool = 1; else pool = 0; } else { if (context.clipInfo.soft) { if (grahpics.grayed) pool = 5; else pool = 4; } else { if (grahpics.grayed) pool = 3; else pool = 2; } } } else { clipId = 0; if (grahpics.grayed) pool = 1; else pool = 0; } return _pools[pool].Get(); }
public void UpdateMaterial(UpdateContext context) { if (_manager != null && !_customMatarial) { _material = _manager.GetMaterial(this, context); if ((object)_material != (object)meshRenderer.sharedMaterial && (object)_material.mainTexture != null) meshRenderer.sharedMaterial = _material; } if (_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 BlendModeUtils.Apply(_material, blendMode); if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) { _material.SetVector("_ClipBox", context.clipInfo.clipBox); if (context.clipInfo.soft) _material.SetVector("_ClipSoftness", context.clipInfo.softness); } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) { if (context.stencilReferenceValue == 1) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 1); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 0); } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", context.stencilReferenceValue - 1); _material.SetInt("_ColorMask", 0); } } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_ColorMask", 15); } if (_material is NMaterial) ((NMaterial)_material).stencilSet = true; } else if ((_material is NMaterial) && ((NMaterial)_material).stencilSet) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); ((NMaterial)_material).stencilSet = false; } } } }
/// <summary> /// /// </summary> /// <param name="context"></param> public void UpdateMaterial(UpdateContext context) { Stats.GraphicsCount++; NMaterial nm = null; if (_manager != null && !_customMatarial) { nm = _manager.GetMaterial(this, context); _material = nm.material; if ((object)_material != (object)meshRenderer.sharedMaterial && (object)_material.mainTexture != null) { meshRenderer.sharedMaterial = _material; } if (nm.combined) { _material.SetTexture("_AlphaTex", _manager.texture.alphaTexture.nativeTexture); } } if (maskFrameId != 0 && maskFrameId != UpdateContext.frameId) { //曾经是遮罩对象,现在不是了 if (_stencilEraser != null) { _stencilEraser.enabled = false; } } if (_material != null) { if (blendMode != BlendMode.Normal) //GetMateria已经保证了不同的blendMode会返回不同的共享材质,所以这里可以放心设置 { BlendModeUtils.Apply(_material, blendMode); } bool clearStencil = false; if (context.clipped) { if (maskFrameId != UpdateContext.frameId && context.rectMaskDepth > 0) //在矩形剪裁下,且不是遮罩对象 { _material.SetVector("_ClipBox", context.clipInfo.clipBox); if (context.clipInfo.soft) { _material.SetVector("_ClipSoftness", context.clipInfo.softness); } } if (context.stencilReferenceValue > 0) { if (maskFrameId == UpdateContext.frameId) //是遮罩 { if (context.stencilReferenceValue == 1) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 1); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 0); } else { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", context.stencilReferenceValue | (context.stencilReferenceValue - 1)); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); _material.SetInt("_StencilReadMask", context.stencilReferenceValue - 1); _material.SetInt("_ColorMask", 0); } //设置擦除stencil的drawcall if (_stencilEraser == null) { _stencilEraser = new StencilEraser(gameObject.transform); _stencilEraser.meshFilter.mesh = mesh; } else { _stencilEraser.enabled = true; } if (nm != null) { NMaterial eraserNm = _manager.GetMaterial(this, context); eraserNm.stencilSet = true; Material eraserMat = eraserNm.material; if ((object)eraserMat != (object)_stencilEraser.meshRenderer.sharedMaterial) { _stencilEraser.meshRenderer.sharedMaterial = eraserMat; } int refValue = context.stencilReferenceValue - 1; eraserMat.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); eraserMat.SetInt("_Stencil", refValue); eraserMat.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Replace); eraserMat.SetInt("_StencilReadMask", refValue); eraserMat.SetInt("_ColorMask", 0); } } else { int refValue = context.stencilReferenceValue | (context.stencilReferenceValue - 1); _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Equal); _material.SetInt("_Stencil", refValue); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", refValue); _material.SetInt("_ColorMask", 15); } if (nm != null) { nm.stencilSet = true; } } else { clearStencil = nm == null || nm.stencilSet; } } else { clearStencil = nm == null || nm.stencilSet; } if (clearStencil) { _material.SetInt("_StencilComp", (int)UnityEngine.Rendering.CompareFunction.Always); _material.SetInt("_Stencil", 0); _material.SetInt("_StencilOp", (int)UnityEngine.Rendering.StencilOp.Keep); _material.SetInt("_StencilReadMask", 255); _material.SetInt("_ColorMask", 15); } } }
public override void Update(UpdateContext context) { if (_requireUpdateMesh) { _requireUpdateMesh = false; if (_rects != null && _rects.Count > 0) { int count = _rects.Count * 4; graphics.Alloc(count); Rect uvRect = new Rect(0, 0, 1, 1); for (int i = 0; i < count; i += 4) { graphics.FillVerts(i, _rects[i / 4]); graphics.FillUV(i, uvRect); } graphics.FillColors(_color); graphics.FillTriangles(); graphics.UpdateMesh(); } else graphics.ClearMesh(); } base.Update(context); }
public virtual void Update(UpdateContext context, float alpha) { if ((System.Object)meshFilter == null || _manager == null || (System.Object)mesh == null) return; if (_colorChanged || _alpha != alpha) { _colorChanged = false; _alpha = alpha; Color32[] cols = mesh.colors32; int count = cols.Length; for (int i = 0; i < count; i++) { Color32 col = cols[i]; int j = i / 4; col.a = (byte)(_alpha * quadAlpha[j]); cols[i] = col; } mesh.colors32 = cols; } Material mat; if ((System.Object)_material != null) mat = _material; else mat = _manager.GetContextMaterial(context); if ((System.Object)mat != (System.Object)meshRenderer.sharedMaterial && (System.Object)mat.mainTexture != null) meshRenderer.sharedMaterial = mat; }
public override void Update(UpdateContext context) { if (_font != null) { if (_font.keepCrisp && _renderScale != UIContentScaler.scaleFactor) _textChanged = true; if (_font.mainTexture != graphics.texture) { if (!_textChanged) RequestText(); graphics.texture = _font.mainTexture; _requireUpdateMesh = true; } if (_textChanged) BuildLines(); if (_requireUpdateMesh) BuildMesh(); } base.Update(context); }
public void EM_Update(UpdateContext context) { container.Update(context); }
public override void Update(UpdateContext context, float parentAlpha) { if (_needRebuild) Rebuild(); if (_playing && frameCount != 0 && _status != 3) { playState.Update(this, context); if (_currentFrame != playState.currrentFrame) { if (_status == 1) { _currentFrame = _start; playState.currrentFrame = _currentFrame; _status = 0; } else if (_status == 2) { _currentFrame = _endAt; playState.currrentFrame = _currentFrame; _status = 3; Stage.inst.onPostUpdate.Add(__playEnd); } else { _currentFrame = playState.currrentFrame; if (_currentFrame == _end) { if (_times > 0) { _times--; if (_times == 0) _status = 2; else _status = 1; } } } quadBatch.SetQuadAlpha(_currentFrame, 1, 1f, 0f); } } quadBatch.Update(context, alpha * parentAlpha); }
internal void _BeforeClip(UpdateContext context) { Rect rect = _contentRect; rect.x += GUTTER_X; rect.y += GUTTER_Y; rect.width -= GUTTER_X * 2; if (richTextField != null) context.EnterClipping(this.id, richTextField.TransformRect(rect, null), null); else context.EnterClipping(this.id, this.TransformRect(rect, null), null); }
public override void Update(UpdateContext context) { if (textField.input) { textField._BeforeClip(context); base.Update(context); textField._AfterClip(context); } else base.Update(context); }
public override void Update(UpdateContext context) { base.Update(context); if (_editing) { if (_nextBlink < Time.time) { _nextBlink = Time.time + 0.5f; _caret.graphics.enabled = !_caret.graphics.enabled; } } }
public override void Update(UpdateContext context, float parentAlpha) { if (_mobileInputAdapter != null) { string s = _mobileInputAdapter.GetInput(); if (s != null && s != _text) this.text = s; } if (_caret != null) { string s = Input.inputString; if (!string.IsNullOrEmpty(s)) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < s.Length; ++i) { char ch = s[i]; if (ch >= ' ') sb.Append(ch.ToString()); } if (sb.Length > 0) InsertText(sb.ToString()); } } if (_font != null) { if (_font.mainTexture != quadBatch.texture) { if (!_textChanged) RequestText(); quadBatch.texture = _font.mainTexture; _meshChanged = true; } if (_textChanged) Wrap(); if (_meshChanged) RebuildMesh(); if (_rectchanged) ApplyClip(); } quadBatch.Update(context, parentAlpha * alpha); }
public override void Update(UpdateContext context) { if (_playing && frameCount != 0 && _status != 3) { playState.Update(this, context); if (_forceDraw || _currentFrame != playState.currrentFrame) { if (_status == 1) { _currentFrame = _start; playState.currrentFrame = _currentFrame; _status = 0; } else if (_status == 2) { _currentFrame = _endAt; playState.currrentFrame = _currentFrame; _status = 3; UpdateContext.OnEnd += _playEndDelegate; } else { _currentFrame = playState.currrentFrame; if (_currentFrame == _end) { if (_times > 0) { _times--; if (_times == 0) _status = 2; else _status = 1; } } } DrawFrame(); } } else if(_forceDraw) DrawFrame(); base.Update(context); }
/// <summary> /// /// </summary> /// <param name="context"></param> /// <param name="alpha"></param> /// <param name="grayed"></param> public void Update(UpdateContext context, float alpha, bool grayed) { Stats.GraphicsCount++; if (_meshDirty) { _alpha = alpha; UpdateMeshNow(); } else if (_alpha != alpha) { ChangeAlpha(alpha); } if (_propertyBlock != null && _blockUpdated) { meshRenderer.SetPropertyBlock(_propertyBlock); _blockUpdated = false; } if (_customMatarial != 0) { if ((_customMatarial & 2) != 0 && _material != null) { context.ApplyClippingProperties(_material, false); } } else { if (_manager != null) { if (_maskFlag == 1) { _material = _manager.GetMaterial((int)MaterialFlags.AlphaMask | _materialFlags, BlendMode.Normal, context.clipInfo.clipId); context.ApplyAlphaMaskProperties(_material, false); } else { int matFlags = _materialFlags; if (grayed) { matFlags |= (int)MaterialFlags.Grayed; } if (context.clipped) { if (context.stencilReferenceValue > 0) { matFlags |= (int)MaterialFlags.StencilTest; } if (context.rectMaskDepth > 0) { if (context.clipInfo.soft) { matFlags |= (int)MaterialFlags.SoftClipped; } else { matFlags |= (int)MaterialFlags.Clipped; } } _material = _manager.GetMaterial(matFlags, blendMode, context.clipInfo.clipId); if (_manager.firstMaterialInFrame) { context.ApplyClippingProperties(_material, true); } } else { _material = _manager.GetMaterial(matFlags, blendMode, 0); } } } else { _material = null; } if (!Material.ReferenceEquals(_material, meshRenderer.sharedMaterial)) { meshRenderer.sharedMaterial = _material; } } if (_maskFlag != 0) { if (_maskFlag == 1) { _maskFlag = 2; } else { if (_stencilEraser != null) { _stencilEraser.enabled = false; } _maskFlag = 0; } } }