Skip to content

Commit

Permalink
fix: support Unity 2021
Browse files Browse the repository at this point in the history
  • Loading branch information
Whinarn committed Jun 25, 2021
1 parent 2c6be8c commit 2f2eb3b
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 46 deletions.
4 changes: 2 additions & 2 deletions Editor/LODGeneratorHelperEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 1 addition & 9 deletions Runtime/MeshCombiner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#region License
#region License
/*
MIT License
Expand All @@ -24,10 +24,6 @@ MIT License
*/
#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;
Expand Down Expand Up @@ -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)
{
Expand Down
6 changes: 1 addition & 5 deletions Runtime/MeshSimplifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,10 @@ MIT License
//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;
Expand Down
19 changes: 2 additions & 17 deletions Runtime/Utility/MeshUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,14 @@ MIT License
*/
#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
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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++)
Expand All @@ -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();
Expand Down Expand Up @@ -427,7 +414,6 @@ public static Vector3[] ConvertUVsTo3D(IList<Vector4> uvs)
return uv3D;
}

#if UNITY_MESH_INDEXFORMAT_SUPPORT
/// <summary>
/// Returns the minimum and maximum indices for each submesh along with the needed index format.
/// </summary>
Expand Down Expand Up @@ -455,7 +441,6 @@ public static Vector2Int[] GetSubMeshIndexMinMax(int[][] indices, out IndexForma
}
return result;
}
#endif
#endregion

#region Private Methods
Expand Down
18 changes: 5 additions & 13 deletions Tests/Editor/MeshUtilsTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,11 @@ MIT License
*/
#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
{
Expand Down Expand Up @@ -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
}

Expand All @@ -429,7 +423,6 @@ public void ShouldGetMeshUVs()
}
}

#if UNITY_MESH_INDEXFORMAT_SUPPORT
[Test]
public void ShouldGetSubMeshIndexMinMax()
{
Expand Down Expand Up @@ -491,7 +484,6 @@ public void ShouldGetSubMeshIndexMinMax()
Assert.AreEqual(expectedMinMaxIndices, minMaxIndices);
Assert.AreEqual(IndexFormat.UInt32, indexFormat);
}
#endif

[Test]
public void ShouldGetUsedUVComponents()
Expand Down

0 comments on commit 2f2eb3b

Please sign in to comment.