Skip to content

Commit 2f2eb3b

Browse files
committed
fix: support Unity 2021
1 parent 2c6be8c commit 2f2eb3b

File tree

5 files changed

+11
-46
lines changed

5 files changed

+11
-46
lines changed

Editor/LODGeneratorHelperEditor.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -618,12 +618,12 @@ where go.transform.IsChildOf(ourTransform)
618618

619619
var notChildGameObjects = from go in gameObjects
620620
where !go.transform.IsChildOf(ourTransform)
621-
#if UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020
621+
#if UNITY_2018_3_OR_NEWER
622622
&& !PrefabUtility.IsPartOfAnyPrefab(go)
623623
#endif
624624
select go;
625625

626-
#if UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020
626+
#if UNITY_2018_3_OR_NEWER
627627
var prefabGameObjects = from go in gameObjects
628628
where !go.transform.IsChildOf(ourTransform) &&
629629
PrefabUtility.IsPartOfAnyPrefab(go)

Runtime/MeshCombiner.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#region License
1+
#region License
22
/*
33
MIT License
44
@@ -24,10 +24,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
*/
2525
#endregion
2626

27-
#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020
28-
#define UNITY_MESH_INDEXFORMAT_SUPPORT
29-
#endif
30-
3127
using System.Collections.Generic;
3228
using System.Linq;
3329
using UnityEngine;
@@ -287,11 +283,7 @@ public static Mesh CombineMeshes(Mesh[] meshes, Matrix4x4[] transforms, Material
287283
for (int subMeshIndex = 0; subMeshIndex < subMeshCount; subMeshIndex++)
288284
{
289285
var subMeshMaterial = meshMaterials[subMeshIndex];
290-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
291286
var subMeshIndices = mesh.GetTriangles(subMeshIndex, true);
292-
#else
293-
var subMeshIndices = mesh.GetTriangles(subMeshIndex);
294-
#endif
295287

296288
if (currentVertexCount > 0)
297289
{

Runtime/MeshSimplifier.cs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,10 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
3737
//https://github.com/sp4cerat/Fast-Quadric-Mesh-Simplification
3838
#endregion
3939

40-
#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020
40+
#if UNITY_2018_2_OR_NEWER
4141
#define UNITY_8UV_SUPPORT
4242
#endif
4343

44-
#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020
45-
#define UNITY_MESH_INDEXFORMAT_SUPPORT
46-
#endif
47-
4844
using System;
4945
using System.Collections.Generic;
5046
using System.Runtime.CompilerServices;

Runtime/Utility/MeshUtils.cs

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,14 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
*/
2525
#endregion
2626

27-
#if UNITY_2018_2 || UNITY_2018_3 || UNITY_2018_4 || UNITY_2019 || UNITY_2020
27+
#if UNITY_2018_2_OR_NEWER
2828
#define UNITY_8UV_SUPPORT
2929
#endif
3030

31-
#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020
32-
#define UNITY_MESH_INDEXFORMAT_SUPPORT
33-
#endif
34-
3531
using System;
3632
using System.Collections.Generic;
3733
using UnityEngine;
38-
39-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
4034
using UnityEngine.Rendering;
41-
#endif
4235

4336
namespace UnityMeshSimplifier
4437
{
@@ -117,11 +110,9 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor
117110
var newMesh = new Mesh();
118111
int subMeshCount = indices.Length;
119112

120-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
121113
IndexFormat indexFormat;
122114
var indexMinMax = MeshUtils.GetSubMeshIndexMinMax(indices, out indexFormat);
123115
newMesh.indexFormat = indexFormat;
124-
#endif
125116

126117
if (bindposes != null && bindposes.Length > 0)
127118
{
@@ -188,9 +179,8 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor
188179
for (int subMeshIndex = 0; subMeshIndex < subMeshCount; subMeshIndex++)
189180
{
190181
var subMeshTriangles = indices[subMeshIndex];
191-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
192182
var minMax = indexMinMax[subMeshIndex];
193-
if (indexFormat == UnityEngine.Rendering.IndexFormat.UInt16 && minMax.y > ushort.MaxValue)
183+
if (indexFormat == IndexFormat.UInt16 && minMax.y > ushort.MaxValue)
194184
{
195185
int baseVertex = minMax.x;
196186
for (int index = 0; index < subMeshTriangles.Length; index++)
@@ -203,9 +193,6 @@ public static Mesh CreateMesh(Vector3[] vertices, int[][] indices, Vector3[] nor
203193
{
204194
newMesh.SetTriangles(subMeshTriangles, subMeshIndex, false, 0);
205195
}
206-
#else
207-
newMesh.SetTriangles(subMeshTriangles, subMeshIndex, false);
208-
#endif
209196
}
210197

211198
newMesh.RecalculateBounds();
@@ -427,7 +414,6 @@ public static Vector3[] ConvertUVsTo3D(IList<Vector4> uvs)
427414
return uv3D;
428415
}
429416

430-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
431417
/// <summary>
432418
/// Returns the minimum and maximum indices for each submesh along with the needed index format.
433419
/// </summary>
@@ -455,7 +441,6 @@ public static Vector2Int[] GetSubMeshIndexMinMax(int[][] indices, out IndexForma
455441
}
456442
return result;
457443
}
458-
#endif
459444
#endregion
460445

461446
#region Private Methods

Tests/Editor/MeshUtilsTest.cs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,11 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2424
*/
2525
#endregion
2626

27-
#if UNITY_2017_3 || UNITY_2017_4 || UNITY_2018 || UNITY_2019 || UNITY_2020
28-
#define UNITY_MESH_INDEXFORMAT_SUPPORT
29-
#endif
30-
3127
using System.Collections.Generic;
3228
using System.Linq;
3329
using UnityEngine;
34-
using NUnit.Framework;
35-
36-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
3730
using UnityEngine.Rendering;
38-
#endif
31+
using NUnit.Framework;
3932

4033
namespace UnityMeshSimplifier.Editor.Tests
4134
{
@@ -412,10 +405,11 @@ public void ShouldGetMeshUVs()
412405
mesh.vertices = new Vector3[4];
413406
for (int i = 0; i < uvs.Length; i++)
414407
{
415-
#if UNITY_2018
416-
mesh.SetUVs(i, uvs[i].ToList());
417-
#else
408+
#if UNITY_2019_3_OR_NEWER
418409
mesh.SetUVs(i, uvs[i]);
410+
411+
#else
412+
mesh.SetUVs(i, uvs[i].ToList());
419413
#endif
420414
}
421415

@@ -429,7 +423,6 @@ public void ShouldGetMeshUVs()
429423
}
430424
}
431425

432-
#if UNITY_MESH_INDEXFORMAT_SUPPORT
433426
[Test]
434427
public void ShouldGetSubMeshIndexMinMax()
435428
{
@@ -491,7 +484,6 @@ public void ShouldGetSubMeshIndexMinMax()
491484
Assert.AreEqual(expectedMinMaxIndices, minMaxIndices);
492485
Assert.AreEqual(IndexFormat.UInt32, indexFormat);
493486
}
494-
#endif
495487

496488
[Test]
497489
public void ShouldGetUsedUVComponents()

0 commit comments

Comments
 (0)