diff --git a/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs b/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs index bad08e41..f7454fdd 100644 --- a/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs +++ b/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkCollider2D.cs @@ -59,6 +59,11 @@ protected override void OnDestroy() CollectionCaches.StoreAndDefault(ref _hits, _hits.Length); } + /// + /// Returns the layers which interact with layer in the 2D collision matrix. Used when Layers is nothing. + /// + protected override int GetInteractableLayersValue(int layer) => GameKit.Dependencies.Utilities.Layers.GetInteractableLayersValue2D(layer); + /// /// Called by the PredictionManager immediately before a reconcile begins. /// diff --git a/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkColliderBase.cs b/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkColliderBase.cs index 03d2745a..25deea20 100644 --- a/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkColliderBase.cs +++ b/Assets/FishNet/Runtime/Generated/Component/Prediction/NetworkColliderBase.cs @@ -147,13 +147,18 @@ protected bool TryPrepareColliderCheck(uint tick) if (_lastGameObjectLayer != currentLayer) { _lastGameObjectLayer = currentLayer; - InteractableLayers = GameKit.Dependencies.Utilities.Layers.GetInteractableLayersValue(currentLayer); + InteractableLayers = GetInteractableLayersValue(currentLayer); } } return true; } + /// + /// Returns the layers which interact with layer in the collision matrix. Used when Layers is nothing. + /// + protected virtual int GetInteractableLayersValue(int layer) => GameKit.Dependencies.Utilities.Layers.GetInteractableLayersValue(layer); + /// /// Implement collider checking logic within this method. /// diff --git a/Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Layers.cs b/Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Layers.cs index edbecea3..fd5ef292 100644 --- a/Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Layers.cs +++ b/Assets/FishNet/Runtime/Plugins/GameKit/Dependencies/Utilities/Layers.cs @@ -12,6 +12,10 @@ public static class Layers /// Lookup of interactable layers for each layer. /// private static Dictionary _interactablesLayers; + /// + /// Lookup of interactable layers for each layer using the 2D collision matrix. + /// + private static Dictionary _interactablesLayers2D; /// /// Tries to initializes InteractableLayers. @@ -37,6 +41,30 @@ private static void TryInitializeInteractableLayers() } } + /// + /// Tries to initializes InteractableLayers2D. + /// + private static void TryInitializeInteractableLayers2D() + { + if (_interactablesLayers2D != null) + return; + + _interactablesLayers2D = new(); + for (int i = 0; i < 32; i++) + { + int mask = 0; + for (int j = 0; j < 32; j++) + { + if (!Physics2D.GetIgnoreLayerCollision(i, j)) + { + mask |= 1 << j; + } + } + // Setting without add check is quicker. + _interactablesLayers2D[i] = mask; + } + } + /// /// Returns interactable layers value for layer. /// @@ -46,6 +74,15 @@ public static int GetInteractableLayersValue(int layer) return _interactablesLayers[layer]; } + /// + /// Returns interactable layers value for layer using the 2D collision matrix. + /// + public static int GetInteractableLayersValue2D(int layer) + { + TryInitializeInteractableLayers2D(); + return _interactablesLayers2D[layer]; + } + /// /// Returns interactable layers LayerMask for a GameObject. ///