Created
April 9, 2019 10:57
-
-
Save tsubaki/29e9d66a2cb5df231180ede9edf455ad to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
using Unity.Physics; | |
using Unity.Mathematics; | |
using Unity.Transforms; | |
using Unity.Entities; | |
using Unity.Physics.Systems; | |
[AlwaysUpdateSystem] | |
public class HitTestSystem : ComponentSystem | |
{ | |
BuildPhysicsWorld m_BuildPhysicsWorldSystem; | |
StepPhysicsWorld m_StepPhysicsWorldSystem; | |
protected override void OnCreateManager() | |
{ | |
m_BuildPhysicsWorldSystem = World.GetOrCreateManager<BuildPhysicsWorld>(); | |
m_StepPhysicsWorldSystem = World.GetOrCreateManager<StepPhysicsWorld>(); | |
} | |
protected override void OnUpdate() | |
{ | |
foreach(var contactEvent in m_StepPhysicsWorldSystem.Simulation.CollisionEvents) | |
{ | |
var physicsWorld = m_BuildPhysicsWorldSystem.PhysicsWorld; | |
var bodyA = physicsWorld.Bodies[contactEvent.BodyIndices.BodyAIndex]; | |
var bodyB = physicsWorld.Bodies[contactEvent.BodyIndices.BodyBIndex]; | |
PostUpdateCommands.DestroyEntity(bodyA.Entity); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment