/// <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); }
//-------------------------------------- // 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(); }
/// <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 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); }
/// <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> /// 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> /// Ares the gem V os swappable. /// </summary> /// <returns><c>true</c>, if gem V os swappable was ared, <c>false</c> otherwise.</returns> /// <param name="gemVO1">Gem V o1.</param> /// <param name="gemVO2">Gem V o2.</param> public static bool AreGemVOsSwappable(GemVO gemVO1, GemVO gemVO2) { bool areGemVOsSwappable = false; // Are Neighbors? // off by exactly one in EITHER row OR column // // Use if/else-if to ease debugging of each axis indivisually // if (gemVO1.RowIndex == gemVO2.RowIndex && Mathf.Abs(gemVO1.ColumnIndex - gemVO2.ColumnIndex) == 1) { areGemVOsSwappable = true; } else if (gemVO1.ColumnIndex == gemVO2.ColumnIndex && Mathf.Abs(gemVO1.RowIndex - gemVO2.RowIndex) == 1) { areGemVOsSwappable = true; } return(areGemVOsSwappable); }
/// <summary> /// Gets the gem tween entry delay. /// </summary> public static float GetGemTweenEntryDelay(GemVO gemVO) { return((TripleMatchConstants.MAX_ROWS - gemVO.RowIndex) * 0.1f); }
/// <summary> /// Determines whether this instance is there A match containing either gem V the specified gemVO1 gemVO2. /// </summary> /// <returns><c>true</c> if this instance is there A match containing either gem V the specified gemVO1 gemVO2; otherwise, <c>false</c>.</returns> /// <param name="gemVO1">Gem V o1.</param> /// <param name="gemVO2">Gem V o2.</param> public bool IsThereAMatchContainingEitherGemVO(GemVO gemVO1, GemVO gemVO2) { return(_gridSystem.IsThereAMatchContainingEitherGridSpotVO(gemVO1, gemVO2)); }
/// <summary> /// Dos the instantly swap two gem V os. /// </summary> /// <param name="gemVO1">Gem V o1.</param> /// <param name="gemVO2">Gem V o2.</param> public void DoInstantlySwapTwoGemVOs(GemVO gemVO1, GemVO gemVO2) { _gridSystem.DoInstantlySwapTwoGridSpotVOs(gemVO1, gemVO2); }