Skip to content

Commit e102878

Browse files
NoelStephensUnityjabbacakesVic-Cooper
authored
Noel stephens unity player cube controller editor update (#1375)
Co-authored-by: Amy Reeve <amy.reeve@unity3d.com> Co-authored-by: Vic Cooper <63712500+Vic-Cooper@users.noreply.github.com>
1 parent 6dfa71d commit e102878

File tree

1 file changed

+8
-41
lines changed

1 file changed

+8
-41
lines changed

docs/learn/distributed-authority-quick-start.md

Lines changed: 8 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -180,49 +180,25 @@ public class PlayerCubeControllerEditor : NetworkTransformEditor
180180
private SerializedProperty m_Speed;
181181
private SerializedProperty m_ApplyVerticalInputToZAxis;
182182

183-
184183
public override void OnEnable()
185184
{
186185
m_Speed = serializedObject.FindProperty(nameof(PlayerCubeController.Speed));
187186
m_ApplyVerticalInputToZAxis = serializedObject.FindProperty(nameof(PlayerCubeController.ApplyVerticalInputToZAxis));
188187
base.OnEnable();
189188
}
190189

190+
private void DisplayPlayerCubeControllerProperties()
191+
{
192+
EditorGUILayout.PropertyField(m_Speed);
193+
EditorGUILayout.PropertyField(m_ApplyVerticalInputToZAxis);
194+
}
191195

192196
public override void OnInspectorGUI()
193197
{
194198
var playerCubeController = target as PlayerCubeController;
195-
196-
197-
playerCubeController.PlayerCubeControllerPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.PlayerCubeControllerPropertiesVisible, $"{nameof(PlayerCubeController)} Properties");
198-
if (playerCubeController.PlayerCubeControllerPropertiesVisible)
199-
{
200-
EditorGUILayout.PropertyField(m_Speed);
201-
EditorGUILayout.PropertyField(m_ApplyVerticalInputToZAxis);
202-
}
203-
EditorGUILayout.EndFoldoutHeaderGroup();
204-
205-
206-
EditorGUILayout.Space();
207-
208-
209-
playerCubeController.NetworkTransformPropertiesVisible = EditorGUILayout.BeginFoldoutHeaderGroup(playerCubeController.NetworkTransformPropertiesVisible, $"{nameof(NetworkTransform)} Properties");
210-
if (playerCubeController.NetworkTransformPropertiesVisible)
211-
{
212-
// End the header group prior to invoking the base OnInspectorGUID in order to avoid nested
213-
// foldout groups.
214-
EditorGUILayout.EndFoldoutHeaderGroup();
215-
// If NetworkTransform properties are visible, then both the properties any modified properties
216-
// will be applied.
217-
base.OnInspectorGUI();
218-
}
219-
else
220-
{
221-
// End the header group
222-
EditorGUILayout.EndFoldoutHeaderGroup();
223-
// If NetworkTransform properties are not visible, then make sure we apply any modified properties.
224-
serializedObject.ApplyModifiedProperties();
225-
}
199+
void SetExpanded(bool expanded) { playerCubeController.PlayerCubeControllerPropertiesVisible = expanded; };
200+
DrawFoldOutGroup<PlayerCubeController>(playerCubeController.GetType(), DisplayPlayerCubeControllerProperties, playerCubeController.PlayerCubeControllerPropertiesVisible, SetExpanded);
201+
base.OnInspectorGUI();
226202
}
227203
}
228204
#endif
@@ -235,17 +211,11 @@ public class PlayerCubeController : NetworkTransform
235211
// within the inspector view will be saved and restored the next time the
236212
// asset/prefab is viewed.
237213
public bool PlayerCubeControllerPropertiesVisible;
238-
public bool NetworkTransformPropertiesVisible;
239214
#endif
240-
241-
242215
public float Speed = 10;
243216
public bool ApplyVerticalInputToZAxis;
244-
245-
246217
private Vector3 m_Motion;
247218

248-
249219
private void Update()
250220
{
251221
// If not spawned or we don't have authority, then don't update
@@ -254,12 +224,10 @@ public class PlayerCubeController : NetworkTransform
254224
return;
255225
}
256226

257-
258227
// Handle acquiring and applying player input
259228
m_Motion = Vector3.zero;
260229
m_Motion.x = Input.GetAxis("Horizontal");
261230

262-
263231
// Determine whether the vertical input is applied to the Y or Z axis
264232
if (!ApplyVerticalInputToZAxis)
265233
{
@@ -270,7 +238,6 @@ public class PlayerCubeController : NetworkTransform
270238
m_Motion.z = Input.GetAxis("Vertical");
271239
}
272240

273-
274241
// If there is any player input magnitude, then apply that amount of
275242
// motion to the transform
276243
if (m_Motion.magnitude > 0)

0 commit comments

Comments
 (0)