Beispiel #1
0
    public static void AddTrigger(IntPtr other, IntPtr otherShape, IntPtr self, bool isEnter, bool isExit)
    {
        PhysXTrigger trigger = PhysXTrigger.GetTrigger();

        trigger.FromPhysXInternalTrigger(other, otherShape, self, isEnter, isExit);
        ongoingTriggers.Add(trigger);
    }
Beispiel #2
0
 public void FireTriggerEvents(PhysXTrigger trigger)
 {
     if (trigger.isEnter)
     {
         foreach (ITriggerEnterEvent triggerEnterEvent in triggerEnterEvents)
         {
             if (triggerEnterEvent.requiresData)
             {
                 triggerEnterEvent.TriggerEnter(trigger.collider);
             }
             else
             {
                 triggerEnterEvent.TriggerEnter();
             }
         }
     }
     if (trigger.isExit)
     {
         foreach (ITriggerExitEvent triggerExitEvent in triggerExitEvents)
         {
             if (triggerExitEvent.requiresData)
             {
                 triggerExitEvent.TriggerExit(trigger.collider);
             }
             else
             {
                 triggerExitEvent.TriggerExit();
             }
         }
     }
 }
Beispiel #3
0
    public void Simulate()
    {
        if (doPhysics)
        {
            PhysXLib.StepPhysics(scene, Time.fixedDeltaTime, scratchMem, scratchKilobytes * 1024);

            foreach (PhysXBody body in bodies.Values)
            {
                body.UpdatePositionAndVelocity();
            }

            collisionCallbackMarker.Begin();
            foreach (PhysXCollision collision in PhysXSceneManager.ongoingCollisions)
            {
                collision.PopulateWithUnityObjects(bodies);
                PhysXBody body = null;
                if (bodies.TryGetValue(collision.self.ToInt64(), out body))
                {
                    try {
                        body.FireCollisionEvents(collision);
                    }
                    catch (Exception e) {
                        Debug.LogError("Exception: " + e.Message + "\n" + e.StackTrace);
                    }
                }
                PhysXCollision.ReleaseCollision(collision);
            }
            PhysXSceneManager.ongoingCollisions.Clear();

            foreach (PhysXTrigger trigger in PhysXSceneManager.ongoingTriggers)
            {
                trigger.PopulateWithUnityObjects(bodies);
                PhysXBody body = null;
                if (bodies.TryGetValue(trigger.self.ToInt64(), out body))
                {
                    try {
                        body.FireTriggerEvents(trigger);
                    }
                    catch (Exception e) {
                        Debug.LogError("Exception: " + e.Message + "\n" + e.StackTrace);
                    }
                }
                PhysXTrigger.ReleaseTrigger(trigger);
            }
            PhysXSceneManager.ongoingTriggers.Clear();
            collisionCallbackMarker.End();

            PhysXLib.StepGhostPhysics(scene, Time.fixedDeltaTime, scratchMem, scratchKilobytes * 1024);
        }
    }