mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-20 17:26:01 +08:00
[unity] Added #if guards for Unity 5.x compatibility before Unity added SpriteMasks. See #941.
This commit is contained in:
parent
cac764fa01
commit
b8a208d382
@ -34,6 +34,10 @@
|
|||||||
#define NO_PREFAB_MESH
|
#define NO_PREFAB_MESH
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2017_OR_NEWER
|
||||||
|
#define BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
#endif
|
||||||
|
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -215,6 +219,7 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
if (setMaskNoneMaterialsQueued) {
|
if (setMaskNoneMaterialsQueued) {
|
||||||
setMaskNoneMaterialsQueued = false;
|
setMaskNoneMaterialsQueued = false;
|
||||||
foreach (var c in targets)
|
foreach (var c in targets)
|
||||||
@ -241,8 +246,9 @@ namespace Spine.Unity.Editor {
|
|||||||
foreach (var c in targets)
|
foreach (var c in targets)
|
||||||
EditorDeleteMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleOutsideMask);
|
EditorDeleteMaskMaterials(c as SkeletonRenderer, SpriteMaskInteraction.VisibleOutsideMask);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if NO_PREFAB_MESH
|
#if NO_PREFAB_MESH
|
||||||
if (isInspectingPrefab) {
|
if (isInspectingPrefab) {
|
||||||
if (multi) {
|
if (multi) {
|
||||||
foreach (var c in targets) {
|
foreach (var c in targets) {
|
||||||
@ -258,7 +264,7 @@ namespace Spine.Unity.Editor {
|
|||||||
meshFilter.sharedMesh = null;
|
meshFilter.sharedMesh = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool valid = TargetIsValid;
|
bool valid = TargetIsValid;
|
||||||
@ -362,6 +368,7 @@ namespace Spine.Unity.Editor {
|
|||||||
if (tangents != null) EditorGUILayout.PropertyField(tangents, TangentsLabel);
|
if (tangents != null) EditorGUILayout.PropertyField(tangents, TangentsLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
if (maskMaterialsNone.arraySize > 0 || maskMaterialsInside.arraySize > 0 || maskMaterialsOutside.arraySize > 0) {
|
if (maskMaterialsNone.arraySize > 0 || maskMaterialsInside.arraySize > 0 || maskMaterialsOutside.arraySize > 0) {
|
||||||
EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Mask Interaction Materials", SpineInspectorUtility.UnityIcon<SpriteMask>()), EditorStyles.boldLabel);
|
EditorGUILayout.LabelField(SpineInspectorUtility.TempContent("Mask Interaction Materials", SpineInspectorUtility.UnityIcon<SpriteMask>()), EditorStyles.boldLabel);
|
||||||
@ -376,6 +383,7 @@ namespace Spine.Unity.Editor {
|
|||||||
MaskMaterialsEditingField(ref setOutsideMaskMaterialsQueued, ref deleteOutsideMaskMaterialsQueued, maskMaterialsOutside, MaskMaterialsOutsideLabel,
|
MaskMaterialsEditingField(ref setOutsideMaskMaterialsQueued, ref deleteOutsideMaskMaterialsQueued, maskMaterialsOutside, MaskMaterialsOutsideLabel,
|
||||||
differentMaskModesSelected, allowDelete : true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleOutsideMask);
|
differentMaskModesSelected, allowDelete : true, isActiveMaterial: activeMaskInteractionValue == (int)SpriteMaskInteraction.VisibleOutsideMask);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
EditorGUILayout.Space();
|
EditorGUILayout.Space();
|
||||||
|
|
||||||
@ -525,11 +533,20 @@ namespace Spine.Unity.Editor {
|
|||||||
if (component == null) return;
|
if (component == null) return;
|
||||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
component.Initialize(true);
|
component.Initialize(true);
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
SpineMaskUtilities.EditorAssignSpriteMaskMaterials(component);
|
SpineMaskUtilities.EditorAssignSpriteMaskMaterials(component);
|
||||||
|
#endif
|
||||||
|
|
||||||
component.LateUpdate();
|
component.LateUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool SkeletonDataAssetIsValid (SkeletonDataAsset asset) {
|
||||||
|
return asset != null && asset.GetSkeletonData(quiet: true) != null;
|
||||||
|
}
|
||||||
|
|
||||||
bool AreAnyMaskMaterialsMissing() {
|
bool AreAnyMaskMaterialsMissing() {
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
foreach (var o in targets) {
|
foreach (var o in targets) {
|
||||||
var component = (SkeletonRenderer)o;
|
var component = (SkeletonRenderer)o;
|
||||||
if (!component.valid)
|
if (!component.valid)
|
||||||
@ -537,13 +554,11 @@ namespace Spine.Unity.Editor {
|
|||||||
if (SpineMaskUtilities.AreMaskMaterialsMissing(component))
|
if (SpineMaskUtilities.AreMaskMaterialsMissing(component))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool SkeletonDataAssetIsValid (SkeletonDataAsset asset) {
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
return asset != null && asset.GetSkeletonData(quiet: true) != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
|
static void EditorSetMaskMaterials(SkeletonRenderer component, SpriteMaskInteraction maskType)
|
||||||
{
|
{
|
||||||
if (component == null) return;
|
if (component == null) return;
|
||||||
@ -556,5 +571,6 @@ namespace Spine.Unity.Editor {
|
|||||||
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
if (!SkeletonDataAssetIsValid(component.SkeletonDataAsset)) return;
|
||||||
SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
|
SpineMaskUtilities.EditorDeleteMaskMaterials(component.maskMaterials, maskType);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -44,6 +44,12 @@
|
|||||||
#define NEWHIERARCHYWINDOWCALLBACKS
|
#define NEWHIERARCHYWINDOWCALLBACKS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2017_OR_NEWER
|
||||||
|
#define BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -241,3 +247,4 @@ namespace Spine.Unity.Editor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif // BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
|||||||
@ -31,6 +31,11 @@
|
|||||||
#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
|
#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
|
||||||
#define NEW_PREFAB_SYSTEM
|
#define NEW_PREFAB_SYSTEM
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if UNITY_2017_OR_NEWER
|
||||||
|
#define BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
|
#endif
|
||||||
|
|
||||||
#define SPINE_OPTIONAL_RENDEROVERRIDE
|
#define SPINE_OPTIONAL_RENDEROVERRIDE
|
||||||
#define SPINE_OPTIONAL_MATERIALOVERRIDE
|
#define SPINE_OPTIONAL_MATERIALOVERRIDE
|
||||||
|
|
||||||
@ -92,6 +97,7 @@ namespace Spine.Unity {
|
|||||||
/// <summary>If true, tangents are calculated every frame and added to the Mesh. Enable this when using a shader that uses lighting that requires tangents.</summary>
|
/// <summary>If true, tangents are calculated every frame and added to the Mesh. Enable this when using a shader that uses lighting that requires tangents.</summary>
|
||||||
public bool calculateTangents = false;
|
public bool calculateTangents = false;
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
/// <summary>This enum controls the mode under which the sprite will interact with the masking system.</summary>
|
/// <summary>This enum controls the mode under which the sprite will interact with the masking system.</summary>
|
||||||
/// <remarks>Interaction modes with <see cref="UnityEngine.SpriteMask"/> components are identical to Unity's <see cref="UnityEngine.SpriteRenderer"/>,
|
/// <remarks>Interaction modes with <see cref="UnityEngine.SpriteMask"/> components are identical to Unity's <see cref="UnityEngine.SpriteRenderer"/>,
|
||||||
/// see https://docs.unity3d.com/ScriptReference/SpriteMaskInteraction.html. </remarks>
|
/// see https://docs.unity3d.com/ScriptReference/SpriteMaskInteraction.html. </remarks>
|
||||||
@ -117,6 +123,7 @@ namespace Spine.Unity {
|
|||||||
public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_VISIBLE_INSIDE = UnityEngine.Rendering.CompareFunction.LessEqual;
|
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>
|
/// <summary>Shader property value used as Stencil comparison function for <see cref="SpriteMaskInteraction.VisibleOutsideMask"/>.</summary>
|
||||||
public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_VISIBLE_OUTSIDE = UnityEngine.Rendering.CompareFunction.Greater;
|
public const UnityEngine.Rendering.CompareFunction STENCIL_COMP_MASKINTERACTION_VISIBLE_OUTSIDE = UnityEngine.Rendering.CompareFunction.Greater;
|
||||||
|
#endif // #if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Overrides
|
#region Overrides
|
||||||
@ -400,9 +407,11 @@ namespace Spine.Unity {
|
|||||||
meshFilter.sharedMesh = currentMesh;
|
meshFilter.sharedMesh = currentMesh;
|
||||||
currentSmartMesh.instructionUsed.Set(currentInstructions);
|
currentSmartMesh.instructionUsed.Set(currentInstructions);
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
if (meshRenderer != null) {
|
if (meshRenderer != null) {
|
||||||
AssignSpriteMaskMaterials();
|
AssignSpriteMaskMaterials();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FindAndApplySeparatorSlots (string startsWith, bool clearExistingSeparators = true, bool updateStringArray = false) {
|
public void FindAndApplySeparatorSlots (string startsWith, bool clearExistingSeparators = true, bool updateStringArray = false) {
|
||||||
@ -465,6 +474,7 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
private void AssignSpriteMaskMaterials()
|
private void AssignSpriteMaskMaterials()
|
||||||
{
|
{
|
||||||
if (maskMaterials.materialsMaskDisabled.Length > 0 && maskMaterials.materialsMaskDisabled[0] != null &&
|
if (maskMaterials.materialsMaskDisabled.Length > 0 && maskMaterials.materialsMaskDisabled[0] != null &&
|
||||||
@ -514,5 +524,6 @@ namespace Spine.Unity {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif //#if BUILT_IN_SPRITE_MASK_COMPONENT
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user