protected virtual void OnEnable() { if (GetComponent <Mask>() != null) { MaskUtilities.NotifyStencilStateChanged(this); } }
protected override void OnEnable() { base.OnEnable(); if (graphic != null) { graphic.canvasRenderer.hasPopInstruction = true; graphic.SetMaterialDirty(); } MaskUtilities.NotifyStencilStateChanged(this); }
protected override void OnValidate() { base.OnValidate(); if (!IsActive()) { return; } if (graphic != null) { graphic.SetMaterialDirty(); } MaskUtilities.NotifyStencilStateChanged(this); }
public static int NotifyStencilStateChanged_s(IntPtr l) { int result; try { Component mask; LuaObject.checkType <Component>(l, 1, out mask); MaskUtilities.NotifyStencilStateChanged(mask); LuaObject.pushValue(l, true); result = 1; } catch (Exception e) { result = LuaObject.error(l, e); } return(result); }
/// <summary> /// Update all soft mask textures. /// </summary> static void UpdateMaskTextures() { foreach (var sm in s_ActiveSoftMasks) { if (!sm || sm._hasChanged) { continue; } var rt = sm.rectTransform; if (rt.hasChanged) { rt.hasChanged = false; sm.hasChanged = true; } #if UNITY_EDITOR if (!Application.isPlaying) { sm.hasChanged = true; } #endif } foreach (var sm in s_ActiveSoftMasks) { if (!sm || !sm._hasChanged) { continue; } sm._hasChanged = false; if (!sm._parent) { sm.UpdateMaskTexture(); if (sm._hasStencilStateChanged) { sm._hasStencilStateChanged = false; MaskUtilities.NotifyStencilStateChanged(sm); } } } }
protected override void OnDisable() { // we call base OnDisable first here // as we need to have the IsActive return the // correct value when we notify the children // that the mask state has changed. base.OnDisable(); if (graphic != null) { graphic.SetMaterialDirty(); graphic.canvasRenderer.hasPopInstruction = false; graphic.canvasRenderer.popMaterialCount = 0; } StencilMaterial.Remove(m_MaskMaterial); m_MaskMaterial = null; StencilMaterial.Remove(m_UnmaskMaterial); m_UnmaskMaterial = null; MaskUtilities.NotifyStencilStateChanged(this); }
/// <summary> /// Update all soft mask textures. /// </summary> private static void UpdateMaskTextures() { Profiler.BeginSample("UpdateMaskTextures"); foreach (var sm in s_ActiveSoftMasks) { if (!sm || sm._hasChanged) { continue; } var canvas = sm.graphic.canvas; if (!canvas) { continue; } if (canvas.renderMode == RenderMode.WorldSpace) { var cam = canvas.worldCamera; if (!cam) { continue; } Profiler.BeginSample("Check view projection matrix changed (world space)"); var nowVP = cam.projectionMatrix * cam.worldToCameraMatrix; var previousVP = default(Matrix4x4); var id = cam.GetInstanceID(); s_PreviousViewProjectionMatrices.TryGetValue(id, out previousVP); s_NowViewProjectionMatrices[id] = nowVP; if (previousVP != nowVP) { sm.hasChanged = true; } Profiler.EndSample(); } var rt = sm.rectTransform; if (rt.hasChanged) { rt.hasChanged = false; sm.hasChanged = true; } #if UNITY_EDITOR if (!Application.isPlaying) { sm.hasChanged = true; } #endif } Profiler.BeginSample("Update changed soft masks"); foreach (var sm in s_ActiveSoftMasks) { if (!sm || !sm._hasChanged) { continue; } sm._hasChanged = false; if (sm._parent) { continue; } sm.UpdateMaskTexture(); if (!sm._hasStencilStateChanged) { continue; } sm._hasStencilStateChanged = false; Profiler.BeginSample("Notify stencil state changed"); MaskUtilities.NotifyStencilStateChanged(sm); Profiler.EndSample(); } Profiler.EndSample(); Profiler.BeginSample("Update previous view projection matrices"); s_PreviousViewProjectionMatrices.Clear(); foreach (var kv in s_NowViewProjectionMatrices) { s_PreviousViewProjectionMatrices.Add(kv.Key, kv.Value); } s_NowViewProjectionMatrices.Clear(); Profiler.EndSample(); Profiler.EndSample(); #if UNITY_EDITOR var w = s_PreviousWidth; var h = s_PreviousHeight; GetDownSamplingSize(DownSamplingRate.None, out s_PreviousWidth, out s_PreviousHeight); if (w != s_PreviousWidth || h != s_PreviousHeight) { Canvas.ForceUpdateCanvases(); } #endif }
/// <summary> /// Update all soft mask textures. /// </summary> static void UpdateMaskTextures() { foreach (var sm in s_ActiveSoftMasks) { if (!sm || sm._hasChanged || !sm.graphic || !sm.graphic.canvas) { continue; } var canvas = sm.graphic.canvas; if (canvas.renderMode == RenderMode.WorldSpace) { var cam = canvas.worldCamera; if (cam == null) { continue; // EDIT: Cytoid } Matrix4x4 nowsVP = cam.projectionMatrix * cam.worldToCameraMatrix; #if UNITY_2018_1_OR_NEWER Matrix4x4 previousVP = cam.previousViewProjectionMatrix; #else Matrix4x4 previousVP = default(Matrix4x4); int id = cam.GetInstanceID(); s_previousViewProjectionMatrices.TryGetValue(id, out previousVP); s_nowViewProjectionMatrices[id] = nowsVP; #endif if (previousVP != nowsVP) { sm.hasChanged = true; } } var rt = sm.rectTransform; if (rt.hasChanged) { rt.hasChanged = false; sm.hasChanged = true; } #if UNITY_EDITOR if (!Application.isPlaying) { sm.hasChanged = true; } #endif } foreach (var sm in s_ActiveSoftMasks) { if (!sm || !sm._hasChanged) { continue; } sm._hasChanged = false; if (!sm._parent) { sm.UpdateMaskTexture(); if (sm._hasStencilStateChanged) { sm._hasStencilStateChanged = false; MaskUtilities.NotifyStencilStateChanged(sm); } } } #if !UNITY_2018_1_OR_NEWER s_previousViewProjectionMatrices.Clear(); foreach (int id in s_previousViewProjectionMatrices.Keys) { s_previousViewProjectionMatrices [id] = s_nowViewProjectionMatrices [id]; } s_nowViewProjectionMatrices.Clear(); #endif }