Skip to content

Commit 93aa0a2

Browse files
committed
Refine "ConveyorBelt".
1 parent 3b7fbd3 commit 93aa0a2

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

LowLevel/Sandbox/Assets/Scenes/Shapes/ConveyorBelt/ConveyorBelt.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,16 @@ private void OnEnable()
3232
// Set up the scene reset action.
3333
m_SandboxManager.SceneResetAction = SetupScene;
3434

35-
// Set Overrides.
36-
m_SandboxManager.SetOverrideColorShapeState(false);
37-
3835
m_PhysicsWorld = PhysicsWorld.defaultWorld;
3936

40-
m_ConveyorSpeed = 20f;
37+
m_ConveyorSpeed = 3f;
4138
m_ConveyorAngle = 0f;
4239

4340
SetupOptions();
4441

4542
SetupScene();
4643
}
4744

48-
private void OnDisable()
49-
{
50-
// Reset overrides.
51-
m_SandboxManager.ResetOverrideColorShapeState();
52-
}
53-
5445
private void SetupOptions()
5546
{
5647
var root = m_UIDocument.rootVisualElement;
@@ -133,11 +124,23 @@ private void Spawn(int spawnCount)
133124
for (var n = 0; n < spawnCount; ++n)
134125
{
135126
var spawnPosition = new Vector2(random.NextFloat(-5f, 5f), random.NextFloat(9f, 20f));
136-
var scale = random.NextFloat(0.05f, 1f);
137-
var radius = random.NextFloat(0f, 0.2f);
138-
139-
var body = m_PhysicsWorld.CreateBody(new PhysicsBodyDefinition { bodyType = RigidbodyType2D.Dynamic, position = spawnPosition });
140-
body.CreateShape(PolygonGeometry.CreateBox(Vector2.one * scale, radius));
127+
var body = m_PhysicsWorld.CreateBody(new PhysicsBodyDefinition { bodyType = RigidbodyType2D.Dynamic, position = spawnPosition, rotation = new PhysicsRotate(random.NextFloat(-PhysicsMath.PI, PhysicsMath.PI)) });
128+
129+
var shapeDef = new PhysicsShapeDefinition { surfaceMaterial = new PhysicsShape.SurfaceMaterial { customColor = m_SandboxManager.ShapeColorState } };
130+
131+
if (random.NextBool())
132+
{
133+
var scaleX = random.NextFloat(0.05f, 1.0f);
134+
var scaleY = random.NextFloat(0.05f, 1.0f);
135+
var radius = random.NextFloat(0f, 0.2f);
136+
body.CreateShape(PolygonGeometry.CreateBox(new Vector2(scaleX, scaleY), radius), shapeDef);
137+
}
138+
else
139+
{
140+
var scale = random.NextFloat(0.2f, 0.6f);
141+
var radius = random.NextFloat(0.2f, 0.4f);
142+
body.CreateShape(new CapsuleGeometry { center1 = Vector2.left * scale, center2 = Vector2.right * scale, radius = radius }, shapeDef);
143+
}
141144
}
142145
}
143146

0 commit comments

Comments
 (0)