|
| 1 | +using System.Collections.Generic; |
| 2 | +using UObject = UnityEngine.Object; |
| 3 | +using UnityEngine; |
| 4 | +using NUnit.Framework; |
| 5 | +using UnityEditor; |
| 6 | +using UnityEditor.ProBuilder; |
| 7 | +using UnityEditor.ProBuilder.Actions; |
| 8 | +using UnityEngine.ProBuilder; |
| 9 | +using UnityEngine.ProBuilder.Shapes; |
| 10 | + |
| 11 | +public class MergeObjectsTest |
| 12 | +{ |
| 13 | + ProBuilderMesh m_mesh1; |
| 14 | + ProBuilderMesh m_mesh2; |
| 15 | + |
| 16 | + [SetUp] |
| 17 | + public void SetUp() |
| 18 | + { |
| 19 | + m_mesh1 = ShapeFactory.Instantiate<Cube>(); |
| 20 | + m_mesh2 = ShapeFactory.Instantiate<Cone>(); |
| 21 | + } |
| 22 | + |
| 23 | + [TearDown] |
| 24 | + public void Cleanup() |
| 25 | + { |
| 26 | + UObject.DestroyImmediate(m_mesh1); |
| 27 | + UObject.DestroyImmediate(m_mesh2); |
| 28 | + } |
| 29 | + |
| 30 | + [Test] |
| 31 | + [TestCase(typeof(PolyShape),typeof(PolyShape))] |
| 32 | + [TestCase(typeof(ProBuilderShape),typeof(ProBuilderShape))] |
| 33 | + [TestCase(typeof(ProBuilderShape),typeof(PolyShape))] |
| 34 | + public void MergeObjects_WithShapeCompPresent_ResultNoLongerHasShapeComp(System.Type shapeCompTypeA, System.Type shapeCompTypeB) |
| 35 | + { |
| 36 | + void AttachComponentOfType(ProBuilderMesh mesh, System.Type shapeCompType) |
| 37 | + { |
| 38 | + if (shapeCompType == typeof(PolyShape)) |
| 39 | + mesh.gameObject.AddComponent<PolyShape>(); |
| 40 | + else |
| 41 | + mesh.gameObject.AddComponent<ProBuilderShape>(); |
| 42 | + } |
| 43 | + |
| 44 | + var meshes = new List<ProBuilderMesh>(); |
| 45 | + meshes.Add(m_mesh1); |
| 46 | + meshes.Add(m_mesh2); |
| 47 | + |
| 48 | + Assume.That(meshes.Count, Is.EqualTo(2)); |
| 49 | + |
| 50 | + AttachComponentOfType(meshes[0], shapeCompTypeA); |
| 51 | + AttachComponentOfType(meshes[1], shapeCompTypeB); |
| 52 | + |
| 53 | + MeshSelection.SetSelection(new List<GameObject>( new[]{ m_mesh1.gameObject, m_mesh2.gameObject })); |
| 54 | + ActiveEditorTracker.sharedTracker.ForceRebuild(); |
| 55 | + |
| 56 | + var mergeObjectsAction = new MergeObjects(); |
| 57 | + var newMeshes = mergeObjectsAction.DoMergeObjectsAction(); |
| 58 | + |
| 59 | + Assume.That(newMeshes.Count, Is.EqualTo(1), "There should only be one mesh after merging objects."); |
| 60 | + |
| 61 | + var shapeCompFound = false; |
| 62 | + shapeCompFound |= newMeshes[0].gameObject.GetComponent<PolyShape>() != null; |
| 63 | + shapeCompFound |= newMeshes[0].gameObject.GetComponent<ProBuilderShape>() != null; |
| 64 | + |
| 65 | + Assert.That(shapeCompFound, Is.Not.True, $"There should be no {shapeCompTypeA.Name} or {shapeCompTypeB.Name} component on ProBuilder Meshes after mesh combine."); |
| 66 | + } |
| 67 | +} |
0 commit comments