[unity] Fixed Prefab with SkeletonRenderSeparator constantly loading in editor. Closes #1626.

This commit is contained in:
Harald Csaszar 2020-06-03 18:12:55 +02:00
parent 512084a749
commit 6e9ad610d6
3 changed files with 26 additions and 5 deletions

View File

@ -27,6 +27,10 @@
* THE SPINE RUNTIMES, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*****************************************************************************/
#if UNITY_2018_3 || UNITY_2019 || UNITY_2018_3_OR_NEWER
#define NEW_PREFAB_SYSTEM
#endif
using UnityEngine;
using UnityEditor;
@ -81,7 +85,18 @@ namespace Spine.Unity.Examples {
// Restore mesh part for undo logic after undo of "Add Parts Renderer".
// Triggers regeneration and assignment of the mesh filter's mesh.
if (component.GetComponent<MeshFilter>() && component.GetComponent<MeshFilter>().sharedMesh == null) {
bool isMeshFilterAlwaysNull = false;
#if UNITY_EDITOR && NEW_PREFAB_SYSTEM
// Don't store mesh or material at the prefab, otherwise it will permanently reload
var prefabType = UnityEditor.PrefabUtility.GetPrefabAssetType(component);
if (UnityEditor.PrefabUtility.IsPartOfPrefabAsset(component) &&
(prefabType == UnityEditor.PrefabAssetType.Regular || prefabType == UnityEditor.PrefabAssetType.Variant)) {
isMeshFilterAlwaysNull = true;
}
#endif
if (!isMeshFilterAlwaysNull && component.GetComponent<MeshFilter>() && component.GetComponent<MeshFilter>().sharedMesh == null) {
component.OnDisable();
component.OnEnable();
}

View File

@ -191,8 +191,10 @@ namespace Spine.Unity {
skeletonRenderer.LateUpdate();
foreach (var s in partsRenderers)
s.ClearMesh();
foreach (var partsRenderer in partsRenderers) {
if (partsRenderer != null)
partsRenderer.ClearMesh();
}
}
MaterialPropertyBlock copiedBlock;
@ -221,6 +223,8 @@ namespace Spine.Unity {
int rendererIndex = 0;
var currentRenderer = partsRenderers[rendererIndex];
for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) {
if (currentRenderer == null)
continue;
if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) {
// Apply properties
var meshGenerator = currentRenderer.MeshGenerator;
@ -245,7 +249,9 @@ namespace Spine.Unity {
// Clear extra renderers if they exist.
for (; rendererIndex < rendererCount; rendererIndex++) {
partsRenderers[rendererIndex].ClearMesh();
currentRenderer = partsRenderers[rendererIndex];
if (currentRenderer != null)
partsRenderers[rendererIndex].ClearMesh();
}
}

View File

@ -529,7 +529,7 @@ namespace Spine.Unity {
separatorSlots.Add(slot);
}
#if UNITY_EDITOR
else
else if (!string.IsNullOrEmpty(separatorSlotNames[i]))
{
Debug.LogWarning(separatorSlotNames[i] + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
}