Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ protected override void OnDestroy()
CollectionCaches<Collider2D>.StoreAndDefault(ref _hits, _hits.Length);
}

/// <summary>
/// Returns the layers which interact with layer in the 2D collision matrix. Used when Layers is nothing.
/// </summary>
protected override int GetInteractableLayersValue(int layer) => GameKit.Dependencies.Utilities.Layers.GetInteractableLayersValue2D(layer);

/// <summary>
/// Called by the PredictionManager immediately before a reconcile begins.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/// <summary>
/// Returns the layers which interact with layer in the collision matrix. Used when Layers is nothing.
/// </summary>
protected virtual int GetInteractableLayersValue(int layer) => GameKit.Dependencies.Utilities.Layers.GetInteractableLayersValue(layer);

/// <summary>
/// Implement collider checking logic within this method.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ public static class Layers
/// Lookup of interactable layers for each layer.
/// </summary>
private static Dictionary<int, int> _interactablesLayers;
/// <summary>
/// Lookup of interactable layers for each layer using the 2D collision matrix.
/// </summary>
private static Dictionary<int, int> _interactablesLayers2D;

/// <summary>
/// Tries to initializes InteractableLayers.
Expand All @@ -37,6 +41,30 @@ private static void TryInitializeInteractableLayers()
}
}

/// <summary>
/// Tries to initializes InteractableLayers2D.
/// </summary>
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;
}
}

/// <summary>
/// Returns interactable layers value for layer.
/// </summary>
Expand All @@ -46,6 +74,15 @@ public static int GetInteractableLayersValue(int layer)
return _interactablesLayers[layer];
}

/// <summary>
/// Returns interactable layers value for layer using the 2D collision matrix.
/// </summary>
public static int GetInteractableLayersValue2D(int layer)
{
TryInitializeInteractableLayers2D();
return _interactablesLayers2D[layer];
}

/// <summary>
/// Returns interactable layers LayerMask for a GameObject.
/// </summary>
Expand Down