|
@@ -117,7 +117,7 @@ namespace Spine.Unity {
|
|
|
/// <summary>Shader property ID used for the Stencil comparison function.</summary>
|
|
|
public static readonly int STENCIL_COMP_PARAM_ID = Shader.PropertyToID("_StencilComp");
|
|
|
/// <summary>Shader property value used as Stencil comparison function for <see cref="SpriteMaskInteraction.None"/>.</summary>
|
|
|
- public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_NONE = UnityEngine.Rendering.CompareFunction.Disabled;
|
|
|
+ public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_NONE = UnityEngine.Rendering.CompareFunction.Always;
|
|
|
/// <summary>Shader property value used as Stencil comparison function for <see cref="SpriteMaskInteraction.VisibleInsideMask"/>.</summary>
|
|
|
public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_VISIBLE_INSIDE = UnityEngine.Rendering.CompareFunction.LessEqual;
|
|
|
/// <summary>Shader property value used as Stencil comparison function for <see cref="SpriteMaskInteraction.VisibleOutsideMask"/>.</summary>
|
|
@@ -476,6 +476,12 @@ namespace Spine.Unity {
|
|
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
|
|
private void AssignSpriteMaskMaterials()
|
|
|
{
|
|
|
+ #if UNITY_EDITOR
|
|
|
+ if (!Application.isPlaying) {
|
|
|
+ EditorFixStencilCompParameters();
|
|
|
+ }
|
|
|
+ #endif
|
|
|
+
|
|
|
if (maskMaterials.materialsMaskDisabled.Length > 0 && maskMaterials.materialsMaskDisabled[0] != null &&
|
|
|
maskInteraction == SpriteMaskInteraction.None) {
|
|
|
this.meshRenderer.materials = maskMaterials.materialsMaskDisabled;
|
|
@@ -523,6 +529,43 @@ namespace Spine.Unity {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
+ #if UNITY_EDITOR
|
|
|
+ private void EditorFixStencilCompParameters() {
|
|
|
+ if (HasAnyStencilComp0Material())
|
|
|
+ FixAllProjectMaterialsStencilCompParameters();
|
|
|
+ }
|
|
|
+
|
|
|
+ private void FixAllProjectMaterialsStencilCompParameters() {
|
|
|
+ string[] materialGUIDS = UnityEditor.AssetDatabase.FindAssets("t:material");
|
|
|
+ foreach (var guid in materialGUIDS) {
|
|
|
+ string path = UnityEditor.AssetDatabase.GUIDToAssetPath(guid);
|
|
|
+ if (!string.IsNullOrEmpty(path)) {
|
|
|
+ var mat = UnityEditor.AssetDatabase.LoadAssetAtPath<Material>(path);
|
|
|
+ if (mat.HasProperty(STENCIL_COMP_PARAM_ID) && mat.GetFloat(STENCIL_COMP_PARAM_ID) == 0) {
|
|
|
+ mat.SetFloat(STENCIL_COMP_PARAM_ID, (int)STENCIL_COMP_MASKINTERACTION_NONE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ UnityEditor.AssetDatabase.Refresh();
|
|
|
+ UnityEditor.AssetDatabase.SaveAssets();
|
|
|
+ }
|
|
|
+
|
|
|
+ private bool HasAnyStencilComp0Material() {
|
|
|
+ if (meshRenderer == null)
|
|
|
+ return false;
|
|
|
+
|
|
|
+ foreach (var mat in meshRenderer.sharedMaterials) {
|
|
|
+ if (mat != null && mat.HasProperty(STENCIL_COMP_PARAM_ID)) {
|
|
|
+ float currentCompValue = mat.GetFloat(STENCIL_COMP_PARAM_ID);
|
|
|
+ if (currentCompValue == 0)
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ #endif // UNITY_EDITOR
|
|
|
+
|
|
|
#endif //#if BUILT_IN_SPRITE_MASK_COMPONENT
|
|
|
}
|
|
|
}
|