////////////////////////////////////////////////////////////////////////// public void ActivateTile(int index) { UAP_AccessibilityManager.Say("", false, false, UAP_AudioQueue.EInterrupt.All); Vector2 xyCoord = ConvertIndexToXYCoordinates(index); gridpanel tile = GetGridTile(index); // Check whether this tile is already selected if (tile == null || m_SelectedTile == tile) { AbortSelection(); return; } // Is this the first tile to be activated or the second? if (m_SelectedTile == null) { // Select, start sound m_SFXPlayer.clip = m_ActiveTile; m_SFXPlayer.loop = true; m_SFXPlayer.Play(); m_SelectedTile = tile; m_SelectionFrame.SetActive(true); m_SelectionFrame.transform.position = m_SelectedTile.transform.position; return; } // If second, check whether this tile is a neighbor to the first Vector2 selectedXY = ConvertIndexToXYCoordinates(m_SelectedTile.GetIndex()); Vector2 diff = selectedXY - xyCoord; // Is it too far away? if (Mathf.Abs(diff.x) + Mathf.Abs(diff.y) > 1.0f) { AbortSelection(); return; } // Temporarily block input in the AM UAP_AccessibilityManager.BlockInput(true); // Swap the tiles CancelPreview(true); int tileTypeSelected = m_SelectedTile.GetTileType(); m_SelectedTile.SetTileType(tile.GetTileType()); tile.SetTileType(tileTypeSelected); m_SelectedTile = null; m_SelectionFrame.SetActive(false); // Stop looping sound m_SFXPlayer.Stop(); m_MovesGained = 0; ++m_MoveCount; m_levelGoalUpdatedWithMove = false; EvaluateBoard(); }
private void AbortSelection() { // Deselect, stop sound m_SFXPlayer.Stop(); m_SFXPlayer.PlayOneShot(m_SwapAborted); CancelPreview(); UAP_AccessibilityManager.Say("Swap canceled.", false, false, UAP_AudioQueue.EInterrupt.All); m_SelectionFrame.SetActive(false); m_SelectedTile = null; return; }
////////////////////////////////////////////////////////////////////////// void Update() { m_GameDuration += Time.unscaledDeltaTime; // Update swap preview, if any if (m_IsPreviewingSwap) { m_SwapPreviewTimer -= Time.unscaledDeltaTime; float scale = 1.0f - (m_SwapPreviewTimer / m_SwapPreviewDuration); gridpanel tile1 = GetGridTile(m_PreviewIndex1); gridpanel tile2 = GetGridTile(m_PreviewIndex2); tile1.m_GemImage.transform.position = Vector3.Lerp(m_Previewposition1, m_Previewposition2, scale); tile2.m_GemImage.transform.position = Vector3.Lerp(m_Previewposition2, m_Previewposition1, scale); } }
public void OnPointerUpDelegate(PointerEventData data) { m_LastPreviewDir = EVecDir.None; // Ignore these in accessibility mode if (UAP_AccessibilityManager.IsEnabled()) { return; } gridpanel panel = (data.pointerEnter != null ? gameObject.GetComponent <gridpanel>() : null); if (panel == this && !data.dragging) { //Debug.Log("Pointer Up, not dragging - on same tile " + GetTileTypeName()); gameplay.Instance.ActivateTile(m_Index); } }
////////////////////////////////////////////////////////////////////////// private bool IsSameTile(GameObject pointerEnter) { bool wasDroppedOnTile = (pointerEnter != null && pointerEnter.transform.parent != null); //Debug.Log("Dropped on " + (data.pointerEnter != null ? data.pointerEnter.name : "") + " and " + ((data.pointerEnter != null && data.pointerEnter.transform.parent != null) ? data.pointerEnter.transform.parent.name : "")); if (wasDroppedOnTile) { gridpanel droppedOn = pointerEnter.transform.parent.gameObject.GetComponent <gridpanel>(); if (droppedOn != null) { if (droppedOn == this) { return(true); } } } return(false); }
////////////////////////////////////////////////////////////////////////// public void CancelPreview(bool swapSuccessful = false) { //Debug.Log("Cancelling preview"); if (!m_IsPreviewingSwap) { return; } m_IsPreviewingSwap = false; //if (swapSuccessful) // return; // Reset positions gridpanel tile1 = GetGridTile(m_PreviewIndex1); gridpanel tile2 = GetGridTile(m_PreviewIndex2); tile1.m_GemImage.transform.position = m_Previewposition1; tile2.m_GemImage.transform.position = m_Previewposition2; }
////////////////////////////////////////////////////////////////////////// public void PreviewDrag(int index1, int index2) { //Debug.Log("Starting preview"); CancelPreview(); gridpanel tile1 = GetGridTile(index1); gridpanel tile2 = GetGridTile(index2); if (tile1 == null || tile2 == null) { return; } m_IsPreviewingSwap = true; m_SwapPreviewTimer = m_SwapPreviewDuration; m_PreviewIndex1 = index1; m_PreviewIndex2 = index2; m_Previewposition1 = tile1.transform.position; m_Previewposition2 = tile2.transform.position; }
////////////////////////////////////////////////////////////////////////// public void InitBoard(int countX, int countY, int tiletypeCount, int moveCount, List <int> levelGoals) { UAP_AccessibilityManager.BlockInput(true); m_SelectionFrame.SetActive(false); m_CellCountX = countX; m_CellCountY = countY; m_MoveCount = 0; m_GameDuration = 0.0f; m_TileTypeCount = tiletypeCount; for (int i = 0; i < m_GoalsLabel.Length; ++i) { m_GoalsLabel[i].gameObject.SetActive(false); } for (int i = 0; i < m_GoalsImages.Length; ++i) { m_GoalsImages[i].gameObject.SetActive(false); } for (int i = 0; i < m_GoalsImages.Length; ++i) { m_GoalsCheckmarks[i].SetActive(false); } m_LevelGoals.Clear(); m_LevelGoals = levelGoals; m_Cleared.Clear(); for (int i = 0; i < gridpanel.tileTypeCount; ++i) { m_Cleared.Add(0); } // Remove all that is on the board now while (transform.childCount > 0) { Transform go = transform.GetChild(0); go.SetParent(null); DestroyImmediate(go.gameObject); } m_GridTiles.Clear(); // Calculate grid element sizes Vector2 newCellSize = new Vector2(0, 0); newCellSize.x = (m_BaseCellSize / (float)countX) * m_BaseCellCountX; newCellSize.y = (m_BaseCellSize / (float)countY) * m_BaseCellCountY; // Ensure an equal tile size by choosing the smaller one for both axes if (m_MakeSquares) { if (newCellSize.x < newCellSize.y) { newCellSize.y = newCellSize.x; } else { newCellSize.x = newCellSize.y; } } grid.cellSize = newCellSize; grid.constraint = GridLayoutGroup.Constraint.FixedColumnCount; grid.constraintCount = countX; // Instantiate correct number of elements GameObject prefab = Resources.Load("Panel") as GameObject; int count = countX * countY; for (int i = 0; i < count; ++i) { GameObject newPanel = Instantiate(prefab); newPanel.transform.SetParent(transform, false); newPanel.GetComponent <gridpanel>().SetIndex(i, countX); m_GridTiles.Add(newPanel.GetComponent <gridpanel>()); } m_SelectedTile = null; m_MovesLeft = moveCount; UpdateMoveLabel(); UpdateLevelGoalsLabels(); RandomizeTiles(); SaveGameState(); // Insert level goal int goalCount = 0; for (int i = 0; i < gridpanel.tileTypeCount; ++i) { if (m_LevelGoals[i] > 0) { m_GoalsImages[goalCount].gameObject.SetActive(true); m_GoalsImages[goalCount].sprite = GetTileTypeSprite(i); ++goalCount; } } string levelGoalsString = "Level Goals: " /*m_GoalsLabel_Access.m_Text*/; int counter = 0; for (int i = 0; i < gridpanel.tileTypeCount; ++i) { if (m_LevelGoals[i] < 0) { continue; } int cleared = m_Cleared[i]; if (cleared > m_LevelGoals[i]) { cleared = m_LevelGoals[i]; } ++counter; if (m_LevelGoalsString.Length > 0) { levelGoalsString += "\n "; } if (counter == goalCount && goalCount > 1) { levelGoalsString += "And "; } levelGoalsString += m_LevelGoals[i].ToString("0") + " " + gridpanel.GetTileTypeName(i) + " gems, "; } levelGoalsString += "need to be destroyed."; UAP_AccessibilityManager.Say("Game Started. Double Tap with two fingers to pause the game.", false); UAP_AccessibilityManager.Say(levelGoalsString + " \nYou have " + m_MovesLeft.ToString("0") + " moves remaining."); UAP_AccessibilityManager.Say("Tap once with two fingers to repeat the level goals."); UAP_AccessibilityManager.BlockInput(false); }