/// <summary> /// Called when the player has selected a word. The letterTiles list will contain all the GameTiles on the board that /// make up the word. This is where the animation of the tiles from the board to the grid happens. /// </summary> public void FoundWord(string word, List <LetterTile> letterTiles, Tween.OnTweenFinished onTweenFinished) { if (!allGridTiles.ContainsKey(word)) { Debug.LogErrorFormat("There is no word \"{0}\" on the WordGrid. Hidding the GameTiles.", word); // Just hide all the GameTiles and their letters for (int i = 0; i < letterTiles.Count; i++) { letterTiles[i].gameObject.SetActive(false); } return; } // Get the grid tiles for the word List <GridTile> gridTiles = allGridTiles[word]; // Loop through each of the LetterTiles and animate them to the location of the GridTile for (int i = 0; i < letterTiles.Count; i++) { gridTiles[i].displayed = true; RectTransform letterTileRectT = letterTiles[i].transform as RectTransform; RectTransform gridTileRectT = gridTiles[i].gridTileObject.transform as RectTransform; // This fixes an issue where if there was a saved hint letter shown, then when the word for the hint was found the letters would animate to the // corner of the screen. This is because when the game started up the letterTile was automatically placed in the spot of the word grid tile and // the grid tile was not positioned properly buy the layout components. if (gridTiles[i].letterTileObject != null) { gridTileRectT = gridTiles[i].letterTileObject.transform as RectTransform; } TransitionAnimateOver(letterTileRectT, gridTileRectT, (i == 0) ? onTweenFinished : null); } }
private void TransitionAnimateOver(RectTransform letterTileRectT, RectTransform wordTileRectT, Tween.OnTweenFinished onTweenFinished) { float duration = 400f; letterTileRectT.SetParent(animationContainer); float xScale = tileSize / letterTileRectT.rect.width; float yScale = tileSize / letterTileRectT.rect.height; Tween.ScaleX(letterTileRectT, Tween.TweenStyle.EaseOut, letterTileRectT.localScale.x, xScale, duration); Tween.ScaleY(letterTileRectT, Tween.TweenStyle.EaseOut, letterTileRectT.localScale.y, yScale, duration); Tween.PositionX(letterTileRectT, Tween.TweenStyle.EaseOut, letterTileRectT.position.x, wordTileRectT.position.x, duration); Tween.PositionY(letterTileRectT, Tween.TweenStyle.EaseOut, letterTileRectT.position.y, wordTileRectT.position.y, duration).SetFinishCallback(onTweenFinished); }