Fix Unity 5.6 submesh sorting bug

This commit is contained in:
2017-05-15 23:46:15 +07:00
parent 4451018727
commit 26e30e45f2
5 changed files with 39 additions and 4 deletions

View File

@@ -1,4 +1,5 @@
using UnityEngine;
using UnityEngine.Rendering;
using UnityEditor;
using System.IO;
@@ -40,6 +41,9 @@ namespace FTEditor.Editors {
var clip_go = new GameObject(clip.name);
clip_go.AddComponent<MeshFilter>();
clip_go.AddComponent<MeshRenderer>();
#if UNITY_5_6_OR_NEWER
clip_go.AddComponent<SortingGroup>();
#endif
clip_go.AddComponent<SwfClip>().clip = clip;
clip_go.AddComponent<SwfClipController>();
return clip_go;

View File

@@ -27,6 +27,17 @@ namespace FTRuntime.Internal {
//
//
public static T GetOrCreateComponent<T>(GameObject obj) where T : Component {
var comp = obj.GetComponent<T>();
return comp != null
? comp
: obj.AddComponent<T>();
}
//
//
//
public static void FillGeneratedMesh(Mesh mesh, SwfClipAsset.MeshData mesh_data) {
if ( mesh_data.SubMeshes.Length > 0 ) {
mesh.subMeshCount = mesh_data.SubMeshes.Length;

View File

@@ -1,13 +1,21 @@
using UnityEngine;
using UnityEngine.Rendering;
using FTRuntime.Internal;
namespace FTRuntime {
[ExecuteInEditMode, DisallowMultipleComponent]
#if UNITY_5_6_OR_NEWER
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer), typeof(SortingGroup))]
#else
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
#endif
public class SwfClip : MonoBehaviour {
MeshFilter _meshFilter = null;
MeshRenderer _meshRenderer = null;
#if UNITY_5_6_OR_NEWER
SortingGroup _sortingGroup = null;
#endif
bool _dirtyMesh = true;
SwfClipAsset.Sequence _curSequence = null;
@@ -274,8 +282,11 @@ namespace FTRuntime {
}
void ClearCache() {
_meshFilter = GetComponent<MeshFilter>();
_meshRenderer = GetComponent<MeshRenderer>();
_meshFilter = SwfUtils.GetOrCreateComponent<MeshFilter>(gameObject);
_meshRenderer = SwfUtils.GetOrCreateComponent<MeshRenderer>(gameObject);
#if UNITY_5_6_OR_NEWER
_sortingGroup = SwfUtils.GetOrCreateComponent<SortingGroup>(gameObject);
#endif
_dirtyMesh = true;
_curSequence = null;
_curPropBlock = null;
@@ -336,6 +347,12 @@ namespace FTRuntime {
_meshRenderer.sortingOrder = sortingOrder;
_meshRenderer.sortingLayerName = sortingLayer;
}
#if UNITY_5_6_OR_NEWER
if ( _sortingGroup ) {
_sortingGroup.sortingOrder = sortingOrder;
_sortingGroup.sortingLayerName = sortingLayer;
}
#endif
}
void UpdatePropBlock() {