close #8; Add `Fit On LateUpdate` option

main
mob-sakai 2018-10-15 15:37:20 +09:00
parent b9fbb366c5
commit 2a8f58f5fd
2 changed files with 28 additions and 10 deletions

View File

@ -16,7 +16,7 @@ namespace Coffee.UIExtensions.Demos
public void AutoFitToButton(bool flag) public void AutoFitToButton(bool flag)
{ {
unmask.autoFitTarget = flag ? (target.transform as RectTransform) : null; unmask.fitOnLateUpdate = flag;
} }
public void SetTransitionColor(bool flag) public void SetTransitionColor(bool flag)

View File

@ -23,8 +23,10 @@ namespace Coffee.UIExtensions
//################################ //################################
// Serialize Members. // Serialize Members.
//################################ //################################
[Tooltip("Fit graphic's transform to target transform on LateUpdate.")] [Tooltip("Fit graphic's transform to target transform.")]
[SerializeField] RectTransform m_AutoFitTarget; [SerializeField] RectTransform m_FitTarget;
[Tooltip("Fit graphic's transform to target transform on LateUpdate every frame.")]
[SerializeField] bool m_FitOnLateUpdate;
[Tooltip("Show the graphic that is associated with the unmask render area.")] [Tooltip("Show the graphic that is associated with the unmask render area.")]
[SerializeField] bool m_ShowUnmaskGraphic = false; [SerializeField] bool m_ShowUnmaskGraphic = false;
@ -38,9 +40,22 @@ namespace Coffee.UIExtensions
public Graphic graphic{ get { return _graphic ?? (_graphic = GetComponent<Graphic>()); } } public Graphic graphic{ get { return _graphic ?? (_graphic = GetComponent<Graphic>()); } }
/// <summary> /// <summary>
/// Fit graphic's transform to target transform on LateUpdate. /// Fit graphic's transform to target transform.
/// </summary> /// </summary>
public RectTransform autoFitTarget{ get { return m_AutoFitTarget; } set { m_AutoFitTarget = value; } } public RectTransform fitTarget
{
get { return m_FitTarget; }
set
{
m_FitTarget = value;
FitTo(m_FitTarget);
}
}
/// <summary>
/// Fit graphic's transform to target transform on LateUpdate every frame.
/// </summary>
public bool fitOnLateUpdate{ get { return m_FitOnLateUpdate; } set { m_FitOnLateUpdate = value; } }
/// <summary> /// <summary>
/// Show the graphic that is associated with the unmask render area. /// Show the graphic that is associated with the unmask render area.
@ -72,7 +87,6 @@ namespace Coffee.UIExtensions
StencilMaterial.Remove(_unmaskMaterial); StencilMaterial.Remove(_unmaskMaterial);
_unmaskMaterial = StencilMaterial.Add(baseMaterial, (1 << stencilDepth) - 1, StencilOp.Zero, CompareFunction.Always, m_ShowUnmaskGraphic ? ColorWriteMask.All : (ColorWriteMask)0, 0, (1 << stencilDepth) - 1); _unmaskMaterial = StencilMaterial.Add(baseMaterial, (1 << stencilDepth) - 1, StencilOp.Zero, CompareFunction.Always, m_ShowUnmaskGraphic ? ColorWriteMask.All : (ColorWriteMask)0, 0, (1 << stencilDepth) - 1);
//StencilMaterial.Remove (baseMaterial);
return _unmaskMaterial; return _unmaskMaterial;
} }
@ -107,9 +121,9 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
void OnEnable() void OnEnable()
{ {
if (m_AutoFitTarget) if (m_FitTarget)
{ {
FitTo(m_AutoFitTarget); FitTo(m_FitTarget);
} }
SetDirty(); SetDirty();
} }
@ -129,9 +143,13 @@ namespace Coffee.UIExtensions
/// </summary> /// </summary>
void LateUpdate() void LateUpdate()
{ {
if (m_AutoFitTarget) #if UNITY_EDITOR
if (m_FitTarget && (m_FitOnLateUpdate || !Application.isPlaying))
#else
if (m_FitTarget && m_FitOnLateUpdate)
#endif
{ {
FitTo(m_AutoFitTarget); FitTo(m_FitTarget);
} }
} }