mirror of
https://github.com/mob-sakai/UIEffect.git
synced 2026-11-20 18:02:38 +08:00
fix: TransitionFilter and GradationMode do not work correctly when the initial scale is 0
close #311
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
using Coffee.UIEffectInternal;
|
using Coffee.UIEffectInternal;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@@ -21,6 +22,7 @@ namespace Coffee.UIEffects
|
|||||||
private Graphic _graphic;
|
private Graphic _graphic;
|
||||||
private Material _material;
|
private Material _material;
|
||||||
private UIEffectContext _context;
|
private UIEffectContext _context;
|
||||||
|
private Action _setVerticesDirtyIfVisible;
|
||||||
|
|
||||||
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
|
public Graphic graphic => _graphic ? _graphic : _graphic = GetComponent<Graphic>();
|
||||||
public virtual uint effectId => (uint)GetInstanceID();
|
public virtual uint effectId => (uint)GetInstanceID();
|
||||||
@@ -52,6 +54,11 @@ namespace Coffee.UIEffects
|
|||||||
|
|
||||||
protected override void OnDisable()
|
protected override void OnDisable()
|
||||||
{
|
{
|
||||||
|
if (_setVerticesDirtyIfVisible != null)
|
||||||
|
{
|
||||||
|
UIExtraCallbacks.onBeforeCanvasRebuild -= _setVerticesDirtyIfVisible;
|
||||||
|
}
|
||||||
|
|
||||||
MaterialRepository.Release(ref _material);
|
MaterialRepository.Release(ref _material);
|
||||||
SetMaterialDirty();
|
SetMaterialDirty();
|
||||||
SetVerticesDirty();
|
SetVerticesDirty();
|
||||||
@@ -59,6 +66,8 @@ namespace Coffee.UIEffects
|
|||||||
|
|
||||||
protected override void OnDestroy()
|
protected override void OnDestroy()
|
||||||
{
|
{
|
||||||
|
_setVerticesDirtyIfVisible = null;
|
||||||
|
_graphic = null;
|
||||||
s_ContextPool.Return(ref _context);
|
s_ContextPool.Return(ref _context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +79,27 @@ namespace Coffee.UIEffects
|
|||||||
{
|
{
|
||||||
if (!isActiveAndEnabled || context == null) return;
|
if (!isActiveAndEnabled || context == null) return;
|
||||||
|
|
||||||
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
|
if (CanModifyMesh())
|
||||||
|
{
|
||||||
|
context.ModifyMesh(graphic, transitionRoot, vh, canModifyShape);
|
||||||
|
}
|
||||||
|
// If you can't modify the mesh, retry next frame.
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UIExtraCallbacks.onBeforeCanvasRebuild += _setVerticesDirtyIfVisible ??= SetVerticesDirtyIfVisible;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CanModifyMesh()
|
||||||
|
{
|
||||||
|
// The transitionRoot is same as the transform => true.
|
||||||
|
var root = transitionRoot;
|
||||||
|
if (transform == root) return true;
|
||||||
|
|
||||||
|
// The transitionRoot is not visible => false.
|
||||||
|
var scale1 = root.lossyScale;
|
||||||
|
var scale2 = transform.lossyScale;
|
||||||
|
return !Mathf.Approximately(scale1.x * scale1.y * scale2.x * scale2.y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual Material GetModifiedMaterial(Material baseMaterial)
|
public virtual Material GetModifiedMaterial(Material baseMaterial)
|
||||||
@@ -148,6 +177,15 @@ namespace Coffee.UIEffects
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SetVerticesDirtyIfVisible()
|
||||||
|
{
|
||||||
|
if (CanModifyMesh())
|
||||||
|
{
|
||||||
|
UIExtraCallbacks.onBeforeCanvasRebuild -= _setVerticesDirtyIfVisible ??= SetVerticesDirtyIfVisible;
|
||||||
|
SetVerticesDirty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void SetMaterialDirty()
|
public virtual void SetMaterialDirty()
|
||||||
{
|
{
|
||||||
if (graphic)
|
if (graphic)
|
||||||
|
|||||||
@@ -462,8 +462,12 @@ namespace Coffee.UIEffects
|
|||||||
if (transitionRoot)
|
if (transitionRoot)
|
||||||
{
|
{
|
||||||
rect = transitionRoot.rect;
|
rect = transitionRoot.rect;
|
||||||
rectMatrix = transitionRoot.worldToLocalMatrix
|
if (transitionRoot != graphic.transform)
|
||||||
* graphic.transform.localToWorldMatrix;
|
{
|
||||||
|
rectMatrix = transitionRoot.worldToLocalMatrix
|
||||||
|
* graphic.transform.localToWorldMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
rot *= Matrix4x4.Scale(new Vector3(1 / multiplier, 1 / multiplier, 1))
|
rot *= Matrix4x4.Scale(new Vector3(1 / multiplier, 1 / multiplier, 1))
|
||||||
* rectMatrix;
|
* rectMatrix;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user