public void AddToGrid(Tetromino tetromino) { foreach (Transform children in tetromino.Transform) { int roundedX = Mathf.RoundToInt(children.transform.position.x); int roundedY = Mathf.RoundToInt(children.transform.position.y); grid[roundedX, roundedY] = children; } spawner.DisableTetromino(tetromino); CheckForLines(); if (grid[Mathf.RoundToInt(spawnPoint.x), Mathf.RoundToInt(spawnPoint.y)] != null) { OnOverflow?.Invoke(); return; } spawner.CreateTetrominoForField(this); }
private void MoveBy(float delta) { if (!m_IsEnabled) { return; } var pos = m_ScrollContainer.anchoredPosition; var maxY = m_ContainerHeight - m_ViewportHeight; float nextY = 0.0f; if (m_IsDragging) { if (pos.y < m_InitialPosition.y) { // elastic stretch from atop var leftToGo = pos.y + m_MaxElasticOverflow; var overflowPercent = Mathf.Clamp01((leftToGo / m_MaxElasticOverflow) * .55f); delta *= overflowPercent; } else if (pos.y > maxY) { var leftToGo = (maxY + m_MaxElasticOverflow) - pos.y; var overflowPercent = Mathf.Clamp01((leftToGo / m_MaxElasticOverflow) * .55f); delta *= overflowPercent; } nextY = pos.y + delta; if (!m_UserTopElastic) { if (nextY < m_InitialPosition.y) { nextY = m_InitialPosition.y; } } if (!m_UseBottomElastic) { if (nextY > maxY) { nextY = maxY; } } pos.y = nextY; } else { if (pos.y < m_InitialPosition.y) { // top m_SpeedY = 0; m_TweenEndValue = m_InitialPosition.y; m_IsTweening = true; } else if (pos.y > maxY) { // bottom m_SpeedY = 0; m_TweenEndValue = maxY; m_IsTweening = true; } nextY = pos.y + delta; if (!m_UserTopElastic) { if (nextY < m_InitialPosition.y) { nextY = m_InitialPosition.y; } } if (!m_UseBottomElastic) { if (nextY > maxY) { nextY = maxY; } } pos.y = nextY; } if (nextY < m_InitialPosition.y) { if (IsDragging) { if (!m_IsTweening) { OnOverflow?.Invoke(this, nextY - m_InitialPosition.y, Position.Top); if (Time.time > m_ReleaseTime) { m_ReleaseTime = Time.time + m_ReleaseWaitTime; } } } else { OnUltimatePositionReached?.Invoke(this, Position.Top); } } else if (nextY > maxY) { if (IsDragging) { if (!m_IsTweening) { OnOverflow?.Invoke(this, nextY - maxY, Position.Bottom); if (Time.time > m_ReleaseTime) { m_ReleaseTime = Time.time + m_ReleaseWaitTime; } } } else { OnUltimatePositionReached?.Invoke(this, Position.Bottom); } } m_ScrollContainer.anchoredPosition = pos; }
public virtual bool Visit(OnOverflow onOverflow) { return(true); }
public void DidOverflowPool(ObservableCollection <ISpawnable> pool) { OnOverflow?.Invoke(pool); }