| | | 1 | | //======================================================================= |
| | | 2 | | // LSCompoundCollider2D.cs |
| | | 3 | | //======================================================================= |
| | | 4 | | // MIT License, Copyright (c) 2026-present David Oravsky (mrdav30) |
| | | 5 | | // See LICENSE file in the project root for full license information. |
| | | 6 | | //======================================================================= |
| | | 7 | | |
| | | 8 | | using System; |
| | | 9 | | using System.Runtime.CompilerServices; |
| | | 10 | | using FixedMathSharp; |
| | | 11 | | using FixedMathSharp.Geometry; |
| | | 12 | | using Gravitas.CollisionHandling; |
| | | 13 | | using Gravitas.Materials; |
| | | 14 | | |
| | | 15 | | namespace Gravitas.Colliders; |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Represents one pure 2D collider identity whose collision shape is composed |
| | | 19 | | /// from deterministic internal primitive and convex-polygon parts. |
| | | 20 | | /// </summary> |
| | | 21 | | public sealed class LSCompoundCollider2D : LSCollider2D |
| | | 22 | | { |
| | | 23 | | private readonly CompoundColliderPart2D[] _parts; |
| | | 24 | | private readonly LSCollider2D[] _partColliders; |
| | | 25 | | private readonly ExactMassPoint2D[] _massPointScratch; |
| | | 26 | | private readonly ExactMassWeight[] _massWeightScratch; |
| | 288 | 27 | | private readonly ContactManifold2D _partManifoldScratch = new(); |
| | | 28 | | private bool _hasMassPropertyCenter; |
| | | 29 | | private Vector2d _massPropertyOwnerScale; |
| | | 30 | | private Vector2d _massPropertyOffset; |
| | | 31 | | private bool _massPropertyCommitted; |
| | | 32 | | private Vector2d _massPropertyCenter; |
| | | 33 | | private bool _hasMomentGeometry; |
| | | 34 | | private Vector2d _momentReferencePoint; |
| | | 35 | | private Signed576 _momentGeometry; |
| | | 36 | | private Signed704 _momentDenominator; |
| | | 37 | | |
| | | 38 | | /// <summary>Creates a runtime compound collider from authored pure 2D parts.</summary> |
| | 288 | 39 | | public LSCompoundCollider2D(params CompoundColliderPart2D[] parts) |
| | | 40 | | { |
| | 288 | 41 | | ChronicleGuard.ThrowIfNull(parts, nameof(parts)); |
| | 288 | 42 | | ChronicleGuard.ThrowIfArgument(parts.Length == 0, nameof(parts), "2D compound collider must contain at least one |
| | | 43 | | |
| | 1526 | 44 | | for (int i = 0; i < parts.Length; i++) |
| | 477 | 45 | | ValidatePart(parts[i]); |
| | | 46 | | |
| | 286 | 47 | | _parts = new CompoundColliderPart2D[parts.Length]; |
| | 286 | 48 | | _partColliders = new LSCollider2D[parts.Length]; |
| | 286 | 49 | | _massPointScratch = new ExactMassPoint2D[parts.Length]; |
| | 286 | 50 | | _massWeightScratch = new ExactMassWeight[parts.Length]; |
| | 1524 | 51 | | for (int i = 0; i < parts.Length; i++) |
| | | 52 | | { |
| | 476 | 53 | | _parts[i] = parts[i]; |
| | 476 | 54 | | _partColliders[i] = MaterializePartCollider(parts[i]); |
| | 476 | 55 | | _partColliders[i].ReserveCompoundPart(this, parts[i].LocalRotation, parts[i].LocalScale); |
| | | 56 | | } |
| | 286 | 57 | | } |
| | | 58 | | |
| | | 59 | | /// <inheritdoc/> |
| | 1254 | 60 | | public override ColliderType2D Shape => ColliderType2D.Compound; |
| | | 61 | | |
| | | 62 | | /// <inheritdoc/> |
| | 79 | 63 | | public override int Priority => ColliderSettings2D.GetPriority(Shape); |
| | | 64 | | |
| | | 65 | | /// <summary> |
| | | 66 | | /// Gets the radius of a circle that conservatively contains the current |
| | | 67 | | /// aggregate shape. |
| | | 68 | | /// </summary> |
| | | 69 | | public Fixed64 ScaledRadius |
| | | 70 | | { |
| | | 71 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 72 | | get |
| | | 73 | | { |
| | 26 | 74 | | return HasCommittedShape |
| | 26 | 75 | | ? CanonicalCenteredProxyRadius |
| | 26 | 76 | | : ColliderCanonicalBounds2D.GetCurrentCompoundCenteredProxyRadius(this); |
| | | 77 | | } |
| | | 78 | | } |
| | | 79 | | |
| | | 80 | | /// <summary>Gets the authored parts in stable source order.</summary> |
| | 55 | 81 | | public ReadOnlySpan<CompoundColliderPart2D> Parts => _parts; |
| | | 82 | | |
| | | 83 | | /// <summary>Gets the number of authored compound parts.</summary> |
| | | 84 | | public int PartCount |
| | | 85 | | { |
| | | 86 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | 11304 | 87 | | get => _parts.Length; |
| | | 88 | | } |
| | | 89 | | |
| | | 90 | | /// <summary>Gets the stable runtime part identifier for a source-order index.</summary> |
| | | 91 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 92 | | public int GetPartId(int index) |
| | | 93 | | { |
| | 2 | 94 | | ChronicleGuard.ThrowIfArrayIndexInvalid(index, _parts.Length, nameof(index)); |
| | 2 | 95 | | return index; |
| | | 96 | | } |
| | | 97 | | |
| | | 98 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 99 | | internal LSCollider2D GetPartCollider(int index) |
| | | 100 | | { |
| | 7312 | 101 | | ChronicleGuard.ThrowIfArrayIndexInvalid(index, _parts.Length, nameof(index)); |
| | 7312 | 102 | | return _partColliders[index]; |
| | | 103 | | } |
| | | 104 | | |
| | 132 | 105 | | internal ContactManifold2D PartManifoldScratch => _partManifoldScratch; |
| | | 106 | | |
| | | 107 | | /// <inheritdoc/> |
| | | 108 | | public override bool ContainsPoint(Vector2d point) |
| | | 109 | | { |
| | 1268 | 110 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 111 | | { |
| | 424 | 112 | | if (_partColliders[i].ContainsPoint(point)) |
| | 3 | 113 | | return true; |
| | | 114 | | } |
| | | 115 | | |
| | 210 | 116 | | return false; |
| | | 117 | | } |
| | | 118 | | |
| | | 119 | | /// <inheritdoc/> |
| | | 120 | | public override Vector2d GetClosestPoint(Vector2d point) |
| | | 121 | | { |
| | 5 | 122 | | _ = TryGetClosestBoundaryAnchor( |
| | 5 | 123 | | point, |
| | 5 | 124 | | out FixedPointAnchor2d anchor); |
| | 5 | 125 | | if (anchor.TryGetPoint(out Vector2d closest)) |
| | | 126 | | { |
| | 4 | 127 | | return closest; |
| | | 128 | | } |
| | | 129 | | |
| | 1 | 130 | | throw new InvalidOperationException( |
| | 1 | 131 | | "The closest compound surface point is outside the Fixed64 coordinate domain."); |
| | | 132 | | } |
| | | 133 | | |
| | | 134 | | /// <inheritdoc/> |
| | | 135 | | public override Vector2d GetSupportPoint(Vector2d direction) |
| | | 136 | | { |
| | 4 | 137 | | Vector2d bestPoint = _partColliders[0].GetSupportPoint(direction); |
| | 4 | 138 | | Fixed64 bestProjection = Vector2d.Dot(bestPoint, direction); |
| | 12 | 139 | | for (int i = 1; i < _partColliders.Length; i++) |
| | | 140 | | { |
| | 2 | 141 | | Vector2d candidate = _partColliders[i].GetSupportPoint(direction); |
| | 2 | 142 | | Fixed64 projection = Vector2d.Dot(candidate, direction); |
| | 2 | 143 | | if (projection <= bestProjection) |
| | | 144 | | continue; |
| | | 145 | | |
| | 1 | 146 | | bestProjection = projection; |
| | 1 | 147 | | bestPoint = candidate; |
| | | 148 | | } |
| | | 149 | | |
| | 4 | 150 | | return bestPoint; |
| | | 151 | | } |
| | | 152 | | |
| | | 153 | | internal override ExactMassPoint2D CalculateLocalMassPoint() |
| | | 154 | | { |
| | 1360 | 155 | | GetCurrentScaleFactors(out Vector2d ownerScale, out _); |
| | 1360 | 156 | | return _hasMassPropertyCenter |
| | 1360 | 157 | | && ownerScale == _massPropertyOwnerScale |
| | 1360 | 158 | | && LocalOffset == _massPropertyOffset |
| | 1360 | 159 | | && HasCommittedShape == _massPropertyCommitted |
| | 1360 | 160 | | ? ExactMassPoint2D.FromPoint(_massPropertyCenter) |
| | 1360 | 161 | | : CalculateAggregateMassPoint(usePrepared: false); |
| | | 162 | | } |
| | | 163 | | |
| | | 164 | | internal override ExactMassPoint2D CalculatePreparedLocalMassPoint() => |
| | 1431 | 165 | | CalculateAggregateMassPoint(usePrepared: true); |
| | | 166 | | |
| | | 167 | | private ExactMassPoint2D CalculateAggregateMassPoint(bool usePrepared) |
| | | 168 | | { |
| | 1767 | 169 | | bool hasPositiveWeight = false; |
| | 8234 | 170 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 171 | | { |
| | 2350 | 172 | | LSCollider2D partCollider = _partColliders[i]; |
| | 2350 | 173 | | ExactMassWeight weight = usePrepared |
| | 2350 | 174 | | ? partCollider.CalculatePreparedAreaForMassProperties() |
| | 2350 | 175 | | : partCollider.CalculateAreaForMassProperties(); |
| | 2350 | 176 | | _massPointScratch[i] = usePrepared |
| | 2350 | 177 | | ? partCollider.CalculatePreparedLocalMassPoint() |
| | 2350 | 178 | | : partCollider.CalculateLocalMassPoint(); |
| | 2350 | 179 | | _massWeightScratch[i] = weight; |
| | 2350 | 180 | | hasPositiveWeight |= !weight.IsZero; |
| | | 181 | | } |
| | | 182 | | |
| | 1767 | 183 | | if (!hasPositiveWeight) |
| | | 184 | | { |
| | 24 | 185 | | for (int i = 0; i < _massWeightScratch.Length; i++) |
| | 8 | 186 | | _massWeightScratch[i] = ExactMassWeight.One; |
| | | 187 | | } |
| | | 188 | | |
| | 1767 | 189 | | if (!ExactMassPoint2D.TryGetWeightedAverage( |
| | 1767 | 190 | | _massPointScratch, |
| | 1767 | 191 | | _massWeightScratch, |
| | 1767 | 192 | | out Vector2d center)) |
| | | 193 | | { |
| | 2 | 194 | | throw new InvalidOperationException( |
| | 2 | 195 | | usePrepared |
| | 2 | 196 | | ? "Prepared 2D compound mass-property point is outside the Fixed64 coordinate domain." |
| | 2 | 197 | | : "The 2D compound collider's center of mass is outside the Fixed64 coordinate domain."); |
| | | 198 | | } |
| | 1765 | 199 | | return ExactMassPoint2D.FromPoint(center); |
| | | 200 | | } |
| | | 201 | | |
| | | 202 | | internal override ExactMassWeight CalculateAreaForMassProperties() => |
| | 2 | 203 | | CalculateAggregateMassWeight(usePrepared: false); |
| | | 204 | | |
| | | 205 | | internal override ExactMassWeight CalculatePreparedAreaForMassProperties() => |
| | 1430 | 206 | | CalculateAggregateMassWeight(usePrepared: true); |
| | | 207 | | |
| | | 208 | | private ExactMassWeight CalculateAggregateMassWeight(bool usePrepared) |
| | | 209 | | { |
| | 1432 | 210 | | ExactMassWeight totalWeight = ExactMassWeight.Zero; |
| | 6442 | 211 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 212 | | { |
| | 1789 | 213 | | ExactMassWeight weight = usePrepared |
| | 1789 | 214 | | ? _partColliders[i].CalculatePreparedAreaForMassProperties() |
| | 1789 | 215 | | : _partColliders[i].CalculateAreaForMassProperties(); |
| | 1789 | 216 | | totalWeight = totalWeight.Add(weight); |
| | | 217 | | } |
| | | 218 | | |
| | 1432 | 219 | | return totalWeight; |
| | | 220 | | } |
| | | 221 | | |
| | | 222 | | internal override Fixed64 CalculateCenterOfMassMoment(Fixed64 mass) |
| | | 223 | | { |
| | 1181 | 224 | | EnsureMassPropertyCenter(); |
| | 1181 | 225 | | return CalculateMomentAboutReference(mass, _massPropertyCenter); |
| | | 226 | | } |
| | | 227 | | |
| | | 228 | | /// <inheritdoc/> |
| | | 229 | | public override Fixed64 CalculateMomentOfInertia(Fixed64 mass, Vector2d localReferencePoint) |
| | | 230 | | { |
| | 1218 | 231 | | if (mass <= Fixed64.Zero) |
| | 2 | 232 | | return Fixed64.Zero; |
| | 1216 | 233 | | EnsureMassPropertyCenter(); |
| | 1216 | 234 | | return localReferencePoint == _massPropertyCenter |
| | 1216 | 235 | | ? CalculateCenterOfMassMoment(mass) |
| | 1216 | 236 | | : CalculateMomentAboutReference(mass, localReferencePoint); |
| | | 237 | | } |
| | | 238 | | |
| | | 239 | | private void EnsureMassPropertyCenter() |
| | | 240 | | { |
| | 2397 | 241 | | GetCurrentScaleFactors(out Vector2d ownerScale, out _); |
| | 2397 | 242 | | if (_hasMassPropertyCenter && ownerScale == _massPropertyOwnerScale |
| | 2397 | 243 | | && LocalOffset == _massPropertyOffset && HasCommittedShape == _massPropertyCommitted) |
| | 2227 | 244 | | return; |
| | | 245 | | |
| | 170 | 246 | | _hasMassPropertyCenter = false; |
| | 170 | 247 | | _massPropertyCenter = CalculateLocalCenterOfMassOffset(); |
| | 170 | 248 | | _massPropertyOwnerScale = ownerScale; |
| | 170 | 249 | | _massPropertyOffset = LocalOffset; |
| | 170 | 250 | | _massPropertyCommitted = HasCommittedShape; |
| | 170 | 251 | | _hasMomentGeometry = false; |
| | 170 | 252 | | _hasMassPropertyCenter = true; |
| | 170 | 253 | | } |
| | | 254 | | |
| | | 255 | | private Fixed64 CalculateMomentAboutReference(Fixed64 mass, Vector2d referencePoint) |
| | | 256 | | { |
| | 1216 | 257 | | if (!_hasMomentGeometry || referencePoint != _momentReferencePoint) |
| | 197 | 258 | | CacheMomentGeometry(referencePoint); |
| | | 259 | | |
| | 1216 | 260 | | Signed704 numerator = WideArithmetic.MultiplySigned576ToSigned704( |
| | 1216 | 261 | | _momentGeometry, Signed320.ExtendValue(Signed192.Raw(mass))); |
| | 1216 | 262 | | if (!Fixed64.TryGetSignedRawRatio(numerator, _momentDenominator, out Fixed64 moment)) |
| | | 263 | | { |
| | 3 | 264 | | throw new InvalidOperationException( |
| | 3 | 265 | | "The 2D compound collider's moment of inertia is outside the Fixed64 scalar domain."); |
| | | 266 | | } |
| | 1213 | 267 | | return moment; |
| | | 268 | | } |
| | | 269 | | |
| | | 270 | | private void CacheMomentGeometry(Vector2d referencePoint) |
| | | 271 | | { |
| | 197 | 272 | | ExactMassWeight totalWeight = ExactMassWeight.Zero; |
| | 1020 | 273 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 274 | | { |
| | 313 | 275 | | ExactMassWeight weight = _partColliders[i].CalculateAreaForMassProperties(); |
| | 313 | 276 | | _massWeightScratch[i] = weight; |
| | 313 | 277 | | totalWeight = totalWeight.Add(weight); |
| | | 278 | | } |
| | | 279 | | |
| | 197 | 280 | | if (totalWeight.IsZero) |
| | | 281 | | { |
| | 16 | 282 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 283 | | { |
| | 5 | 284 | | _massWeightScratch[i] = ExactMassWeight.One; |
| | 5 | 285 | | totalWeight = totalWeight.Add(ExactMassWeight.One); |
| | | 286 | | } |
| | | 287 | | } |
| | | 288 | | |
| | 197 | 289 | | ExactMassPoint2D reference = ExactMassPoint2D.FromPoint(referencePoint); |
| | 197 | 290 | | Signed576 geometry = default; |
| | 1020 | 291 | | for (int i = 0; i < _partColliders.Length; i++) |
| | | 292 | | { |
| | 313 | 293 | | LSCollider2D part = _partColliders[i]; |
| | 313 | 294 | | ExactMassWeight weight = _massWeightScratch[i]; |
| | 313 | 295 | | if (weight.IsZero) |
| | | 296 | | continue; |
| | 312 | 297 | | ExactMassPoint2D point = part.CalculateLocalMassPoint(); |
| | 312 | 298 | | Signed320 dx = WideArithmetic.SubtractSigned320(point.XNumerator, reference.XNumerator); |
| | 312 | 299 | | Signed320 dy = WideArithmetic.SubtractSigned320(point.YNumerator, reference.YNumerator); |
| | 312 | 300 | | Signed320 squaredDistance = Signed320.NarrowValue(WideArithmetic.AddSigned576( |
| | 312 | 301 | | WideArithmetic.MultiplySigned320(dx, dx), WideArithmetic.MultiplySigned320(dy, dy))); |
| | 312 | 302 | | Signed576 parallelAxis = WideArithmetic.MultiplySigned576( |
| | 312 | 303 | | WideArithmetic.MultiplySigned320(squaredDistance, weight.Numerator), 60); |
| | 312 | 304 | | Signed576 intrinsic = WideArithmetic.MultiplySigned576( |
| | 312 | 305 | | CompoundMomentMath2D.GetWeightedMoment(part, weight, _parts[i].LocalRotation, dx, dy, |
| | 312 | 306 | | out Signed576 firstMomentContribution), Signed192.One); |
| | 312 | 307 | | geometry = WideArithmetic.AddSigned576(geometry, WideArithmetic.AddSigned576(intrinsic, parallelAxis)); |
| | 312 | 308 | | geometry = WideArithmetic.AddSigned576(geometry, firstMomentContribution); |
| | | 309 | | } |
| | | 310 | | // Semantic points retain Q64 coordinates. Their squared offsets and |
| | | 311 | | // weighted intrinsic moments share Q256; only the final parent moment rounds. |
| | 197 | 312 | | _momentGeometry = geometry; |
| | 197 | 313 | | _momentDenominator = Signed704.ExtendValue(WideArithmetic.MultiplySigned576( |
| | 197 | 314 | | WideArithmetic.MultiplySigned576(Signed576.ExtendValue(totalWeight.Numerator), |
| | 197 | 315 | | Signed192.One, Signed192.One, Signed192.One, Signed192.One), 60)); |
| | 197 | 316 | | _momentReferencePoint = referencePoint; |
| | 197 | 317 | | _hasMomentGeometry = true; |
| | 197 | 318 | | } |
| | | 319 | | |
| | | 320 | | internal Fixed64 GetMutationGeometryReach(LSCollider2D changed, Vector2d ownerScale, |
| | | 321 | | Fixed64 candidateIntrinsic, Vector2d candidateOffset) |
| | | 322 | | { |
| | 11 | 323 | | Fixed64 reach = Fixed64.Zero; |
| | 44 | 324 | | for (int i = 0; i < _parts.Length; i++) |
| | | 325 | | { |
| | 11 | 326 | | LSCollider2D part = _partColliders[i]; |
| | 11 | 327 | | bool replaced = ReferenceEquals(part, changed); |
| | 11 | 328 | | Fixed64 intrinsic = replaced ? candidateIntrinsic |
| | 11 | 329 | | : part.GetCandidateGeometryReach(ownerScale, _parts[i].LocalScale); |
| | 11 | 330 | | reach = FixedMath.Max(reach, ColliderGeometryPolicy.Add( |
| | 11 | 331 | | ColliderGeometryPolicy.Attachment(replaced ? candidateOffset : part.LocalOffset, ownerScale), |
| | 11 | 332 | | intrinsic)); |
| | | 333 | | } |
| | 11 | 334 | | return reach; |
| | | 335 | | } |
| | | 336 | | |
| | | 337 | | private protected override void PrepareShape(in ColliderShapeSnapshot2D snapshot) |
| | | 338 | | { |
| | 1437 | 339 | | Vector2d min = Vector2d.Zero; |
| | 1437 | 340 | | Vector2d max = Vector2d.Zero; |
| | | 341 | | |
| | 1437 | 342 | | Fixed64 reach = Fixed64.Zero; |
| | 6450 | 343 | | for (int i = 0; i < _parts.Length; i++) |
| | | 344 | | { |
| | 1794 | 345 | | CompoundColliderPart2D part = _parts[i]; |
| | 1794 | 346 | | LSCollider2D partCollider = _partColliders[i]; |
| | 1794 | 347 | | partCollider.PrepareCompoundPart( |
| | 1794 | 348 | | snapshot, |
| | 1794 | 349 | | part.LocalRotation, |
| | 1794 | 350 | | part.LocalScale, |
| | 1794 | 351 | | PreparedContext); |
| | 1788 | 352 | | reach = FixedMath.Max(reach, ColliderGeometryPolicy.Add( |
| | 1788 | 353 | | partCollider.PreparedAttachmentReach, |
| | 1788 | 354 | | partCollider.PreparedGeometryReach)); |
| | | 355 | | |
| | 1788 | 356 | | Vector2d partMin = partCollider.PreparedShapeBounds.Min; |
| | 1788 | 357 | | Vector2d partMax = partCollider.PreparedShapeBounds.Max; |
| | 1788 | 358 | | if (i == 0) |
| | | 359 | | { |
| | 1432 | 360 | | min = partMin; |
| | 1432 | 361 | | max = partMax; |
| | 1432 | 362 | | continue; |
| | | 363 | | } |
| | | 364 | | |
| | 356 | 365 | | min = new Vector2d(FixedMath.Min(min.X, partMin.X), FixedMath.Min(min.Y, partMin.Y)); |
| | 356 | 366 | | max = new Vector2d(FixedMath.Max(max.X, partMax.X), FixedMath.Max(max.Y, partMax.Y)); |
| | | 367 | | } |
| | | 368 | | |
| | 1431 | 369 | | _ = CalculatePreparedLocalMassPoint(); |
| | 1430 | 370 | | _ = CalculatePreparedAreaForMassProperties(); |
| | 1430 | 371 | | SetPreparedGeometryReach(reach); |
| | 1430 | 372 | | SetPreparedBounds(FixedBoundArea.FromMinMax(min, max)); |
| | 1430 | 373 | | } |
| | | 374 | | |
| | | 375 | | private protected override void PublishShape() |
| | | 376 | | { |
| | 6406 | 377 | | for (int i = 0; i < _parts.Length; i++) |
| | | 378 | | { |
| | 1778 | 379 | | CompoundColliderPart2D part = _parts[i]; |
| | 1778 | 380 | | _partColliders[i].PublishCompoundPart( |
| | 1778 | 381 | | part.LocalRotation, |
| | 1778 | 382 | | part.LocalScale, |
| | 1778 | 383 | | PreparedContext); |
| | | 384 | | } |
| | 1425 | 385 | | } |
| | | 386 | | |
| | | 387 | | private static LSCollider2D MaterializePartCollider(CompoundColliderPart2D part) |
| | | 388 | | { |
| | 476 | 389 | | LSCollider2D collider = part.Shape.CreateRuntimeCollider(); |
| | 476 | 390 | | collider.LocalOffset = part.LocalOffset; |
| | 476 | 391 | | collider.Material = part.ResolveMaterial(PhysicsMaterial.Default); |
| | 476 | 392 | | return collider; |
| | | 393 | | } |
| | | 394 | | |
| | | 395 | | /// <inheritdoc/> |
| | | 396 | | protected override void OnMaterialChanged() |
| | | 397 | | { |
| | 114 | 398 | | for (int i = 0; i < _parts.Length; i++) |
| | 35 | 399 | | _partColliders[i].Material = _parts[i].ResolveMaterial(Material); |
| | 22 | 400 | | } |
| | | 401 | | |
| | | 402 | | [MethodImpl(MethodImplOptions.AggressiveInlining)] |
| | | 403 | | private static void ValidatePart(CompoundColliderPart2D part) => |
| | 477 | 404 | | ChronicleGuard.ThrowIfArgument(part.IsDefault, nameof(part), "2D compound collider part cannot be default."); |
| | | 405 | | } |