Skip to content

Commit 3f91fbc

Browse files
fix: multi object selection support for axis to synchronize toggles in network transform (#3781)
* fix editing of the axis to synchronize toggles in network transform - with multi object selection the last object selected was overriding the other objects - enabled multi select support on the toggle fields so it will properly show a dash when a mix of values is present * update changelog --------- Co-authored-by: Noel Stephens <[email protected]>
1 parent a3bb5e8 commit 3f91fbc

File tree

2 files changed

+33
-9
lines changed

2 files changed

+33
-9
lines changed

com.unity.netcode.gameobjects/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ Additional documentation and release notes are available at [Multiplayer Documen
2424

2525
### Fixed
2626

27+
- Fixed issue where the `Axis to Synchronize` toggles didn't work with multi object editing in `NetworkTransform`. (#3781)
28+
2729

2830
### Security
2931

com.unity.netcode.gameobjects/Editor/NetworkTransformEditor.cs

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ private void DisplayNetworkTransformProperties()
107107
rect = EditorGUI.PrefixLabel(rect, ctid, s_PositionLabel);
108108
rect.width = s_ToggleOffset;
109109

110-
m_SyncPositionXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncPositionXProperty.boolValue);
110+
DrawToggleProperty(rect, "X", m_SyncPositionXProperty);
111111
rect.x += s_ToggleOffset;
112-
m_SyncPositionYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncPositionYProperty.boolValue);
112+
DrawToggleProperty(rect, "Y", m_SyncPositionYProperty);
113113
rect.x += s_ToggleOffset;
114-
m_SyncPositionZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncPositionZProperty.boolValue);
114+
DrawToggleProperty(rect, "Z", m_SyncPositionZProperty);
115115

116116
GUILayout.EndHorizontal();
117117
}
@@ -126,11 +126,11 @@ private void DisplayNetworkTransformProperties()
126126
rect = EditorGUI.PrefixLabel(rect, ctid, s_RotationLabel);
127127
rect.width = s_ToggleOffset;
128128

129-
m_SyncRotationXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncRotationXProperty.boolValue);
129+
DrawToggleProperty(rect, "X", m_SyncRotationXProperty);
130130
rect.x += s_ToggleOffset;
131-
m_SyncRotationYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncRotationYProperty.boolValue);
131+
DrawToggleProperty(rect, "Y", m_SyncRotationYProperty);
132132
rect.x += s_ToggleOffset;
133-
m_SyncRotationZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncRotationZProperty.boolValue);
133+
DrawToggleProperty(rect, "Z", m_SyncRotationZProperty);
134134

135135
GUILayout.EndHorizontal();
136136
}
@@ -150,11 +150,11 @@ private void DisplayNetworkTransformProperties()
150150
rect = EditorGUI.PrefixLabel(rect, ctid, s_ScaleLabel);
151151
rect.width = s_ToggleOffset;
152152

153-
m_SyncScaleXProperty.boolValue = EditorGUI.ToggleLeft(rect, "X", m_SyncScaleXProperty.boolValue);
153+
DrawToggleProperty(rect, "X", m_SyncScaleXProperty);
154154
rect.x += s_ToggleOffset;
155-
m_SyncScaleYProperty.boolValue = EditorGUI.ToggleLeft(rect, "Y", m_SyncScaleYProperty.boolValue);
155+
DrawToggleProperty(rect, "Y", m_SyncScaleYProperty);
156156
rect.x += s_ToggleOffset;
157-
m_SyncScaleZProperty.boolValue = EditorGUI.ToggleLeft(rect, "Z", m_SyncScaleZProperty.boolValue);
157+
DrawToggleProperty(rect, "Z", m_SyncScaleZProperty);
158158

159159
GUILayout.EndHorizontal();
160160
}
@@ -281,6 +281,28 @@ private void DisplayNetworkTransformProperties()
281281
#endif // COM_UNITY_MODULES_PHYSICS2D
282282
}
283283

284+
/// <summary>
285+
/// Draw a ToggleLeft property field so it will support multi selection editing if applicable.
286+
/// </summary>
287+
private void DrawToggleProperty(Rect rect, string label, SerializedProperty property)
288+
{
289+
if (property.hasMultipleDifferentValues)
290+
{
291+
EditorGUI.showMixedValue = true;
292+
EditorGUI.BeginChangeCheck();
293+
bool enabled = EditorGUI.ToggleLeft(rect, label, property.boolValue);
294+
if (EditorGUI.EndChangeCheck())
295+
{
296+
property.boolValue = enabled;
297+
}
298+
EditorGUI.showMixedValue = false;
299+
}
300+
else
301+
{
302+
property.boolValue = EditorGUI.ToggleLeft(rect, label, property.boolValue);
303+
}
304+
}
305+
284306
/// <inheritdoc/>
285307
public override void OnInspectorGUI()
286308
{

0 commit comments

Comments
 (0)