Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Assets/PredictionTests/Scripts/Scenarios/BounceProbe.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ protected override void OnDestroy()
/// </summary>
private const float MinCountedImpactSpeed = 1f;

private void OnBounce(GameObject other, PhysicsCollision collision)
private void OnBounce(GameObject other, PredictedComponentID otherId, PhysicsCollision collision)
{
if (!predictionManager.isVerifiedView)
return;
Expand Down
14 changes: 4 additions & 10 deletions Assets/PredictionTests/Scripts/Scenarios/SmokeZoneTracker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,18 @@ private void OnDisable()
instances.Remove(this);
}

private void OnPredictedTriggerEnter(GameObject other)
private void OnPredictedTriggerEnter(GameObject other, PredictedComponentID otherId)
{
if (!PredictionManager.TryGetClosestPredictedID(other, out var pid))
return;

enterFires++;
var id = pid.objectId;
var id = otherId.objectId;
if (!currentState.insideIds.Contains(id))
currentState.insideIds.Add(id);
}

private void OnPredictedTriggerExit(GameObject other)
private void OnPredictedTriggerExit(GameObject other, PredictedComponentID otherId)
{
if (!PredictionManager.TryGetClosestPredictedID(other, out var pid))
return;

exitFires++;
var id = pid.objectId;
var id = otherId.objectId;
if (currentState.insideIds.Contains(id))
currentState.insideIds.Remove(id);
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/PurrDiction/Examples/ProjectileShooter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private void Shoot()

projectile.AddImpulse(transform.forward * _initialForce);
if(projectile.isTrigger)
projectile.onTriggerEnter += (other) => OnProjectileTriggerEnter(projectile, other);
projectile.onTriggerEnter += (other, _) => OnProjectileTriggerEnter(projectile, other);
}

private void OnProjectileTriggerEnter(PredictedProjectile3D projectile, GameObject other)
Expand Down
15 changes: 8 additions & 7 deletions Assets/PurrDiction/Runtime/PhysicsEvents/Predicted2DPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -121,20 +121,21 @@ private static void TriggerEvent(PredictionManager predictionManager, Physics2DE
if (ev.me.TryGetIdentity<PredictedRigidbody2D>(predictionManager, out var me))
{
var otherGo = ev.other.GetGameObject(predictionManager);
if (!otherGo && ev.other.objectId.instanceId.value != 0)
if (!otherGo && ev.type != PhysicsEventType.Exit &&
ev.other.objectId.instanceId.value != 0)
return;
if (ev.isTrigger)
{
switch (ev.type)
{
case PhysicsEventType.Enter:
me.RaiseTriggerEnter(otherGo);
me.RaiseTriggerEnter(otherGo, ev.other);
break;
case PhysicsEventType.Exit:
me.RaiseTriggerExit(otherGo);
me.RaiseTriggerExit(otherGo, ev.other);
break;
case PhysicsEventType.Stay:
me.RaiseTriggerStay(otherGo);
me.RaiseTriggerStay(otherGo, ev.other);
break;
default: throw new ArgumentOutOfRangeException();
}
Expand All @@ -144,13 +145,13 @@ private static void TriggerEvent(PredictionManager predictionManager, Physics2DE
switch (ev.type)
{
case PhysicsEventType.Enter:
me.RaiseCollisionEnter(otherGo, ev.contacts);
me.RaiseCollisionEnter(otherGo, ev.other, ev.contacts);
break;
case PhysicsEventType.Exit:
me.RaiseCollisionExit(otherGo, ev.contacts);
me.RaiseCollisionExit(otherGo, ev.other, ev.contacts);
break;
case PhysicsEventType.Stay:
me.RaiseCollisionStay(otherGo, ev.contacts);
me.RaiseCollisionStay(otherGo, ev.other, ev.contacts);
break;
default: throw new ArgumentOutOfRangeException();
}
Expand Down
15 changes: 8 additions & 7 deletions Assets/PurrDiction/Runtime/PhysicsEvents/Predicted3DPhysics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,21 @@ private static void TriggerEvent(PredictionManager predictionManager, PhysicsEve
if (ev.me.TryGetIdentity<IPredictedPhysicsCallbacks>(predictionManager, out var me))
{
var otherGo = ev.other.GetGameObject(predictionManager);
if (!otherGo && ev.other.objectId.instanceId.value != 0)
if (!otherGo && ev.type != PhysicsEventType.Exit &&
ev.other.objectId.instanceId.value != 0)
return;
if (ev.isTrigger)
{
switch (ev.type)
{
case PhysicsEventType.Enter:
me.RaiseTriggerEnter(otherGo);
me.RaiseTriggerEnter(otherGo, ev.other);
break;
case PhysicsEventType.Exit:
me.RaiseTriggerExit(otherGo);
me.RaiseTriggerExit(otherGo, ev.other);
break;
case PhysicsEventType.Stay:
me.RaiseTriggerStay(otherGo);
me.RaiseTriggerStay(otherGo, ev.other);
break;
default: throw new ArgumentOutOfRangeException();
}
Expand All @@ -82,13 +83,13 @@ private static void TriggerEvent(PredictionManager predictionManager, PhysicsEve
switch (ev.type)
{
case PhysicsEventType.Enter:
me.RaiseCollisionEnter(otherGo, ev.collision);
me.RaiseCollisionEnter(otherGo, ev.other, ev.collision);
break;
case PhysicsEventType.Exit:
me.RaiseCollisionExit(otherGo, ev.collision);
me.RaiseCollisionExit(otherGo, ev.other, ev.collision);
break;
case PhysicsEventType.Stay:
me.RaiseCollisionStay(otherGo, ev.collision);
me.RaiseCollisionStay(otherGo, ev.other, ev.collision);
break;
default: throw new ArgumentOutOfRangeException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ namespace PurrNet.Prediction
{
public interface IPredictedPhysicsCallbacks
{
public void RaiseTriggerEnter(GameObject other);
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId);

public void RaiseTriggerExit(GameObject other);
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId);

public void RaiseTriggerStay(GameObject other);
public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId);

public void RaiseCollisionEnter(GameObject other, PhysicsCollision evContacts);
public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts);

public void RaiseCollisionExit(GameObject other, PhysicsCollision evContacts);
public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts);

public void RaiseCollisionStay(GameObject other, PhysicsCollision evContacts);
public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,26 @@ public class PredictedPhysicsCallbacks : StatelessPredictedIdentity, IPredictedP

public event OnControllerColliderHitDelegate onControllerColliderHit;

public void RaiseTriggerEnter(GameObject other) => onTriggerEnter?.Invoke(other);
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId)
=> onTriggerEnter?.Invoke(other, otherId);

public void RaiseTriggerExit(GameObject other) => onTriggerExit?.Invoke(other);
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId)
=> onTriggerExit?.Invoke(other, otherId);

public void RaiseTriggerStay(GameObject other) => onTriggerStay?.Invoke(other);
public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId)
=> onTriggerStay?.Invoke(other, otherId);

public void RaiseCollisionEnter(GameObject other, PhysicsCollision evContacts) => onCollisionEnter?.Invoke(other, evContacts);
public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionEnter?.Invoke(other, otherId, evContacts);

public void RaiseCollisionExit(GameObject other, PhysicsCollision evContacts) => onCollisionExit?.Invoke(other, evContacts);
public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionExit?.Invoke(other, otherId, evContacts);

public void RaiseCollisionStay(GameObject other, PhysicsCollision evContacts) => onCollisionStay?.Invoke(other, evContacts);
public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionStay?.Invoke(other, otherId, evContacts);

public void RaiseControllerColliderHit(GameObject other, PhysicsControllerHit hit)
=> onControllerColliderHit?.Invoke(other, hit);
Expand Down
25 changes: 19 additions & 6 deletions Assets/PurrDiction/Runtime/UnityPhysics/PredictedProjectile3D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,26 @@ public void AddImpulse(Vector3 impulse)
currentState.velocity += impulse;
}

public void RaiseTriggerEnter(GameObject other) => onTriggerEnter?.Invoke(other);
public void RaiseTriggerExit(GameObject other) => onTriggerExit?.Invoke(other);
public void RaiseTriggerStay(GameObject other) => onTriggerStay?.Invoke(other);
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId)
=> onTriggerEnter?.Invoke(other, otherId);

public void RaiseCollisionEnter(GameObject other, PhysicsCollision evContacts) => onCollisionEnter?.Invoke(other, evContacts);
public void RaiseCollisionExit(GameObject other, PhysicsCollision evContacts) => onCollisionExit?.Invoke(other, evContacts);
public void RaiseCollisionStay(GameObject other, PhysicsCollision evContacts) => onCollisionStay?.Invoke(other, evContacts);
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId)
=> onTriggerExit?.Invoke(other, otherId);

public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId)
=> onTriggerStay?.Invoke(other, otherId);

public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionEnter?.Invoke(other, otherId, evContacts);

public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionExit?.Invoke(other, otherId, evContacts);

public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
=> onCollisionStay?.Invoke(other, otherId, evContacts);

protected override ProjectileState3D Interpolate(ProjectileState3D from, ProjectileState3D to, float t)
{
Expand Down
47 changes: 27 additions & 20 deletions Assets/PurrDiction/Runtime/UnityPhysics/PredictedRigidbody.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ public enum FloatAccuracy
Low = 2
}

public delegate void OnCollisionDelegate(GameObject other, PhysicsCollision physicsEvent);
public delegate void OnTriggerDelegate(GameObject other);
public delegate void OnCollisionDelegate(GameObject other, PredictedComponentID otherId,
PhysicsCollision physicsEvent);
public delegate void OnTriggerDelegate(GameObject other, PredictedComponentID otherId);
public delegate void OnControllerColliderHitDelegate(GameObject other, PhysicsControllerHit physicsEvent);

#if UNITY_PHYSICS_3D
Expand Down Expand Up @@ -746,62 +747,68 @@ public void Move(Vector3 position, Quaternion rotation)
}


public void RaiseTriggerEnter(GameObject other)
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId)
{
onTriggerEnter?.Invoke(other);
onTriggerEnter?.Invoke(other, otherId);
}

public void RaiseTriggerExit(GameObject other)
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId)
{
onTriggerExit?.Invoke(other);
onTriggerExit?.Invoke(other, otherId);
}

public void RaiseTriggerStay(GameObject other)
public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId)
{
onTriggerStay?.Invoke(other);
onTriggerStay?.Invoke(other, otherId);
}

public void RaiseCollisionEnter(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
onCollisionEnter?.Invoke(other, evContacts);
onCollisionEnter?.Invoke(other, otherId, evContacts);
}

public void RaiseCollisionExit(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
onCollisionExit?.Invoke(other, evContacts);
onCollisionExit?.Invoke(other, otherId, evContacts);
}

public void RaiseCollisionStay(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
onCollisionStay?.Invoke(other, evContacts);
onCollisionStay?.Invoke(other, otherId, evContacts);
}
#else
public void RaiseTriggerEnter(GameObject other)
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId)
{
throw new NotImplementedException();
}

public void RaiseTriggerExit(GameObject other)
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId)
{
throw new NotImplementedException();
}

public void RaiseTriggerStay(GameObject other)
public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId)
{
throw new NotImplementedException();
}

public void RaiseCollisionEnter(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
throw new NotImplementedException();
}

public void RaiseCollisionExit(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
throw new NotImplementedException();
}

public void RaiseCollisionStay(GameObject other, PhysicsCollision evContacts)
public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
PhysicsCollision evContacts)
{
throw new NotImplementedException();
}
Expand Down
29 changes: 18 additions & 11 deletions Assets/PurrDiction/Runtime/UnityPhysics/PredictedRigidbody2D.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ public class PredictedRigidbody2D : PredictedIdentity<UnityRigidbody2DState>
[SerializeField, Min(0f)] private float _softVelocityCorrectionRate = 8f;

#if UNITY_PHYSICS_2D
public delegate void OnCollisionDelegate(GameObject other, DisposableList<Physics2DContactPoint> evContacts);
public delegate void OnTriggerDelegate(GameObject other);
public delegate void OnCollisionDelegate(GameObject other, PredictedComponentID otherId,
DisposableList<Physics2DContactPoint> evContacts);
public delegate void OnTriggerDelegate(GameObject other, PredictedComponentID otherId);

[SerializeField] private Rigidbody2D _rigidbody;
[SerializeField] private PhysicsEventMask _eventMask = (PhysicsEventMask)0x3F;
Expand Down Expand Up @@ -503,25 +504,31 @@ private void OnTriggerStay2D(Collider2D other)
predictionManager.physics2d.RegisterEvent(PhysicsEventType.Stay, this, other);
}

public void RaiseTriggerEnter(GameObject other) => onTriggerEnter?.Invoke(other);
public void RaiseTriggerEnter(GameObject other, PredictedComponentID otherId)
=> onTriggerEnter?.Invoke(other, otherId);

public void RaiseTriggerExit(GameObject other) => onTriggerExit?.Invoke(other);
public void RaiseTriggerExit(GameObject other, PredictedComponentID otherId)
=> onTriggerExit?.Invoke(other, otherId);

public void RaiseTriggerStay(GameObject other) => onTriggerStay?.Invoke(other);
public void RaiseTriggerStay(GameObject other, PredictedComponentID otherId)
=> onTriggerStay?.Invoke(other, otherId);

public void RaiseCollisionEnter(GameObject other, DisposableList<Physics2DContactPoint> evContacts)
public void RaiseCollisionEnter(GameObject other, PredictedComponentID otherId,
DisposableList<Physics2DContactPoint> evContacts)
{
onCollisionEnter?.Invoke(other, evContacts);
onCollisionEnter?.Invoke(other, otherId, evContacts);
}

public void RaiseCollisionExit(GameObject other, DisposableList<Physics2DContactPoint> evContacts)
public void RaiseCollisionExit(GameObject other, PredictedComponentID otherId,
DisposableList<Physics2DContactPoint> evContacts)
{
onCollisionExit?.Invoke(other, evContacts);
onCollisionExit?.Invoke(other, otherId, evContacts);
}

public void RaiseCollisionStay(GameObject other, DisposableList<Physics2DContactPoint> evContacts)
public void RaiseCollisionStay(GameObject other, PredictedComponentID otherId,
DisposableList<Physics2DContactPoint> evContacts)
{
onCollisionStay?.Invoke(other, evContacts);
onCollisionStay?.Invoke(other, otherId, evContacts);
}

public Vector2 position
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ public void UnregisteringLiveIdentityClearsRegistration()
}
finally
{
Object.DestroyImmediate(identityObject);
if (identityObject)
Object.DestroyImmediate(identityObject);
Object.DestroyImmediate(managerObject);
}
}
Expand Down Expand Up @@ -116,5 +117,6 @@ private static void SetField(
Assert.That(field, Is.Not.Null, $"missing field {name}");
field.SetValue(manager, value);
}

}
}
Loading