From 2f2eb3bee2ac1d1691373200983ac64ae507dfc8 Mon Sep 17 00:00:00 2001 From: Mattias Edlund Date: Fri, 25 Jun 2021 11:58:25 +0200 Subject: [PATCH] fix: support Unity 2021 --- Editor/LODGeneratorHelperEditor.cs | 4 ++-- Runtime/MeshCombiner.cs | 10 +--------- Runtime/MeshSimplifier.cs | 6 +----- Runtime/Utility/MeshUtils.cs | 19 ++----------------- Tests/Editor/MeshUtilsTest.cs | 18 +++++------------- 5 files changed, 11 insertions(+), 46 deletions(-) diff --git a/Editor/LODGeneratorHelperEditor.cs b/Editor/LODGeneratorHelperEditor.cs index fff16a0..b0c6416 100644 --- a/Editor/LODGeneratorHelperEditor.cs +++ b/Editor/LODGeneratorHelperEditor.cs @@ -618,12 +618,12 @@ where go.transform.IsChildOf(ourTransform) var notChildGameObjects = from go in gameObjects where !go.transform.IsChildOf(ourTransform) -#if UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020 +#if UNITY_2018_3_OR_NEWER && !PrefabUtility.IsPartOfAnyPrefab(go) #endif select go; -#if UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020 +#if UNITY_2018_3_OR_NEWER var prefabGameObjects = from go in gameObjects where !go.transform.IsChildOf(ourTransform) && PrefabUtility.IsPartOfAnyPrefab(go) diff --git a/Runtime/MeshCombiner.cs b/Runtime/MeshCombiner.cs index b5653ce..32c6fed 100644 --- a/Runtime/MeshCombiner.cs +++ b/Runtime/MeshCombiner.cs @@ -1,4 +1,4 @@ -#region License +#region License /* MIT License @@ -24,10 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #endregion -#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020 -#define UNITY_MESH_INDEXFORMAT_SUPPORT -#endif - using System.Collections.Generic; using System.Linq; using UnityEngine; @@ -287,11 +283,7 @@ public static Mesh CombineMeshes(Mesh[] meshes, Matrix4x4[] transforms, Material for (int subMeshIndex = 0; subMeshIndex < subMeshCount; subMeshIndex++) { var subMeshMaterial = meshMaterials[subMeshIndex]; -#if UNITY_MESH_INDEXFORMAT_SUPPORT var subMeshIndices = mesh.GetTriangles(subMeshIndex, true); -#else - var subMeshIndices = mesh.GetTriangles(subMeshIndex); -#endif if (currentVertexCount > 0) { diff --git a/Runtime/MeshSimplifier.cs b/Runtime/MeshSimplifier.cs index d275dce..027b703 100644 --- a/Runtime/MeshSimplifier.cs +++ b/Runtime/MeshSimplifier.cs @@ -37,14 +37,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE //https://github.com/sp4cerat/Fast-Quadric-Mesh-Simplification #endregion -#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020 +#if UNITY_2018_2_OR_NEWER #define UNITY_8UV_SUPPORT #endif -#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020 -#define UNITY_MESH_INDEXFORMAT_SUPPORT -#endif - using System; using System.Collections.Generic; using System.Runtime.CompilerServices; diff --git a/Runtime/Utility/MeshUtils.cs b/Runtime/Utility/MeshUtils.cs index 0453c67..ea777bf 100644 --- a/Runtime/Utility/MeshUtils.cs +++ b/Runtime/Utility/MeshUtils.cs @@ -24,21 +24,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #endregion -#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020 +#if UNITY_2018_2_OR_NEWER #define UNITY_8UV_SUPPORT #endif -#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020 -#define UNITY_MESH_INDEXFORMAT_SUPPORT -#endif - using System; using System.Collections.Generic; using UnityEngine; - -#if UNITY_MESH_INDEXFORMAT_SUPPORT using UnityEngine.Rendering; -#endif namespace UnityMeshSimplifier { @@ -117,11 +110,9 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor var newMesh = new Mesh(); int subMeshCount = indices.Length; -#if UNITY_MESH_INDEXFORMAT_SUPPORT IndexFormat indexFormat; var indexMinMax = MeshUtils.GetSubMeshIndexMinMax(indices, out indexFormat); newMesh.indexFormat = indexFormat; -#endif if (bindposes != null && bindposes.Length > 0) { @@ -188,9 +179,8 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor for (int subMeshIndex = 0; subMeshIndex < subMeshCount; subMeshIndex++) { var subMeshTriangles = indices[subMeshIndex]; -#if UNITY_MESH_INDEXFORMAT_SUPPORT var minMax = indexMinMax[subMeshIndex]; - if (indexFormat == UnityEngine.Rendering.IndexFormat.UInt16 && minMax.y > ushort.MaxValue) + if (indexFormat == IndexFormat.UInt16 && minMax.y > ushort.MaxValue) { int baseVertex = minMax.x; for (int index = 0; index < subMeshTriangles.Length; index++) @@ -203,9 +193,6 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor { newMesh.SetTriangles(subMeshTriangles, subMeshIndex, false, 0); } -#else - newMesh.SetTriangles(subMeshTriangles, subMeshIndex, false); -#endif } newMesh.RecalculateBounds(); @@ -427,7 +414,6 @@ public static Vector3[] ConvertUVsTo3D(IList uvs) return uv3D; } -#if UNITY_MESH_INDEXFORMAT_SUPPORT /// /// Returns the minimum and maximum indices for each submesh along with the needed index format. /// @@ -455,7 +441,6 @@ public static Vector2Int[] GetSubMeshIndexMinMax(int[][] indices, out IndexForma } return result; } -#endif #endregion #region Private Methods diff --git a/Tests/Editor/MeshUtilsTest.cs b/Tests/Editor/MeshUtilsTest.cs index 140ea7b..6b66ba5 100644 --- a/Tests/Editor/MeshUtilsTest.cs +++ b/Tests/Editor/MeshUtilsTest.cs @@ -24,18 +24,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */ #endregion -#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020 -#define UNITY_MESH_INDEXFORMAT_SUPPORT -#endif - using System.Collections.Generic; using System.Linq; using UnityEngine; -using NUnit.Framework; - -#if UNITY_MESH_INDEXFORMAT_SUPPORT using UnityEngine.Rendering; -#endif +using NUnit.Framework; namespace UnityMeshSimplifier.Editor.Tests { @@ -412,10 +405,11 @@ public void ShouldGetMeshUVs() mesh.vertices = new Vector3[4]; for (int i = 0; i < uvs.Length; i++) { -#if UNITY_2018 - mesh.SetUVs(i, uvs[i].ToList()); -#else +#if UNITY_2019_3_OR_NEWER mesh.SetUVs(i, uvs[i]); + +#else + mesh.SetUVs(i, uvs[i].ToList()); #endif } @@ -429,7 +423,6 @@ public void ShouldGetMeshUVs() } } -#if UNITY_MESH_INDEXFORMAT_SUPPORT [Test] public void ShouldGetSubMeshIndexMinMax() { @@ -491,7 +484,6 @@ public void ShouldGetSubMeshIndexMinMax() Assert.AreEqual(expectedMinMaxIndices, minMaxIndices); Assert.AreEqual(IndexFormat.UInt32, indexFormat); } -#endif [Test] public void ShouldGetUsedUVComponents()