/// <summary> /// _s the on selected gem VO changed. /// </summary> /// <param name="gemVO">Gem V.</param> private void _OnSelectedGemVOChanged (GemVO gemVO) { if (_gemViews != null) { foreach (GemViewComponent gemView in _gemViews) { // 1. DESELECT ALL GEMS gemView.SetIsHighlighted (false); } if (gemVO != null && _GetGemViewForGemVo(gemVO) != null) { // 2. SELECT EXACTLY ONE GEM _GetGemViewForGemVo(gemVO).SetIsHighlighted (true); } } }
/// <summary> /// _s the swap two gem V os. /// </summary> private void _AttemptSwapTwoGemVOs (GemVO gemVO1, GemVO gemVO2) { // SOUND FOR SWAP #1 if (AudioManager.IsInstantiated()) { CoroutineManager.Instance.WaitForSecondsToCall (_AudioManagerPlayGemSwap, TripleMatchConstants.DURATION_GEM_TWEEN_SWAP/2); } //SWAP THE DATA MODEL (INSTANT) _model.DoInstantlySwapTwoGemVOs (gemVO1, gemVO2); //SWAP THE VISUALS (OVER X SECONDS) _GetGemViewForGemVo (gemVO1).TweenToNewPositionSwap(0); _GetGemViewForGemVo (gemVO2).TweenToNewPositionSwap(0); //NO MATCH, THEN SWAP BACK if (!_model.IsThereAMatchContainingEitherGemVO(gemVO1, gemVO2)) { //local variables used for code-readability float delayToStartGemTween_float = TripleMatchConstants.DURATION_GEM_TWEEN_SWAP; float delayToStartGemSound_float = delayToStartGemTween_float * 1.5f; // SOUND FOR SWAP #2 if (AudioManager.IsInstantiated()) { CoroutineManager.Instance.WaitForSecondsToCall (_AudioManagerPlayGemSwap, delayToStartGemSound_float); } //SWAP THE DATA MODEL (INSTANT) _model.DoInstantlySwapTwoGemVOs (gemVO1, gemVO2); //SWAP THE VISUALS (OVER X SECONDS) _GetGemViewForGemVo (gemVO1).TweenToNewPositionSwap(delayToStartGemTween_float); _GetGemViewForGemVo (gemVO2).TweenToNewPositionSwap(delayToStartGemTween_float); } else { // CHECK FOR MATCHES after a cosmetic delay CoroutineManager.Instance.WaitForSecondsToCall (_controller.CheckForMatches, TripleMatchConstants.DURATION_GEM_TWEEN_SWAP); } }
/// <summary> /// _s the do create and add gem view. /// </summary> /// <param name="nextGemVO">Next gem V.</param> private void _DoCreateAndAddGemView (GemVO nextGemVO) { // CREATE AND REPARENT GameObject nextGemViewPrefab = Instantiate (Resources.Load (TripleMatchConstants.PATH_GEM_VIEW_PREFAB)) as GameObject; nextGemViewPrefab.transform.parent = _gemsParent.transform; // INITIALIZE WITH DATA VO GemViewComponent nextGemView = nextGemViewPrefab.GetComponent<GemViewComponent>(); // Vector3 spawnPointForGemsVector3 = new Vector3 ( TripleMatchConstants.COLUMN_SIZE * nextGemVO.ColumnIndex, 5, transform.localPosition.z ); // nextGemView.OnTweenToNewPositionEntryCompleted += _OnGemTweenToNewPositionEntryCompleted; nextGemView.OnClicked += _OnGemViewClicked; nextGemView.Initialize (nextGemVO, spawnPointForGemsVector3); _gemViews.Add (nextGemView); }
/// <summary> /// _s the get gem view for gem vo. /// </summary> private GemViewComponent _GetGemViewForGemVo (GemVO gemVO) { GemViewComponent gemViewFound = null; if (_gemViews != null) { foreach (GemViewComponent gemView in _gemViews) { if (gemView.GemVO == gemVO) { gemViewFound = gemView; } } } return gemViewFound; }
//-------------------------------------- // Methods //-------------------------------------- // PUBLIC // PRIVATE /// <summary> /// _renders the title text. /// </summary> private void _DoLayoutGems (GemVO[,] gemVOs) { // CLEAR OUT GEMS if (_gemViews != null) { foreach (GemViewComponent gemView in _gemViews) { _DoDestroyAndRemoveGemView (gemView); } } _gemViews = new List<GemViewComponent>(); // GemVO nextGemVO; for (int rowIndex_int = 0; rowIndex_int < gemVOs.GetLength(0); rowIndex_int += 1) { for (int columnIndex_int = 0; columnIndex_int < gemVOs.GetLength(1); columnIndex_int += 1) { nextGemVO = gemVOs[rowIndex_int,columnIndex_int]; _DoCreateAndAddGemView (nextGemVO); } } }
/// <summary> /// Gets the gem color by gem V. Since our list of gems is finite and permanent, manually listing the colors is fast/fun. /// /// Option: Alternative, Pass GemViewComponent instance instead and take a sample of its pixel colors dynamically. /// /// </summary> /// <returns>The gem color by gem V.</returns> /// <param name="_gemVO">_gem V.</param> public static Color GetGemColorByGemVO (GemVO _gemVO) { Color colorByGemVO = new Color(0,0,0); //create non-null default if (_gemVO != null) { switch (_gemVO.GemTypeIndex) { case 0: // blue colorByGemVO = Color.blue; break; case 1: // green colorByGemVO = Color.green; break; case 2: // purple colorByGemVO = Color.magenta; break; case 3: // red colorByGemVO = Color.red; break; case 4: // yellow colorByGemVO = Color.yellow; break; default: #pragma warning disable 0162 throw new SwitchStatementException (); break; #pragma warning restore 0162 } } return colorByGemVO; }
/// <summary> /// Gets the gem tween entry delay. /// </summary> public static float GetGemTweenEntryDelay (GemVO gemVO) { return (TripleMatchConstants.MAX_ROWS - gemVO.RowIndex) * 0.1f; }
//-------------------------------------- // Constructor / Creation //-------------------------------------- /// <summary> /// Initialize the specified gemVO and initialLocalPositionVector3. /// </summary> /// <param name="gemVO">Gem V.</param> /// <param name="initialLocalPositionVector3">Initial local position vector3.</param> public void Initialize (GemVO gemVO, Vector3 initialLocalPositionVector3) { _gemVO = gemVO; // _gemSpriteRenderer.sprite = _sprites[_gemVO.GemTypeIndex]; // transform.localPosition = initialLocalPositionVector3; TweenToNewPositionEntry(); }