Skip to content

Commit 64d67a9

Browse files
Merge pull request #583 from Unity-Technologies/bugfix/pbld-205-polyshape-merging
Fix for Edit PolyShape tool reverting previously merged polyshapes
2 parents 6beb723 + 1365a8a commit 64d67a9

File tree

4 files changed

+88
-2
lines changed

4 files changed

+88
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- [STO-3432] Fixed a bug where the Polyshape creation tool was not placing the first point on a custom grids correctly.
2424
- [PBLD-183] Fixed a bug where the **Extrude by** setting of the **Extrude Faces** action was always set to **Individual Faces**.
2525
- [STO-3442] Fixed a bug where hover-highlighted elements are not always selected.
26+
- [PBLD-205] Fixed a bug where the `Edit PolyShape` tool would revert previously merged PolyShape objects.
2627

2728
## [6.0.4] - 2024-09-12
2829

Editor/MenuActions/Object/MergeObjects.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using UnityEditor;
77
using UnityEditor.ProBuilder.UI;
88
using UnityEngine.ProBuilder.MeshOperations;
9+
using UnityEngine.ProBuilder.Shapes;
910

1011
namespace UnityEditor.ProBuilder.Actions
1112
{
@@ -39,6 +40,12 @@ protected override ActionResult PerformActionImplementation()
3940
if (MeshSelection.selectedObjectCount < 2)
4041
return new ActionResult(ActionResult.Status.Canceled, "Must Select 2+ Objects");
4142

43+
DoMergeObjectsAction();
44+
return new ActionResult(ActionResult.Status.Success, "Merged Objects");
45+
}
46+
47+
internal List<ProBuilderMesh> DoMergeObjectsAction()
48+
{
4249
var selected = MeshSelection.top.ToArray();
4350
ProBuilderMesh currentMesh = MeshSelection.activeMesh;
4451
UndoUtility.RecordObject(currentMesh, "Merge Objects");
@@ -53,8 +60,18 @@ protected override ActionResult PerformActionImplementation()
5360
{
5461
mesh.gameObject.name = Selection.activeGameObject.name + "-Merged";
5562
UndoUtility.RegisterCreatedObjectUndo(mesh.gameObject, "Merge Objects");
63+
5664
Selection.objects = res.Select(x => x.gameObject).ToArray();
5765
}
66+
67+
// Remove PolyShape and ProBuilderShape components if any are present post-merge
68+
var polyShapeComp = mesh.gameObject.GetComponent<PolyShape>();
69+
if (polyShapeComp != null )
70+
UndoUtility.DestroyImmediate(polyShapeComp);
71+
72+
var proBuilderShape = mesh.gameObject.GetComponent<ProBuilderShape>();
73+
if (proBuilderShape != null )
74+
UndoUtility.DestroyImmediate(proBuilderShape);
5875
}
5976

6077
// Delete donor objects if they are not part of the result
@@ -65,8 +82,7 @@ protected override ActionResult PerformActionImplementation()
6582
}
6683
}
6784

68-
ProBuilderEditor.Refresh();
69-
return new ActionResult(ActionResult.Status.Success, "Merged Objects");
85+
return res;
7086
}
7187
}
7288
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
}

Tests/Editor/Actions/MergeObjectsTest.cs.meta

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)