private void Collision(Collision2D collision) { if (cooldown <= 0.0f && prefab != null) { if (D2dHelper.IndexInMask(collision.gameObject.layer, mask) == true) { var contacts = collision.contacts; for (var i = contacts.Length - 1; i >= 0; i--) { var contact = contacts[i]; var normal = collision.relativeVelocity; var force = normal.magnitude; if (force >= threshold) { switch (rotateTo) { case RotationType.RandomDirection: { var angle = Random.Range(-Mathf.PI, Mathf.PI); normal.x = Mathf.Sin(angle); normal.y = Mathf.Cos(angle); } break; case RotationType.ImpactDirection: { normal /= force; } break; case RotationType.SurfaceNormal: { normal = contact.normal; } break; } var point = contact.point - contact.normal * offset; cooldown = delay; Instantiate(prefab, point, Quaternion.identity); if (onImpact != null) { onImpact.Invoke(); } if (delay > 0.0f) { break; } } } } } }
private void Collision(Collision2D collision) { if (cooldown <= 0.0f) { if (D2dHelper.IndexInMask(collision.gameObject.layer, mask) == true) { var contacts = collision.contacts; for (var i = contacts.Length - 1; i >= 0; i--) { var normal = collision.relativeVelocity; var force = normal.magnitude; if (force >= threshold) { cooldown = delay; cachedDamage.Damage += force * scale; if (onImpact != null) { onImpact.Invoke(); } if (delay > 0.0f) { break; } } } } } }
private void Collision(Collision2D collision) { if (cooldown <= 0.0f) { if (D2dHelper.IndexInMask(collision.gameObject.layer, mask) == true) { var contacts = collision.contacts; for (var i = contacts.Length - 1; i >= 0; i--) { var contact = contacts[i]; var normal = collision.relativeVelocity; var force = normal.magnitude; if (force >= threshold) { if (useSurfaceNormal == true) { normal = contact.normal; } else { normal /= force; } var point = contact.point; var pointA = point - normal * offset; var pointB = point + normal * depth; var matrix = D2dSlice.CalculateMatrix(pointA, pointB, thickness); cooldown = delay; cachedDestructible.Paint(paint, matrix, shape, color); if (prefab != null) { Instantiate(prefab, point, Quaternion.identity); } if (onImpact != null) { onImpact.Invoke(); } if (delay > 0.0f) { break; } } } } } }
public static void All(D2dDestructible.PaintType paint, Matrix4x4 matrix, Texture2D shape, Color color, int layerMask = -1) { var destructible = D2dDestructible.FirstInstance; for (var i = D2dDestructible.InstanceCount - 1; i >= 0; i--) { if (D2dHelper.IndexInMask(destructible.gameObject.layer, layerMask) == true) { destructible.Paint(paint, matrix, shape, color); } destructible = destructible.NextInstance; } }
private void Overlap(Collider2D collider) { if (D2dHelper.IndexInMask(collider.gameObject.layer, mask) == true) { cachedDamage.Damage += damagePerSecond * Time.deltaTime; if (cooldown <= 0.0f) { cooldown = delay; if (onOverlap != null) { onOverlap.Invoke(); } } } }