bool IsValidKeyInView(ParallaxLayer layer) { var camBounds = _viewBoundary.GetBounds(); var bounds = layer.GetBounds(); switch (_repeat) { case LayerRepeatType.XAxis: var vertYMin = WorldToAxisKey(bounds, new Vector2(camBounds.center.x, camBounds.min.y)); var vertYMax = WorldToAxisKey(bounds, new Vector2(camBounds.center.x, camBounds.max.y)); return(vertYMin.y <= Y_ORIGIN && vertYMax.y >= Y_ORIGIN); case LayerRepeatType.YAxis: var vertXMin = WorldToAxisKey(bounds, new Vector2(camBounds.min.x, camBounds.center.y)); var vertXMax = WorldToAxisKey(bounds, new Vector2(camBounds.max.x, camBounds.center.y)); return(vertXMin.x <= X_ORIGIN && vertXMax.x >= X_ORIGIN); case LayerRepeatType.Both: return(true); default: throw new ArgumentOutOfRangeException(); } }
protected override void OnUpdateModule(ParallaxLayer layer) { _bounds = UpdateBounds(_bounds); var pos = layer.transform.position; var b = layer.GetBounds(); if (_xMinOverflow.IsOverride() && b.min.x < _bounds.min.x) { if (_xMinOverflow == BoundaryOverride.Contain) { pos.x += _bounds.min.x - b.min.x; } else if (_xMinOverflow == BoundaryOverride.RecycleOnOppositeSide && _xMaxOverflow.IsOverride()) { pos.x = _bounds.max.x; } } if (_xMaxOverflow.IsOverride() && b.max.x > _bounds.max.x) { if (_xMaxOverflow == BoundaryOverride.Contain) { pos.x += _bounds.max.x - b.max.x; } else if (_xMaxOverflow == BoundaryOverride.RecycleOnOppositeSide && _xMinOverflow.IsOverride()) { pos.x = _bounds.min.x; } } if (_yMinOverflow.IsOverride() && b.min.y < _bounds.min.y) { if (_yMinOverflow == BoundaryOverride.Contain) { pos.y += _bounds.min.y - b.min.y; } else if (_yMinOverflow == BoundaryOverride.RecycleOnOppositeSide && _yMaxOverflow.IsOverride()) { pos.y = _bounds.max.y; } } if (_yMaxOverflow.IsOverride() && b.max.y > _bounds.max.y) { if (_yMaxOverflow == BoundaryOverride.Contain) { pos.y += _bounds.max.y - b.max.y; } else if (_yMaxOverflow == BoundaryOverride.RecycleOnOppositeSide && _yMinOverflow.IsOverride()) { pos.y = _bounds.min.y; } } layer.transform.position = pos; }
Vector2Int GetValidKeyInView(ParallaxLayer layer) { var camBounds = _viewBoundary.GetBounds(); var bounds = layer.GetBounds(); switch (_repeat) { case LayerRepeatType.XAxis: var vertYMin = WorldToAxisKey(bounds, new Vector2(camBounds.center.x, camBounds.min.y)); return(new Vector2Int(vertYMin.x, Y_ORIGIN)); case LayerRepeatType.YAxis: var vertXMin = WorldToAxisKey(bounds, new Vector2(camBounds.min.x, camBounds.center.y)); return(new Vector2Int(X_ORIGIN, vertXMin.y)); case LayerRepeatType.Both: return(WorldToAxisKey(layer.GetBounds(), _viewBoundary.GetBounds().center)); default: throw new ArgumentOutOfRangeException(); } }