@@ -26,6 +26,10 @@ public float CameraZoom
26
26
public UIDocument SceneOptionsUI { get ; set ; }
27
27
28
28
private bool ColorShapeState { get ; set ; }
29
+ private ControlsMenu . CustomButton m_PausePlayButton ;
30
+ private ControlsMenu . CustomButton m_StepButton ;
31
+ private ControlsMenu . CustomButton m_DebugButton ;
32
+ private ControlsMenu . CustomButton m_UIButton ;
29
33
private ControlsMenu . CustomButton m_QuitButton ;
30
34
31
35
public string StartScene = string . Empty ;
@@ -181,69 +185,6 @@ private struct MenuDefaults
181
185
public Color32 ShapeColorState => ColorShapeState ? new Color32 ( ) : new Color32 ( ( byte ) m_Random . NextUInt ( 0 , 256 ) , ( byte ) m_Random . NextUInt ( 0 , 256 ) , ( byte ) m_Random . NextUInt ( 0 , 256 ) , 255 ) ;
182
186
bool IShapeColorProvider . IsShapeColorActive => ColorShapeState ;
183
187
184
- public void ResetSceneState ( )
185
- {
186
- // Disable any "SceneBody".
187
- foreach ( var sceneBody in FindObjectsByType < SceneBody > ( FindObjectsInactive . Include , FindObjectsSortMode . None ) )
188
- sceneBody . enabled = false ;
189
-
190
- // Disable any "SceneWorlds".
191
- foreach ( var sceneWorld in FindObjectsByType < SceneWorld > ( FindObjectsSortMode . None ) )
192
- sceneWorld . enabled = false ;
193
-
194
- {
195
- var destroyBodies = new NativeList < PhysicsBody > ( 1000 , Allocator . Temp ) ;
196
-
197
- // Iterate all worlds.
198
- using var allWorlds = PhysicsWorld . GetWorlds ( ) ;
199
- foreach ( var world in allWorlds )
200
- {
201
- // Iterate all non-owned bodies.
202
- using var bodies = world . GetBodies ( ) ;
203
- foreach ( var body in bodies )
204
- {
205
- if ( ! body . isOwned )
206
- destroyBodies . Add ( body ) ;
207
- }
208
- }
209
-
210
- if ( destroyBodies . Length > 0 )
211
- PhysicsWorld . DestroyBodyBatch ( destroyBodies . AsArray ( ) ) ;
212
-
213
- // Dispose.
214
- destroyBodies . Dispose ( ) ;
215
- }
216
-
217
- // Clear the debug draw.
218
- ClearDebugDraw ( ) ;
219
-
220
- // Reset random generator.
221
- m_Random . InitState ( 0x42424242 ) ;
222
-
223
- // Reset the default world.
224
- PhysicsWorld . defaultWorld . Reset ( ) ;
225
-
226
- // Enable any "SceneWorlds".
227
- foreach ( var sceneWorld in FindObjectsByType < SceneWorld > ( FindObjectsSortMode . None ) )
228
- sceneWorld . enabled = true ;
229
-
230
- // Enable all bodies again.
231
- foreach ( var sceneBody in FindObjectsByType < SceneBody > ( FindObjectsInactive . Include , FindObjectsSortMode . None ) )
232
- sceneBody . enabled = true ;
233
- }
234
-
235
- private void OnEnable ( )
236
- {
237
- // We don't want this appearing all the time.
238
- UnityEngine . Rendering . DebugManager . instance . enableRuntimeUI = false ;
239
-
240
- m_DrawFlagElements = new Dictionary < PhysicsWorld . DrawOptions , Toggle > ( capacity : 8 ) ;
241
-
242
- // Overrides.
243
- m_OverrideDrawOptions = PhysicsWorld . DrawOptions . Off ;
244
- m_OverridePreviousDrawOptions = PhysicsWorld . DrawOptions . Off ;
245
- }
246
-
247
188
private void Start ( )
248
189
{
249
190
m_CameraManipulator = FindFirstObjectByType < CameraManipulator > ( ) ;
@@ -258,8 +199,17 @@ private void Start()
258
199
259
200
// Reset the controls.
260
201
ControlsMenu . ResetControls ( ) ;
202
+ m_PausePlayButton = ControlsMenu . pausePlayButton ;
203
+ m_StepButton = ControlsMenu . stepButton ;
204
+ m_DebugButton = ControlsMenu . debugButton ;
205
+ m_UIButton = ControlsMenu . uiButton ;
261
206
m_QuitButton = ControlsMenu . quitButton ;
262
-
207
+
208
+ m_PausePlayButton . button . clickable . clicked += TogglePauseContinue ;
209
+ m_StepButton . button . clickable . clicked += SingleStep ;
210
+ m_DebugButton . button . clickable . clicked += ToggleDebugging ;
211
+ m_UIButton . button . clickable . clicked += ToggleUI ;
212
+
263
213
var defaultWorld = PhysicsWorld . defaultWorld ;
264
214
m_MenuDefaults = new MenuDefaults
265
215
{
@@ -290,9 +240,21 @@ private void Start()
290
240
m_UpdateTimeFPS = UpdatePeriodFPS ;
291
241
}
292
242
243
+ private void OnEnable ( )
244
+ {
245
+ // We don't want this appearing all the time.
246
+ UnityEngine . Rendering . DebugManager . instance . enableRuntimeUI = false ;
247
+
248
+ m_DrawFlagElements = new Dictionary < PhysicsWorld . DrawOptions , Toggle > ( capacity : 8 ) ;
249
+
250
+ // Overrides.
251
+ m_OverrideDrawOptions = PhysicsWorld . DrawOptions . Off ;
252
+ m_OverridePreviousDrawOptions = PhysicsWorld . DrawOptions . Off ;
253
+ }
254
+
293
255
private void Update ( )
294
256
{
295
- // Keyboard Controls.
257
+ // Controls.
296
258
{
297
259
var currentKeyboard = Keyboard . current ;
298
260
@@ -310,32 +272,13 @@ private void Update()
310
272
// Toggle UI.
311
273
if ( currentKeyboard . tabKey . wasPressedThisFrame )
312
274
{
313
- m_ShowUI = ! m_ShowUI ;
314
-
315
- // Debugging Menu.
316
- if ( m_ShowDebuggingElement . value )
317
- DebuggingMenu . gameObject . SetActive ( m_ShowUI ) ;
318
-
319
- // Toggle Shortcut Menu.
320
- ShortcutMenu . gameObject . SetActive ( ! ShortcutMenu . gameObject . activeInHierarchy ) ;
321
-
322
- // Main Menu.
323
- m_MainMenuDocument . rootVisualElement . style . display = m_ShowUI ? DisplayStyle . Flex : DisplayStyle . None ;
324
-
325
- // If we have an assigned scene options UI then toggle it.
326
- if ( SceneOptionsUI != null )
327
- SceneOptionsUI . enabled = m_ShowUI ;
328
-
275
+ ToggleUI ( ) ;
329
276
return ;
330
277
}
331
278
332
279
// Single-Step.
333
280
if ( currentKeyboard . sKey . wasPressedThisFrame )
334
281
{
335
- // Pause the world if we're not already paused.
336
- if ( ! WorldPaused )
337
- TogglePauseContinue ( ) ;
338
-
339
282
// Single-step.
340
283
SingleStep ( ) ;
341
284
}
@@ -349,7 +292,7 @@ private void Update()
349
292
// Debugging.
350
293
if ( currentKeyboard . dKey . wasPressedThisFrame )
351
294
{
352
- m_ShowDebuggingElement . value = ! m_ShowDebuggingElement . value ;
295
+ ToggleDebugging ( ) ;
353
296
}
354
297
355
298
// Toggle Color PhysicsShape State.
@@ -389,6 +332,81 @@ private void Update()
389
332
}
390
333
}
391
334
335
+ private void ToggleUI ( )
336
+ {
337
+ m_ShowUI = ! m_ShowUI ;
338
+
339
+ // Debugging Menu.
340
+ if ( m_ShowDebuggingElement . value )
341
+ DebuggingMenu . gameObject . SetActive ( m_ShowUI ) ;
342
+
343
+ // Toggle Shortcut Menu.
344
+ ShortcutMenu . gameObject . SetActive ( ! ShortcutMenu . gameObject . activeInHierarchy ) ;
345
+
346
+ // Main Menu.
347
+ m_MainMenuDocument . rootVisualElement . style . display = m_ShowUI ? DisplayStyle . Flex : DisplayStyle . None ;
348
+
349
+ // If we have an assigned scene options UI then toggle it.
350
+ if ( SceneOptionsUI != null )
351
+ SceneOptionsUI . enabled = m_ShowUI ;
352
+ }
353
+
354
+ private void ToggleDebugging ( )
355
+ {
356
+ m_ShowDebuggingElement . value = ! m_ShowDebuggingElement . value ;
357
+ }
358
+
359
+ public void ResetSceneState ( )
360
+ {
361
+ // Disable any "SceneBody".
362
+ foreach ( var sceneBody in FindObjectsByType < SceneBody > ( FindObjectsInactive . Include , FindObjectsSortMode . None ) )
363
+ sceneBody . enabled = false ;
364
+
365
+ // Disable any "SceneWorlds".
366
+ foreach ( var sceneWorld in FindObjectsByType < SceneWorld > ( FindObjectsSortMode . None ) )
367
+ sceneWorld . enabled = false ;
368
+
369
+ {
370
+ var destroyBodies = new NativeList < PhysicsBody > ( 1000 , Allocator . Temp ) ;
371
+
372
+ // Iterate all worlds.
373
+ using var allWorlds = PhysicsWorld . GetWorlds ( ) ;
374
+ foreach ( var world in allWorlds )
375
+ {
376
+ // Iterate all non-owned bodies.
377
+ using var bodies = world . GetBodies ( ) ;
378
+ foreach ( var body in bodies )
379
+ {
380
+ if ( ! body . isOwned )
381
+ destroyBodies . Add ( body ) ;
382
+ }
383
+ }
384
+
385
+ if ( destroyBodies . Length > 0 )
386
+ PhysicsWorld . DestroyBodyBatch ( destroyBodies . AsArray ( ) ) ;
387
+
388
+ // Dispose.
389
+ destroyBodies . Dispose ( ) ;
390
+ }
391
+
392
+ // Clear the debug draw.
393
+ ClearDebugDraw ( ) ;
394
+
395
+ // Reset random generator.
396
+ m_Random . InitState ( 0x42424242 ) ;
397
+
398
+ // Reset the default world.
399
+ PhysicsWorld . defaultWorld . Reset ( ) ;
400
+
401
+ // Enable any "SceneWorlds".
402
+ foreach ( var sceneWorld in FindObjectsByType < SceneWorld > ( FindObjectsSortMode . None ) )
403
+ sceneWorld . enabled = true ;
404
+
405
+ // Enable all bodies again.
406
+ foreach ( var sceneBody in FindObjectsByType < SceneBody > ( FindObjectsInactive . Include , FindObjectsSortMode . None ) )
407
+ sceneBody . enabled = true ;
408
+ }
409
+
392
410
private void SetupOptions ( )
393
411
{
394
412
var root = m_MainMenuDocument . rootVisualElement ;
@@ -777,15 +795,14 @@ private void TogglePauseContinue()
777
795
778
796
private void SingleStep ( )
779
797
{
798
+ if ( ! WorldPaused )
799
+ return ;
800
+
780
801
var defaultWorld = PhysicsWorld . defaultWorld ;
781
802
782
803
var oldPaused = defaultWorld . paused ;
783
804
var oldSimulationMode = defaultWorld . simulationMode ;
784
805
785
- // Pause thw world if we're not already paused.
786
- if ( ! WorldPaused )
787
- TogglePauseContinue ( ) ;
788
-
789
806
// Update the worlds.
790
807
using var worlds = PhysicsWorld . GetWorlds ( ) ;
791
808
foreach ( var world in worlds )
0 commit comments