[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. * 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 UnityEngine;
using UnityEditor; using UnityEditor;
@ -81,7 +85,18 @@ namespace Spine.Unity.Examples {
// Restore mesh part for undo logic after undo of "Add Parts Renderer". // Restore mesh part for undo logic after undo of "Add Parts Renderer".
// Triggers regeneration and assignment of the mesh filter's mesh. // 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.OnDisable();
component.OnEnable(); component.OnEnable();
} }

View File

@ -191,8 +191,10 @@ namespace Spine.Unity {
skeletonRenderer.LateUpdate(); skeletonRenderer.LateUpdate();
foreach (var s in partsRenderers) foreach (var partsRenderer in partsRenderers) {
s.ClearMesh(); if (partsRenderer != null)
partsRenderer.ClearMesh();
}
} }
MaterialPropertyBlock copiedBlock; MaterialPropertyBlock copiedBlock;
@ -221,6 +223,8 @@ namespace Spine.Unity {
int rendererIndex = 0; int rendererIndex = 0;
var currentRenderer = partsRenderers[rendererIndex]; var currentRenderer = partsRenderers[rendererIndex];
for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) { for (int si = 0, start = 0; si <= lastSubmeshInstruction; si++) {
if (currentRenderer == null)
continue;
if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) { if (submeshInstructionsItems[si].forceSeparate || si == lastSubmeshInstruction) {
// Apply properties // Apply properties
var meshGenerator = currentRenderer.MeshGenerator; var meshGenerator = currentRenderer.MeshGenerator;
@ -245,7 +249,9 @@ namespace Spine.Unity {
// Clear extra renderers if they exist. // Clear extra renderers if they exist.
for (; rendererIndex < rendererCount; rendererIndex++) { 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); separatorSlots.Add(slot);
} }
#if UNITY_EDITOR #if UNITY_EDITOR
else else if (!string.IsNullOrEmpty(separatorSlotNames[i]))
{ {
Debug.LogWarning(separatorSlotNames[i] + " is not a slot in " + skeletonDataAsset.skeletonJSON.name); Debug.LogWarning(separatorSlotNames[i] + " is not a slot in " + skeletonDataAsset.skeletonJSON.name);
} }