forked from stride3d/stride
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCollisionComponent.cs
More file actions
60 lines (49 loc) · 2.33 KB
/
CollisionComponent.cs
File metadata and controls
60 lines (49 loc) · 2.33 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
// Copyright (c) .NET Foundation and Contributors (https://dotnetfoundation.org/ & https://stride3d.net)
// Distributed under the MIT license. See the LICENSE.md file in the project root for more information.
using Stride.BepuPhysics;
using Stride.BepuPhysics.Definitions.Contacts;
using Stride.Engine;
namespace BepuSample.Game.Components.Utils
{
//[DataContract("SpawnerComponent", Inherited = true)]
[ComponentCategory("BepuDemo - Utils")]
public class CollisionComponent : SyncScript
{
private MyCustomContactEventHandler MyCustomContactEventHandler1 = new();
private MyCustomContactEventHandler MyCustomContactEventHandler2 = new();
private MyCustomContactEventHandler MyCustomContactEventHandler3 = new();
private MyCustomContactEventHandler MyCustomContactEventHandler4 = new();
public BodyComponent? Collidable1 { get; set; }
public BodyComponent? Collidable2 { get; set; }
public BodyComponent? Collidable3 { get; set; }
public BodyComponent? Collidable4 { get; set; }
public override void Start()
{
if (Collidable1 != null)
Collidable1.ContactEventHandler = MyCustomContactEventHandler1;
if (Collidable2 != null)
Collidable2.ContactEventHandler = MyCustomContactEventHandler2;
if (Collidable3 != null)
Collidable3.ContactEventHandler = MyCustomContactEventHandler3;
if (Collidable4 != null)
Collidable4.ContactEventHandler = MyCustomContactEventHandler4;
}
public override void Update()
{
DebugText.Print($"1 : {MyCustomContactEventHandler1.Contact} | 2 : {MyCustomContactEventHandler2.Contact} | 3 : {MyCustomContactEventHandler3.Contact} | 4 : {MyCustomContactEventHandler4.Contact}", new(Game.Window.PreferredWindowedSize.X - 500, 800));
}
}
public class MyCustomContactEventHandler : IContactHandler
{
public bool Contact { get; private set; } = false;
public bool NoContactResponse => false;
void IContactHandler.OnStartedTouching<TManifold>(Contacts<TManifold> contacts)
{
Contact = true;
}
void IContactHandler.OnStoppedTouching<TManifold>(Contacts<TManifold> contacts)
{
Contact = false;
}
}
}