public void ChangingPositions(GameObject slideObject) { SlideCell slideCell = slideObject.GetComponent <SlideCell>(); if (slideCell.GetIsPositionTrue().Equals(true)) { SlidePuzzle.shiftedCellCount++; slideCell.SetIsPositionTrue(false); if (SlidePuzzle.selectedCell.GetComponent <SlideCell>().GetIsPositionTrue().Equals(true)) { SlidePuzzle.shiftedCellCount++; SlidePuzzle.selectedCell.GetComponent <SlideCell>().SetIsPositionTrue(false); } } else { if (SlidePuzzle.selectedCell.GetComponent <SlideCell>().GetIsPositionTrue().Equals(true)) { SlidePuzzle.shiftedCellCount++; SlidePuzzle.selectedCell.GetComponent <SlideCell>().SetIsPositionTrue(false); } else { if (SlidePuzzle.selectedCell.GetComponent <SlideCell>().GetTruePosition().Equals(slideObject.GetComponent <RectTransform>().anchoredPosition)) { SlidePuzzle.shiftedCellCount--; SlidePuzzle.selectedCell.GetComponent <SlideCell>().SetIsPositionTrue(true); if (slideCell.GetTruePosition().Equals(SlidePuzzle.selectedCell.GetComponent <RectTransform>().anchoredPosition)) { SlidePuzzle.shiftedCellCount--; slideCell.SetIsPositionTrue(true); } } else { if (slideCell.GetTruePosition().Equals(SlidePuzzle.selectedCell.GetComponent <RectTransform>().anchoredPosition)) { SlidePuzzle.shiftedCellCount--; slideCell.SetIsPositionTrue(true); } } } } Vector2 tempPosition = SlidePuzzle.selectedCell.GetComponent <RectTransform>().anchoredPosition; randomPositionsOfCells[slideObject.GetComponent <RectTransform>().anchoredPosition] = selectedCell; randomPositionsOfCells[tempPosition] = slideObject; SlidePuzzle.selectedCell.GetComponent <RectTransform>().anchoredPosition = slideObject.GetComponent <RectTransform>().anchoredPosition; slideObject.GetComponent <RectTransform>().anchoredPosition = tempPosition; }
private void BuilCell(Vector2 randomCellPosition, Quaternion rotation, int index, float i, float j, Vector2 pivot, Rect rec, int maxGlowWidth) { //Cordinates for cell float xCordinate = (pixel * i) + (pixel / 2f); float yCordinate = (pixel * j) + (pixel / 2f); //Creating cells GameObject cell = new GameObject(); //Bounding with script if (isRotateEnabled.Equals(true)) { if (index != pieceCount - 1) { cell.AddComponent <TouchSlideCell>(); } } //--------------------- RectTransform rectTransform = cell.AddComponent <RectTransform>() as RectTransform; BoxCollider2D box2D = cell.AddComponent <BoxCollider2D>() as BoxCollider2D; //Creating with z: +90 position, because default z position is -180 and we want it to be 0 if (isRotateEnabled) { cell.transform.SetPositionAndRotation(randomCellPosition, rotation); } else { cell.transform.SetPositionAndRotation(randomCellPosition, Quaternion.Euler(0, 0, 0)); } //Naming Cell and Setting his parent cell.name = "cell_" + xCordinate.ToString() + "x" + yCordinate.ToString(); cellsParent.name = "Parent_Of_Cells\\" + pieceCount.ToString() + "-Children"; cell.transform.SetParent(cellsParent.transform); //Scalling rectTransform.sizeDelta = new Vector2(pixel, pixel); box2D.size = new Vector2(pixel, pixel); cell.transform.localScale = new Vector3(1, 1, 1); //Positioning; anchorMin and anchorMax are for starting position bottom left corner of parent. rectTransform.anchorMin = new Vector2(0f, 0f); rectTransform.anchorMax = new Vector2(0f, 0f); rectTransform.anchoredPosition = new Vector3(x: randomCellPosition.x, y: randomCellPosition.y); //Creating Sprite Texture--------------------------------------------------------------------- Texture2D spriteTexture = new Texture2D((int)(pixel * 100f), (int)(pixel * 100f)); var pixels = painting.texture.GetPixels((int)((pixel * 100) * i), (int)((pixel * 100) * j), (int)(pixel * 100f), (int)(pixel * 100f)); spriteTexture.SetPixels(pixels); spriteTexture.Apply(); //------------------------------------------------------------------------------------ //Setting sprite to Cell SpriteRenderer spriteRenderer = cell.AddComponent <SpriteRenderer>() as SpriteRenderer; spriteRenderer.sprite = Sprite.Create(spriteTexture, rec, pivot); //spriteRenderer.color = Color.blue; spriteRenderer.sortingLayerName = "Cells"; spriteRenderer.material.shader = glowShader; //GlowEffect---------------- SpriteGlowEffect glowEffect = cell.AddComponent <SpriteGlowEffect>(); glowEffect.OutlineWidth = 0; glowEffect.AlphaThreshold = 0.01f; //------------------------- //-----SlideCell Values--------- SlideCell slideCell = cell.AddComponent <SlideCell>(); slideCell.SetTruePosition(new Vector2(xCordinate, yCordinate)); slideCell.SetIsPositionTrue(slideCell.GetTruePosition().Equals(randomCellPosition)); slideCell.SetMaxGlowWidth(maxGlowWidth); //----------------------- //Finally, adding our cell to the list. cells.SetValue(cell, index); }