-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathTopMenu.cs
More file actions
677 lines (559 loc) · 25 KB
/
TopMenu.cs
File metadata and controls
677 lines (559 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
using AGXUnity;
using AGXUnity.Collide;
using AGXUnity.Model;
using AGXUnity.Sensor;
using AGXUnity.Utils;
using UnityEditor;
using UnityEngine;
using Mesh = AGXUnity.Collide.Mesh;
using Plane = AGXUnity.Collide.Plane;
namespace AGXUnityEditor
{
public static class TopMenu
{
public static readonly string AGXDynamicsForUnityManualURL = "https://us.download.algoryx.se/AGXUnity/documentation/current/";
public static readonly string AGXDynamicsForUnityExamplesURL = "https://us.download.algoryx.se/AGXUnity/documentation/current/examples.html";
public static readonly string AGXUserManualURL = "https://www.algoryx.se/documentation/complete/agx/tags/latest/UserManual/source/";
public static readonly string AGXAPIReferenceURL = "https://www.algoryx.se/documentation/complete/agx/tags/latest/";
public static readonly string AGXUnityChangelogURL = "https://us.download.algoryx.se/AGXUnity/documentation/current/changelog.html";
#region Shapes
private static GameObject CreateShape<T>( MenuCommand command )
where T : Shape
{
var go = Factory.Create<T>();
if ( go == null )
return null;
var parent = command.context as GameObject;
var views = SceneView.sceneViews;
if ( parent != null )
go.transform.SetParent( parent.transform, false );
else if ( SceneView.sceneViews.Count > 0 ) {
var view = SceneView.sceneViews[0] as SceneView;
if ( view != null )
view.MoveToView( go.transform );
}
AGXUnity.Rendering.ShapeVisual.Create( go.GetComponent<T>() );
Undo.RegisterCreatedObjectUndo( go, "shape" );
return go;
}
[MenuItem( "AGXUnity/Collide/Box", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Box", validate = false, priority = 10 )]
public static GameObject CreateBox( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Box>( command );
}
[MenuItem( "AGXUnity/Collide/Sphere", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Sphere", validate = false, priority = 10 )]
public static GameObject CreateSphere( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Sphere>( command );
}
[MenuItem( "AGXUnity/Collide/Capsule", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Capsule", validate = false, priority = 10 )]
public static GameObject CreateCapsule( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Capsule>( command );
}
[MenuItem( "AGXUnity/Collide/Cylinder", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Cylinder", validate = false, priority = 10 )]
public static GameObject CreateCylinder( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Cylinder>( command );
}
[MenuItem( "AGXUnity/Collide/Plane", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Plane", validate = false, priority = 10 )]
public static GameObject CreatePlane( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Plane>( command );
}
[MenuItem( "AGXUnity/Collide/Mesh", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Mesh", validate = false, priority = 10 )]
public static GameObject CreateMesh( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Mesh>( command );
}
[MenuItem( "AGXUnity/Collide/HollowCylinder", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Hollow Cylinder", validate = false, priority = 10 )]
public static GameObject CreateHollowCylinder( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<HollowCylinder>( command );
}
[MenuItem( "AGXUnity/Collide/Cone", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Cone", validate = false, priority = 10 )]
public static GameObject CreateCone( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<Cone>( command );
}
[MenuItem( "AGXUnity/Collide/HollowCone", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Collide/Hollow Cone", validate = false, priority = 10 )]
public static GameObject CreateHollowCone( MenuCommand command )
{
return Selection.activeGameObject = CreateShape<HollowCone>( command );
}
#endregion
#region Rigid bodies
private static GameObject CreateRigidBody( MenuCommand command, GameObject child = null )
{
var parent = command.context as GameObject;
var go = child != null ?
Factory.Create<RigidBody>( child ) :
Factory.Create<RigidBody>();
if ( go == null )
return null;
if ( parent != null )
go.transform.SetParent( parent.transform, false );
Undo.RegisterCreatedObjectUndo( go, "Rigid body" );
return go;
}
private static GameObject CreateRigidBody<T>( MenuCommand command )
where T : Shape
{
return CreateRigidBody( command, CreateShape<T>( new MenuCommand( null ) ) );
}
[MenuItem( "AGXUnity/Rigid body/Box", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Box", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyBox( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Box>( command );
}
[MenuItem( "AGXUnity/Rigid body/Sphere", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Sphere", validate = false, priority = 10 )]
public static GameObject CreateRigidBodySphere( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Sphere>( command );
}
[MenuItem( "AGXUnity/Rigid body/Capsule", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Capsule", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyCapsule( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Capsule>( command );
}
[MenuItem( "AGXUnity/Rigid body/Cylinder", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Cylinder", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyCylinder( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Cylinder>( command );
}
[MenuItem( "AGXUnity/Rigid body/Mesh", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Mesh", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyMesh( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Mesh>( command );
}
[MenuItem( "AGXUnity/Rigid body/Hollow Cylinder", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Hollow Cylinder", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyHollowCylinder( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<HollowCylinder>( command );
}
[MenuItem( "AGXUnity/Rigid body/Cone", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Cone", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyCone( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<Cone>( command );
}
[MenuItem( "AGXUnity/Rigid body/Hollow Cone", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Hollow Cone", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyHollowCone( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody<HollowCone>( command );
}
[MenuItem( "AGXUnity/Rigid body/Empty", priority = 31 )]
[MenuItem( "GameObject/AGXUnity/Rigid body/Empty", validate = false, priority = 10 )]
public static GameObject CreateRigidBodyEmpty( MenuCommand command )
{
return Selection.activeGameObject = CreateRigidBody( command );
}
#endregion
#region Constraint
private static GameObject CreateConstraint( MenuCommand command, ConstraintType type )
{
var parent = command.context as GameObject;
var go = Factory.Create( type );
if ( go == null )
return null;
if ( parent != null )
go.transform.SetParent( parent.transform, false );
Undo.RegisterCreatedObjectUndo( go, "Constraint" );
return go;
}
[MenuItem( "AGXUnity/Constraints/Hinge", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Hinge", validate = false, priority = 10 )]
public static GameObject ConstraintHinge( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.Hinge );
}
[MenuItem( "AGXUnity/Constraints/Prismatic", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Prismatic", validate = false, priority = 10 )]
public static GameObject ConstraintPrismatic( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.Prismatic );
}
[MenuItem( "AGXUnity/Constraints/Lock Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Lock Joint", validate = false, priority = 10 )]
public static GameObject ConstraintLockJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.LockJoint );
}
[MenuItem( "AGXUnity/Constraints/Cylindrical Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Cylindrical Joint", validate = false, priority = 10 )]
public static GameObject ConstraintCylindricalJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.CylindricalJoint );
}
[MenuItem( "AGXUnity/Constraints/Ball Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Ball Joint", validate = false, priority = 10 )]
public static GameObject ConstraintBallJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.BallJoint );
}
[MenuItem( "AGXUnity/Constraints/Distance Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Distance Joint", validate = false, priority = 10 )]
public static GameObject ConstraintDistanceJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.DistanceJoint );
}
[MenuItem( "AGXUnity/Constraints/Angular Lock Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Angular Lock Joint", validate = false, priority = 10 )]
public static GameObject ConstraintAngularLockJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.AngularLockJoint );
}
[MenuItem( "AGXUnity/Constraints/Plane Joint", priority = 20 )]
[MenuItem( "GameObject/AGXUnity/Constraints/Plane Joint", validate = false, priority = 10 )]
public static GameObject ConstraintPlaneJoint( MenuCommand command )
{
return Selection.activeGameObject = CreateConstraint( command, ConstraintType.PlaneJoint );
}
#endregion
#region Model
private static GameObject CreateModel<T>( MenuCommand command ) where T : ScriptComponent
{
var go = Factory.Create<T>();
if ( go == null )
return null;
var parent = command.context as GameObject;
if ( parent != null )
go.transform.SetParent( parent.transform, false );
Undo.RegisterCreatedObjectUndo( go, $"New {typeof( T ).Name}" );
return go;
}
[MenuItem( "AGXUnity/Model/Wire", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Wire", validate = false, priority = 10 )]
public static GameObject WireEmpty( MenuCommand command )
{
return Selection.activeGameObject = CreateModel<Wire>( command );
}
[MenuItem( "AGXUnity/Model/Cable", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Cable", validate = false, priority = 10 )]
public static GameObject CableEmpty( MenuCommand command )
{
return Selection.activeGameObject = CreateModel<Cable>( command );
}
[MenuItem( "AGXUnity/Model/Track", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Track", validate = false, priority = 10 )]
public static GameObject CreateTrack( MenuCommand command )
{
return Selection.activeGameObject = CreateModel<Track>( command );
}
[MenuItem( "AGXUnity/Model/Deformable Terrain", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Deformable Terrain", validate = false, priority = 10 )]
public static GameObject CreateDeformableTerrain( MenuCommand command )
{
var terrainData = new TerrainData()
{
size = new Vector3( 60 / 8.0f, 45, 60 / 8.0f ),
heightmapResolution = 257
};
terrainData.SetDetailResolution( 1024, terrainData.detailResolutionPerPatch );
var terrainDataName = AssetDatabase.GenerateUniqueAssetPath( "Assets/New Terrain.asset" );
AssetDatabase.CreateAsset( terrainData, terrainDataName );
var go = Terrain.CreateTerrainGameObject( terrainData );
go.name = Factory.CreateName<DeformableTerrain>();
if ( go == null ) {
AssetDatabase.DeleteAsset( terrainDataName );
return null;
}
AGXUnity.Utils.PrefabUtils.PlaceInCurrentStange( go );
go.transform.position = new Vector3( -30, 0, -30 );
go.AddComponent<DeformableTerrain>();
if ( command.context is GameObject ctx )
go.transform.SetParent( ctx.transform, false );
Undo.RegisterCreatedObjectUndo( go, "New Deformable Terrain" );
return Selection.activeGameObject = go;
}
[MenuItem( "AGXUnity/Model/Deformable Terrain Pager", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Deformable Terrain Pager", validate = false, priority = 10 )]
public static GameObject CreateTerrainPager( MenuCommand command )
{
var terrainData = new TerrainData()
{
size = new Vector3( 60 / 8.0f, 45, 60 / 8.0f ),
heightmapResolution = 517
};
terrainData.SetDetailResolution( 1024, terrainData.detailResolutionPerPatch );
var terrainDataName = AssetDatabase.GenerateUniqueAssetPath( "Assets/New Terrain.asset" );
AssetDatabase.CreateAsset( terrainData, terrainDataName );
var go = Terrain.CreateTerrainGameObject( terrainData );
go.name = Factory.CreateName<DeformableTerrainPager>();
if ( go == null ) {
AssetDatabase.DeleteAsset( terrainDataName );
return null;
}
AGXUnity.Utils.PrefabUtils.PlaceInCurrentStange( go );
go.transform.position = new Vector3( -60, 0, -60 );
go.AddComponent<DeformableTerrainPager>();
if ( command.context is GameObject ctx )
go.transform.SetParent( ctx.transform, false );
Undo.RegisterCreatedObjectUndo( go, "New Terrain Pager" );
return Selection.activeGameObject = go;
}
[MenuItem( "AGXUnity/Model/Movable Terrain", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Movable Terrain", validate = false, priority = 10 )]
public static GameObject CreateMovableTerrain( MenuCommand command )
{
var go = new GameObject();
go.name = Factory.CreateName<MovableTerrain>();
AGXUnity.Utils.PrefabUtils.PlaceInCurrentStange( go );
go.AddComponent<MeshFilter>();
var renderer = go.AddComponent<MeshRenderer>();
renderer.sharedMaterial = RenderingUtils.CreateDefaultMaterial();
RenderingUtils.SetMainTexture( renderer.sharedMaterial, AssetDatabase.GetBuiltinExtraResource<Texture2D>( "Default-Checker-Gray.png" ) );
go.AddComponent<MovableTerrain>();
if ( command.context is GameObject ctx )
go.transform.SetParent( ctx.transform, false );
Undo.RegisterCreatedObjectUndo( go, "New Movable Terrain" );
return Selection.activeGameObject = go;
}
[MenuItem( "AGXUnity/Model/Terrain Material Patch", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Model/Terrain Material Patch", validate = false, priority = 10 )]
public static GameObject CreateTerrainMaterialPatch( MenuCommand command )
{
var go = CreateModel<TerrainMaterialPatch>(command);
var box = Factory.Create<Box>();
box.transform.SetParent( go.transform, false );
box.GetComponent<Box>().HalfExtents = new Vector3( 2.5f, 1.0f, 2.5f );
AGXUnity.Rendering.ShapeVisual.Create( box.GetComponent<Box>() );
Undo.RegisterCreatedObjectUndo( go, "New Terrain Material Patch" );
return Selection.activeGameObject = go;
}
#endregion
#region Sensors
[MenuItem( "AGXUnity/Sensor/LiDAR", priority = 50 )]
[MenuItem( "GameObject/AGXUnity/Sensor/LiDAR", validate = false, priority = 10 )]
public static GameObject LiDAR( MenuCommand command )
{
var lidar = CreateModel<LidarSensor>( command );
lidar.transform.localRotation = Quaternion.FromToRotation( Vector3.forward, Vector3.up );
return Selection.activeGameObject = lidar;
}
#endregion
#region Managers
[MenuItem( "AGXUnity/Managers/Debug Render Manager", validate = true )]
private static bool DebugRendererValidate()
{
return ValidateManager<AGXUnity.Rendering.DebugRenderManager>();
}
[MenuItem( "AGXUnity/Managers/Debug Render Manager" )]
public static GameObject DebugRenderer()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<AGXUnity.Rendering.DebugRenderManager>().gameObject;
}
[MenuItem( "AGXUnity/Simulation", validate = true )]
private static bool SimulationValidate()
{
return ValidateManager<Simulation>();
}
[MenuItem( "AGXUnity/Simulation", priority = 66 )]
public static GameObject Simulation()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<Simulation>()?.gameObject;
}
[MenuItem( "AGXUnity/Sensor Environment", validate = true )]
private static bool SensorEnvironmentValidate()
{
return ValidateManager<SensorEnvironment>();
}
[MenuItem( "AGXUnity/Sensor Environment", priority = 66 )]
public static GameObject SensorEnvironment()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<SensorEnvironment>()?.gameObject;
}
[MenuItem( "AGXUnity/Plot", priority = 66 )]
public static GameObject Plot()
{
var PlotObject = new GameObject("PlotObject");
PlotObject.AddComponent<AGXUnity.Utils.Plot>();
PlotObject.AddComponent<AGXUnity.Utils.DataSeries>();
PlotObject.AddComponent<AGXUnity.Utils.DataSeries>();
#if USE_VISUAL_SCRIPTING
var plotAssetPath = AGXUnityEditor.IO.Utils.AGXUnityResourceDirectory + "/Plot/TemplatePlot.Asset";
var targetAssetPath = AssetDatabase.GenerateUniqueAssetPath("Assets/Plot.Asset");
AssetDatabase.CopyAsset( plotAssetPath, targetAssetPath );
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
var sm = PlotObject.AddComponent<Unity.VisualScripting.ScriptMachine>();
sm.nest.SwitchToMacro( AssetDatabase.LoadAssetAtPath<Unity.VisualScripting.ScriptGraphAsset>( targetAssetPath ) );
#endif
return Selection.activeGameObject = PlotObject.gameObject;
}
[MenuItem( "AGXUnity/Managers/Collision Groups Manager", validate = true )]
private static bool CollisionGroupsManagerValidate()
{
return ValidateManager<CollisionGroupsManager>();
}
[MenuItem( "AGXUnity/Managers/Collision Groups Manager", priority = 65 )]
public static GameObject CollisionGroupsManager()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<CollisionGroupsManager>()?.gameObject;
}
[MenuItem( "AGXUnity/Managers/Contact Material Manager", validate = true )]
private static bool ContactMaterialManagerValidate()
{
return ValidateManager<ContactMaterialManager>();
}
[MenuItem( "AGXUnity/Managers/Contact Material Manager", priority = 65 )]
public static GameObject ContactMaterialManager()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<ContactMaterialManager>()?.gameObject;
}
[MenuItem( "AGXUnity/Managers/Wind and Water Manager", validate = true )]
private static bool WindAndWaterManagerValidate()
{
return ValidateManager<WindAndWaterManager>();
}
[MenuItem( "AGXUnity/Managers/Wind and Water Manager", priority = 65 )]
public static GameObject WindAndWaterManager()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<WindAndWaterManager>()?.gameObject;
}
[MenuItem( "AGXUnity/Managers/Script Asset Manager", validate = true )]
private static bool ScriptAssetManagerValidate()
{
return ValidateManager<ScriptAssetManager>();
}
[MenuItem( "AGXUnity/Managers/Script Asset Manager", priority = 65 )]
public static GameObject ScriptAssetManager()
{
return Selection.activeGameObject = GetOrCreateUniqueGameObject<ScriptAssetManager>()?.gameObject;
}
[MenuItem( "AGXUnity/Managers/Pick Handler (Game View)", validate = true )]
private static bool PickHandlerValidate()
{
return ValidateManager<PickHandler>();
}
[MenuItem( "AGXUnity/Managers/Pick Handler (Game View)", priority = 65 )]
public static GameObject PickHandler()
{
var ph = GetOrCreateUniqueGameObject<PickHandler>();
if ( ph == null )
return null;
if ( ph.MainCamera == null ) {
// Check for tagged main camera.
if ( Camera.main != null ) {
ph.MainCamera = Camera.main.gameObject;
}
// Search for any camera containing "Main".
else {
foreach ( var camera in Camera.allCameras ) {
if ( camera.name.Contains( "Main" ) ) {
ph.MainCamera = camera.gameObject;
break;
}
}
}
if ( ph.MainCamera == null )
Debug.LogWarning( "Unable to find Main Camera. You have to manually assign view camera for pick handler to work.", ph );
}
return Selection.activeGameObject = ph.gameObject;
}
#endregion
#region Utils Settings
[MenuItem( "AGXUnity/Utils/Generate Custom Editors", priority = 80 )]
public static void GenerateEditors()
{
Utils.CustomEditorGenerator.Generate();
}
[MenuItem( "AGXUnity/Utils/Convert Rendering Materials", priority = 80 )]
public static void ConvertRenderingMaterials()
{
Windows.ConvertMaterialsWindow.Open();
}
[MenuItem( "AGXUnity/Utils/Convert PhysX components to AGX", priority = 80 )]
public static void ConvertPhysXToAGX()
{
Windows.ConvertPhysXToAGXWindow.Open();
}
[MenuItem( "AGXUnity/Settings...", priority = 81 )]
public static void OpenSettings()
{
SettingsService.OpenProjectSettings( "Project/AGXSettings" );
}
public static T GetOrCreateUniqueGameObject<T>()
where T : ScriptComponent
{
bool hadInstance = UniqueGameObject<T>.HasInstanceInScene;
if ( !hadInstance && AGXUnity.Utils.PrefabUtils.IsEditingPrefab ) {
Debug.LogWarning( $"Invalid to create {typeof( T ).FullName} while editing prefabs." );
return null;
}
T obj = UniqueGameObject<T>.Instance;
if ( !hadInstance && obj != null )
Undo.RegisterCreatedObjectUndo( obj.gameObject, "Created " + obj.name );
return obj;
}
private static bool ValidateManager<T>()
where T : UniqueGameObject<T>
{
return !AGXUnity.Utils.PrefabUtils.IsEditingPrefab;
}
#endregion
#region Documentation, About and Update
[MenuItem( "AGXUnity/AGX Dynamics for Unity Manual", priority = 2001 )]
public static void AGXDynamicsForUnityManual()
{
Application.OpenURL( AGXDynamicsForUnityManualURL );
}
[MenuItem( "AGXUnity/AGX Dynamics for Unity Examples", priority = 2002 )]
public static void AGXDynamicsForUnityExamples()
{
Application.OpenURL( AGXDynamicsForUnityExamplesURL );
}
[MenuItem( "AGXUnity/AGX Dynamics Manual", priority = 2020 )]
public static void AGXManual()
{
Application.OpenURL( AGXUserManualURL );
}
[MenuItem( "AGXUnity/AGX Dynamics API Reference", priority = 2021 )]
public static void AGXAPI()
{
Application.OpenURL( AGXAPIReferenceURL );
}
[MenuItem( "AGXUnity/About AGX Dynamics for Unity", priority = 2040 )]
public static void AboutWindow()
{
Windows.AboutWindow.Open();
}
[MenuItem( "AGXUnity/License/License Manager", priority = 2041 )]
public static void LicenseManagerWindow()
{
Windows.LicenseManagerWindow.Open();
}
[MenuItem( "AGXUnity/License/Runtime Activation Generator", priority = 2042 )]
public static void RuntimeGeneratorWindow()
{
Windows.GenerateRuntimeLicenseActivationWindow.Open();
}
[MenuItem( "AGXUnity/Check for Updates...", priority = 2060, validate = true )]
public static bool CheckForUpdatesWindowValidater()
{
return PackageManifest.Instance.GetAGXUnityVersionInfo().IsValid;
}
[MenuItem( "AGXUnity/Check for Updates...", priority = 2060 )]
public static void CheckForUpdatesWindow()
{
Windows.CheckForUpdatesWindow.Open();
}
#endregion
}
}