mirror of
https://github.com/BlackMATov/unity-flash-tools.git
synced 2025-12-16 14:11:19 +07:00
Fix Unity 5.6 submesh sorting bug
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user