Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions Tests/Editor/Editor/MeshSyncTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ static IEnumerable CopyPasteDuplicate
}
}

static ulong GetRawId(Object obj)
{
var id = obj.GetObjectId();

#if UNITY_6000_4_OR_NEWER
return id.GetRawData();
#else
return (ulong)id;
#endif
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of casting an int into a ulong - which can cause loss of precision somwhere, you could define an ID type based on the #ifdef

#if UNITY_6000_4_OR_NEWER
using UObjectID = UnityEngine.EntityId;
#else
using UObjectID = System.Int32;
#endif


[Test]
[TestCaseSource(nameof(CopyPasteDuplicate))]
public void ExecuteCopyPasteDuplicate_CreatesUniqueMesh(string[] commands)
Expand All @@ -52,7 +63,7 @@ public void ExecuteCopyPasteDuplicate_CreatesUniqueMesh(string[] commands)
var cube = ShapeGenerator.CreateShape(ShapeType.Cube, PivotLocation.FirstVertex);
cube.transform.parent = parent;
Assume.That(parent.childCount, Is.EqualTo(1));
int originalMeshId = cube.GetComponent<MeshFilter>().sharedMesh.GetObjectId();
ulong originalMeshId = GetRawId(cube.GetComponent<MeshFilter>().sharedMesh);

Selection.activeObject = cube.gameObject;

Expand All @@ -72,7 +83,7 @@ public void ExecuteCopyPasteDuplicate_CreatesUniqueMesh(string[] commands)
HierarchyListener.OnObjectCreated(copy);

Assume.That(copy, Is.Not.EqualTo(cube));
Assert.That(copy.GetComponent<MeshFilter>().sharedMesh.GetObjectId(), Is.Not.EqualTo(originalMeshId));
Assert.That(GetRawId(copy.GetComponent<MeshFilter>().sharedMesh), Is.Not.EqualTo(originalMeshId));
}

//[PBLD-75] Sending the event to the scene view is needed as just calling HierarchyListener.OnObjectCreated
Expand All @@ -89,7 +100,7 @@ public IEnumerator ExecuteCopyPasteDuplicateOnParent_CreatesUniqueMesh()
cube.transform.parent = emptyGO;

Assume.That(parent.childCount, Is.EqualTo(1));
int originalMeshId = cube.GetComponent<MeshFilter>().sharedMesh.GetObjectId();
ulong originalMeshId = GetRawId(cube.GetComponent<MeshFilter>().sharedMesh);

Selection.objects = new[] { emptyGO.gameObject };
ActiveEditorTracker.sharedTracker.ForceRebuild();
Expand Down Expand Up @@ -117,7 +128,7 @@ public IEnumerator ExecuteCopyPasteDuplicateOnParent_CreatesUniqueMesh()
HierarchyListener.OnObjectCreated(copy);

Assume.That(copy, Is.Not.EqualTo(cube));
Assert.That(copy.GetComponent<MeshFilter>().sharedMesh.GetObjectId(), Is.Not.EqualTo(originalMeshId));
Assert.That(GetRawId(copy.GetComponent<MeshFilter>().sharedMesh), Is.Not.EqualTo(originalMeshId));
}

[Test]
Expand Down