//Call to the engine to create a new piece and create a representation of the random piece in view private void CreateTetrimino() { if (!pv.IsMine && !PhotonNetwork.IsMasterClient) { return; } if (mCurrentTetrimino != null) { mCurrentTetrimino.isLocked = true; } var tetrimino = mPlayfield.CreateTetrimo(); var tetriminoView = mTetriminoPool.Collect(); tetriminoView.InitiateTetrimino(tetrimino); mTetriminos.Add(tetriminoView); if (mPreview != null) { mTetriminoPool.Release(mPreview); } mPreview = mTetriminoPool.Collect(); mPreview.InitiateTetrimino(tetrimino, true); mRefreshPreview = true; }
private void CreateList(int startIndex) { var totalSize = 0f; var lastObjectPosition = Vector2.zero; startIndex = Mathf.Max(0, startIndex); var currentIndex = startIndex; var canDrag = false; if (infoList != null && infoList.Count > 0) { do { var obj = objectPool.Collect(); obj.UpdateScrollObject(this.infoList[currentIndex], currentIndex); var posX = currentIndex > 0 ? lastObjectPosition.x + (mIsHorizontal ? spacing : 0) : 0; var posY = currentIndex > 0 ? lastObjectPosition.y - (mIsVertical ? spacing : 0) : 0; obj.RectTransform.anchoredPosition = new Vector2(posX, posY); lastObjectPosition = new Vector2(posX + (mIsHorizontal ? obj.CurrentWidth : 0), posY - (mIsVertical ? obj.CurrentHeight : 0)); totalSize += ((mIsVertical) ? obj.CurrentHeight : obj.CurrentWidth) + spacing; currentIndex++; } while (currentIndex < infoList.Count && (mIsVertical && totalSize < (ScrollRect.viewport.rect.height * 2f)) || (mIsHorizontal && totalSize < (ScrollRect.viewport.rect.width * 2f))); canDrag = (mIsHorizontal && totalSize > ScrollRect.viewport.rect.width) || (mIsVertical && totalSize > ScrollRect.viewport.rect.height); } ToggleScroll(canDrag); }
//Draw each block in the correct position based on the engine position and rotation private void Draw() { var cRot = currentTetrimino.blockPositions[currentTetrimino.currentRotation]; var currentIndex = 0; for (int i = 0; i < cRot.Length; i++) { for (int j = 0; j < cRot[i].Length; j++) { if (cRot[i][j] == 0) { continue; } var piece = mPieces.Count > currentIndex ? mPieces[currentIndex] : null; if (piece == null) { piece = blockPool.Collect(transform); piece.SetColor(mBlockColor); mPieces.Add(piece); } currentIndex++; MovePiece(piece, mTetriminoPosition.x + j, mTetriminoPosition.y + i); } } }
void Update() { if (Input.GetKeyDown(KeyCode.Space)) { var o = mPooling.Collect(); o.transform.position = new Vector3(Random.Range(-13f, 13f), Random.Range(-6.5f, 6.5f), 2.66f); } }
//Call to the engine to create a new piece and create a representation of the random piece in view private void CreateTetrimino() { if (mCurrentTetrimino != null) { mCurrentTetrimino.isLocked = true; } var tetrimino = mPlayfield.CreateTetrimo(); var tetriminoView = mTetriminoPool.Collect(); tetriminoView.InitiateTetrimino(tetrimino); mTetriminos.Add(tetriminoView); if (mPreview != null) { mTetriminoPool.Release(mPreview); } mPreview = mTetriminoPool.Collect(); mPreview.InitiateTetrimino(tetrimino, true); mRefreshPreview = true; }
//[PunRPC] //Call to the engine to create a new piece and create a representation of the random piece in view private void CreateTetrimino() { hasStashed = false; if (mCurrentTetrimino != null) { mCurrentTetrimino.isLocked = true; } var tetrimino = mPlayfield.CreateTetrimo(); var tetriminoView = mTetriminoPool.Collect(); tetriminoView.InitiateTetrimino(tetrimino); mTetriminos.Add(tetriminoView); if (mPreview != null) { mTetriminoPool.Release(mPreview); } mPreview = mTetriminoPool.Collect(); mPreview.InitiateTetrimino(tetrimino, true); //Try to create a nextBlock view if (mNextView != null) { mTetriminoPool.Release(mNextView); } mNextView = mTetriminoPool.Collect(nextTetriminoParent); mNextView.InitiateTetrimino(mPlayfield.mNextTetrimino); mRefreshPreview = true; if (firstPiece) { firstPiece = false; } }
public void Initiate(ScrollRect scrollRect, T[] infoList, int startIndex, GameObject objReference, int initialAmount, bool createMoreIfNeeded = true) { mScrollRect = scrollRect; if (mScrollRect == null) { throw new Exception("No scroll rect in gameObject."); } if (objReference == null) { throw new Exception("No Reference GameObject setted."); } mInitialAmount = initialAmount; mInfoList = infoList; var currentIndex = startIndex; mScrollRect.onValueChanged.AddListener(OnScroll); mScrollRect.movementType = ScrollRect.MovementType.Unrestricted; if (mScrollRect.content.GetComponent <VerticalLayoutGroup>() != null) { mVerticalLayoutGroup = mScrollRect.content.GetComponent <VerticalLayoutGroup>(); mVerticalLayoutGroup.spacing = spacing; } if (mScrollRect.content.GetComponent <HorizontalLayoutGroup>() != null) { mHorizontalLayoutGroup = mScrollRect.content.GetComponent <HorizontalLayoutGroup>(); mHorizontalLayoutGroup.spacing = spacing; } if (mScrollRect.content.GetComponent <GridLayoutGroup>() != null) { mGridLayoutGroup = mScrollRect.content.GetComponent <GridLayoutGroup>(); mGridLayoutGroup.spacing = new Vector2(spacing, spacing); } if (mScrollRect.content.GetComponent <ContentSizeFitter>() != null) { mContentSizeFitter = mScrollRect.content.GetComponent <ContentSizeFitter>(); } mIsHorizontal = mScrollRect.horizontal; mIsVertical = mScrollRect.vertical; objectPool.createMoreIfNeeded = createMoreIfNeeded; objectPool.Initialize(Mathf.Min(initialAmount, infoList.Length), objReference, mScrollRect.content); float totalSize = 0f; int toCreate = Mathf.Min(initialAmount, infoList.Length); var lastObjectPosition = Vector2.zero; for (var i = 0; i < toCreate; i++) { var obj = objectPool.Collect(); obj.updateScrollObject(mInfoList[currentIndex + i], currentIndex + i); var rect = obj.GetComponent <RectTransform>(); var posX = i > 0 ? lastObjectPosition.x + (mIsHorizontal ? +spacing : 0) : 0; var posY = i > 0 ? lastObjectPosition.y - (mIsVertical ? spacing : 0) : 0; rect.anchoredPosition = new Vector2(posX, posY); lastObjectPosition = new Vector2(posX + (mIsHorizontal ? obj.currentWidth : 0), posY - (mIsVertical ? obj.currentHeight : 0)); totalSize += (mIsVertical) ? obj.currentHeight : obj.currentWidth; } totalSize = (totalSize / (float)toCreate) * infoList.Length; bool canDrag = (mIsHorizontal && totalSize > mScrollRect.content.rect.width) || (mIsVertical && totalSize > mScrollRect.content.rect.height); ToggleScroll(canDrag); DisableGridComponents(); objectPool.ForEach(x => x.SetRefreshListAction(RefreshPosition)); if (!mIsHorizontal || !mIsVertical) { return; } Debug.LogError("AssukarSynamicScroll doesn't support scrolling in both directions, please choose one direction (horizontal or vertical)"); mIsHorizontal = false; }