Skip to content

Commit

Permalink
fix: Nested MaskingShape is not working correctly
Browse files Browse the repository at this point in the history
close #189
  • Loading branch information
mob-sakai committed Sep 4, 2024
1 parent 21dfae7 commit 42fcc14
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
10 changes: 5 additions & 5 deletions Packages/src/Runtime/Internal/Extensions/TransformExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ public static int CompareHierarchyIndex(this Transform self, Transform other, Tr
Profiler.EndSample();

Profiler.BeginSample("(COF)[TransformExt] CompareHierarchyIndex > Calc");
var loop = Mathf.Min(lTrs.Count, rTrs.Count);
var loop = Mathf.Max(lTrs.Count, rTrs.Count);
var result = 0;
for (var i = 0; i < loop; ++i)
{
self = lTrs[lTrs.Count - i - 1];
other = rTrs[rTrs.Count - i - 1];
if (self == other) continue;
var selfIndex = 0 <= lTrs.Count - i - 1 ? lTrs[lTrs.Count - i - 1].GetSiblingIndex() : -1;
var otherIndex = 0 <= rTrs.Count - i - 1 ? rTrs[rTrs.Count - i - 1].GetSiblingIndex() : -1;
if (selfIndex == otherIndex) continue;

result = self.GetSiblingIndex() - other.GetSiblingIndex();
result = selfIndex - otherIndex;
break;
}

Expand Down
15 changes: 12 additions & 3 deletions Packages/src/Runtime/MaskingShape/MaskingShape.cs
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ int IComparable<MaskingShape>.CompareTo(MaskingShape other)

void IMaskable.RecalculateMasking()
{
StencilMaterial.Remove(_maskMaterial);
_maskMaterial = null;
_shouldRecalculateStencil = true;
UpdateContainer();
RegisterAntiAliasingIfNeeded();
Expand All @@ -258,6 +260,8 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
{
if (!isActiveAndEnabled)
{
StencilMaterial.Remove(_maskMaterial);
_maskMaterial = null;
return baseMaterial;
}

Expand All @@ -267,10 +271,11 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
{
StencilMaterial.Remove(_maskMaterial);
_maskMaterial = null;
return null;
return baseMaterial;
}

// Mask material
var toUse = baseMaterial;
Material maskMat = null;
var colorMask = m_ShowMaskGraphic ? ColorWriteMask.All : 0;
if (SoftMaskingEnabled() && !UISoftMaskProjectSettings.useStencilOutsideScreen)
Expand Down Expand Up @@ -303,8 +308,12 @@ Material IMaterialModifier.GetModifiedMaterial(Material baseMaterial)
}

StencilMaterial.Remove(_maskMaterial);
_maskMaterial = maskMat;
return _maskMaterial;
if (maskMat && maskMat != baseMaterial)
{
toUse = _maskMaterial = maskMat;
}

return toUse;
}

void IMeshModifier.ModifyMesh(Mesh mesh)
Expand Down

0 comments on commit 42fcc14

Please sign in to comment.