main
mob-sakai 2019-01-25 20:40:59 +09:00
parent 73321b9b62
commit 64b90da720
1 changed files with 15 additions and 10 deletions

View File

@ -27,10 +27,10 @@ namespace Coffee.UIExtensions
[SerializeField] RectTransform m_FitTarget; [SerializeField] RectTransform m_FitTarget;
[Tooltip("Fit graphic's transform to target transform on LateUpdate every frame.")] [Tooltip("Fit graphic's transform to target transform on LateUpdate every frame.")]
[SerializeField] bool m_FitOnLateUpdate; [SerializeField] bool m_FitOnLateUpdate;
[Tooltip("Show the graphic that is associated with the unmask render area.")]
[SerializeField] bool m_ShowUnmaskGraphic = false;
[Tooltip ("Unmask affects only for children.")] [Tooltip ("Unmask affects only for children.")]
[SerializeField] bool m_OnlyForChildren = false; [SerializeField] bool m_OnlyForChildren = false;
[Tooltip("Show the graphic that is associated with the unmask render area.")]
[SerializeField] bool m_ShowUnmaskGraphic = false;
//################################ //################################
@ -72,7 +72,6 @@ namespace Coffee.UIExtensions
} }
} }
/// <summary> /// <summary>
/// Unmask affects only for children. /// Unmask affects only for children.
/// </summary> /// </summary>
@ -108,9 +107,9 @@ namespace Coffee.UIExtensions
var canvasRenderer = graphic.canvasRenderer; var canvasRenderer = graphic.canvasRenderer;
if (m_OnlyForChildren) if (m_OnlyForChildren)
{ {
canvasRenderer.hasPopInstruction = true;
StencilMaterial.Remove (_revertUnmaskMaterial); StencilMaterial.Remove (_revertUnmaskMaterial);
_revertUnmaskMaterial = StencilMaterial.Add (baseMaterial, (1 << stencilDepth) - 1, StencilOp.Replace, CompareFunction.NotEqual, (ColorWriteMask)0); _revertUnmaskMaterial = StencilMaterial.Add (baseMaterial, (1 << stencilDepth) - 1, StencilOp.Replace, CompareFunction.NotEqual, (ColorWriteMask)0);
canvasRenderer.hasPopInstruction = true;
canvasRenderer.popMaterialCount = 1; canvasRenderer.popMaterialCount = 1;
canvasRenderer.SetPopMaterial (_revertUnmaskMaterial, 0); canvasRenderer.SetPopMaterial (_revertUnmaskMaterial, 0);
} }
@ -171,9 +170,13 @@ namespace Coffee.UIExtensions
_unmaskMaterial = null; _unmaskMaterial = null;
_revertUnmaskMaterial = null; _revertUnmaskMaterial = null;
var canvasRenderer = graphic.canvasRenderer; if (graphic)
canvasRenderer.hasPopInstruction = false; {
canvasRenderer.popMaterialCount = 0; var canvasRenderer = graphic.canvasRenderer;
canvasRenderer.hasPopInstruction = false;
canvasRenderer.popMaterialCount = 0;
graphic.SetMaterialDirty();
}
SetDirty (); SetDirty ();
} }
@ -182,16 +185,17 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
void LateUpdate() void LateUpdate()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
if (m_FitTarget && (m_FitOnLateUpdate || !Application.isPlaying)) if (m_FitTarget && (m_FitOnLateUpdate || !Application.isPlaying))
#else #else
if (m_FitTarget && m_FitOnLateUpdate) if (m_FitTarget && m_FitOnLateUpdate)
#endif #endif
{ {
FitTo(m_FitTarget); FitTo(m_FitTarget);
} }
} }
#if UNITY_EDITOR
/// <summary> /// <summary>
/// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only). /// This function is called when the script is loaded or a value is changed in the inspector (Called in the editor only).
/// </summary> /// </summary>
@ -199,6 +203,7 @@ namespace Coffee.UIExtensions
{ {
SetDirty(); SetDirty();
} }
#endif
/// <summary> /// <summary>
/// Mark the graphic as dirty. /// Mark the graphic as dirty.