From 26e30e45f23c38ebe2f1ef636b67413d7f0926aa Mon Sep 17 00:00:00 2001 From: BlackMATov Date: Mon, 15 May 2017 23:46:15 +0700 Subject: [PATCH] Fix Unity 5.6 submesh sorting bug --- Assets/FlashTools/Docs/CHANGELOG.md | 1 + .../FTEditor/Editors/SwfClipAssetEditor.cs | 4 ++++ .../Scripts/FTRuntime/Internal/SwfUtils.cs | 11 ++++++++++ .../FlashTools/Scripts/FTRuntime/SwfClip.cs | 21 +++++++++++++++++-- ProjectStuff/FlashTools.org | 6 ++++-- 5 files changed, 39 insertions(+), 4 deletions(-) diff --git a/Assets/FlashTools/Docs/CHANGELOG.md b/Assets/FlashTools/Docs/CHANGELOG.md index a55f4ee..2f0f7e7 100644 --- a/Assets/FlashTools/Docs/CHANGELOG.md +++ b/Assets/FlashTools/Docs/CHANGELOG.md @@ -2,6 +2,7 @@ * Fix shape groups in tweens problems * Fix locked elements problem * Fix optimizator bitmap trim problems +* Fix Unity 5.6 submesh sorting bug * Add shape tween warning * Remove excess "if" instruction from shaders diff --git a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs index 8a18a9f..136d2fd 100644 --- a/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs +++ b/Assets/FlashTools/Scripts/Editor/FTEditor/Editors/SwfClipAssetEditor.cs @@ -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(); clip_go.AddComponent(); + #if UNITY_5_6_OR_NEWER + clip_go.AddComponent(); + #endif clip_go.AddComponent().clip = clip; clip_go.AddComponent(); return clip_go; diff --git a/Assets/FlashTools/Scripts/FTRuntime/Internal/SwfUtils.cs b/Assets/FlashTools/Scripts/FTRuntime/Internal/SwfUtils.cs index 3a05e75..5d343d2 100644 --- a/Assets/FlashTools/Scripts/FTRuntime/Internal/SwfUtils.cs +++ b/Assets/FlashTools/Scripts/FTRuntime/Internal/SwfUtils.cs @@ -27,6 +27,17 @@ namespace FTRuntime.Internal { // // + public static T GetOrCreateComponent(GameObject obj) where T : Component { + var comp = obj.GetComponent(); + return comp != null + ? comp + : obj.AddComponent(); + } + + // + // + // + public static void FillGeneratedMesh(Mesh mesh, SwfClipAsset.MeshData mesh_data) { if ( mesh_data.SubMeshes.Length > 0 ) { mesh.subMeshCount = mesh_data.SubMeshes.Length; diff --git a/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs b/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs index 0f7798b..8091c82 100644 --- a/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs +++ b/Assets/FlashTools/Scripts/FTRuntime/SwfClip.cs @@ -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(); - _meshRenderer = GetComponent(); + _meshFilter = SwfUtils.GetOrCreateComponent(gameObject); + _meshRenderer = SwfUtils.GetOrCreateComponent(gameObject); + #if UNITY_5_6_OR_NEWER + _sortingGroup = SwfUtils.GetOrCreateComponent(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() { diff --git a/ProjectStuff/FlashTools.org b/ProjectStuff/FlashTools.org index 4714366..1c97d23 100644 --- a/ProjectStuff/FlashTools.org +++ b/ProjectStuff/FlashTools.org @@ -61,14 +61,16 @@ dipyalov: фишка в том, что swf обновился, но и собр **** DONE Элемент может быть залокан (element.locked) **** DONE Возможно не стоит преобразовывать группы в символы Таки стоит, но с рекурсивным выносом в отдельные символы и последующей их обработкой -**** TODO В ошибках конвертации писать, что нужно прогнать через скрипт экспорта +**** DONE В ошибках конвертации писать, что нужно прогнать через скрипт экспорта А еще лучше как-то метить прогнанную анимацию и нет *** Баги **** TODO При больших (>= 4000 пикселей) выделениях не работает convertSelectionToBitmap **** TODO Не работает конвертация в batchmod'е **** DONE В ошибках конвертации не пишется путь до swf **** DONE Не растеризуются группы в твинах -**** TODO Unity может переставлять сабмеши на одинаковой глубине (проблема с масками) +**** DONE Unity может переставлять сабмеши на одинаковой глубине (проблема с масками) +https://fogbugz.unity3d.com/default.asp?910858_0diqjnj67814hj3i +http://ru.esotericsoftware.com/forum/Submeshes-render-in-random-order-with-orthographic-camera-8528 **** TODO При автоплее с пустым клипом контроллер накапливает _tickTimer **** TODO Возможно проблемы с DX9 UNITY_UV_STARTS_AT_TOP