private void SetBomb(MatchGroup m) { if (m == null) { return; } GridCell c = m.lastMatchedCell; DynamicClickBombObjectData b = null; switch (m.GetGroupType()) { case MatchGroupType.HorBomb: b = MatchSet.GetDynamicClickBombObject(BombDir.Horizontal, m.lastMatchedID); break; case MatchGroupType.VertBomb: b = MatchSet.GetDynamicClickBombObject(BombDir.Vertical, m.lastMatchedID); break; case MatchGroupType.Bomb: b = MatchSet.GetDynamicClickBombObject(BombDir.Radial, m.lastMatchedID); break; case MatchGroupType.ColorBomb: b = MatchSet.GetDynamicClickBombObject(BombDir.Color, m.lastMatchedID); break; } if (b == null) { return; } createPrefab = b.createAnimPrefab; c.SetDynamicClickBomb(b); Creator.InstantiateAnimPrefab(createPrefab, c.DynamicObject.transform, c.DynamicObject.transform.position, SortingOrder.BombCreator + 1, false, null); }
/// <summary> /// Create new MainObject for gridcell /// </summary> /// <param name="parent"></param> /// <param name="oData"></param> /// <param name="addCollider"></param> /// <param name="radius"></param> /// <param name="isTrigger"></param> /// <returns></returns> public static DynamicClickBombObject Create(GridCell parent, DynamicClickBombObjectData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent) { if (!parent || oData == null) { return(null); } SpriteRenderer sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); GameObject gO = sR.gameObject; DynamicClickBombObject gridObject = gO.AddComponent <DynamicClickBombObject>(); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } if (oData.iddleAnimPrefab) { Creator.InstantiatePrefab(oData.iddleAnimPrefab, gridObject.transform, gridObject.transform.position, 0, SortingOrder.Main + 2); } gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; gridObject.SetData(oData); return(gridObject); }
internal virtual void SetData(DynamicClickBombObjectData oData) { SRenderer = GetComponent <SpriteRenderer>(); if (SRenderer) { SRenderer.sprite = (oData != null) ? oData.ObjectImage : null; } OData = oData; #if UNITY_EDITOR gameObject.name = (oData != null && SRenderer.sprite) ? "DynamicClickBomb: " + GetID() + "(" + SRenderer.sprite.name + ")" : "none"; #endif SetToFront(false); }
internal void SetDynamicClickBomb(DynamicClickBombObjectData mObjectData) { if (mObjectData == null || IsDisabled || Blocked) { return; } // Debug.Log("set dynamic click bomb : " + mObjectData.ID); if (DynamicObject) { GameObject old = DynamicObject; DestroyImmediate(old); } if (StaticBlocker) { GameObject old = StaticBlocker.gameObject; DestroyImmediate(old); } DynamicClickBombObject.Create(this, mObjectData, false, true, MBoard.TargetCollectEventHandler); DynamicClickBomb.SetToFront(false); }
private DynamicClickBombObjectData sourceColorBombData; // need only for color bomb public void CombineAndExplode(GridCell gCell, DynamicClickBombObject bomb, Action completeCallBack) { if (!gCell || !bomb) { completeCallBack?.Invoke(); return; } NeighBors nG = gCell.Neighbors; BombDir bd1 = bomb.GetBombDir(); BombCombine bC = BombCombine.None; List <DynamicClickBombObject> nBs = GetNeighBombs(gCell); if (bomb.GetBombDir() == BombDir.Color) { sourceColorBombData = bomb.OData; } foreach (var item in nBs) // search color bomb { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Color) { if (sourceColorBombData == null) { sourceColorBombData = item.OData; } bC = GetCombineType(bd1, bd2); break; } } if (bC == BombCombine.None) // search radial bomb { foreach (var item in nBs) { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Radial) { bC = GetCombineType(bd1, bd2); break; } } } if (bC == BombCombine.None) // search hor or vert bomb { foreach (var item in nBs) { BombDir bd2 = item.GetBombDir(); if (bd2 == BombDir.Horizontal || bd2 == BombDir.Vertical) { bC = GetCombineType(bd1, bd2); break; } } } switch (bC) { case BombCombine.ColorBombAndColorBomb: // clean full board collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndColorBomb bigBomb = Instantiate(colorBombAndColorBombPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.BombAndBomb: // big bomb explode collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedBombAndBomb bigBomb = Instantiate(bombAndBombPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.RocketAndRocket: // 2 rows or 2 columns collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject, 0.2f); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedRocketAndRocket bigBomb = Instantiate(rocketAndRocketPrefab); bigBomb.transform.localScale = gCell.transform.lossyScale; bigBomb.transform.position = gCell.transform.position; bigBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.ColorBombAndBomb: // replace color match with bomb collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndBomb colorBombAndBomb = Instantiate(colorBombAndBombPrefab); colorBombAndBomb.transform.localScale = gCell.transform.lossyScale; colorBombAndBomb.transform.position = gCell.transform.position; colorBombAndBomb.OData = sourceColorBombData; colorBombAndBomb.ApplyToGrid(gCell, 0.2f, completeCallBack); colorBombAndBomb.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage; }); break; case BombCombine.BombAndRocket: // 3 rows and 3 columns collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedBombAndRocket bombAndRocket = Instantiate(bombAndRocketPrefab); bombAndRocket.transform.localScale = gCell.transform.lossyScale; bombAndRocket.transform.position = gCell.transform.position; bombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack); }); break; case BombCombine.ColorBombAndRocket: // replace color bomb with rockets collectTween = new ParallelTween(); nBs.Add(bomb); foreach (var item in nBs) { item.transform.parent = null; item.SetToFront(true); Creator.CreateSprite(item.transform, glow, item.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { item.MoveToBomb(gCell, 0, () => { Destroy(item.gameObject); callBack(); }); }); } collectTween.Start(() => { MSound.SoundPlayMakeBomb(0.05f, null); CombinedColorBombAndRocket colorBombAndRocket = Instantiate(colorBombAndRocketPrefab); colorBombAndRocket.transform.localScale = gCell.transform.lossyScale; colorBombAndRocket.transform.position = gCell.transform.position; colorBombAndRocket.OData = sourceColorBombData; colorBombAndRocket.ApplyToGrid(gCell, 0.2f, completeCallBack); colorBombAndRocket.GetComponent <SpriteRenderer>().sprite = sourceColorBombData.ObjectImage; }); break; case BombCombine.None: // simple explode gCell.ExplodeBomb(0.0f, true, true, bd1 == BombDir.Color, false, () => { completeCallBack?.Invoke(); }); break; default: completeCallBack?.Invoke(); break; } }
internal void SetObject(int ID) { IsDisabled = false; MatchObjectData mOD = GOSet.GetMainObject(ID); if (mOD != null) { SetMatchObject(mOD); return; } OverlayObjectData oOD = GOSet.GetOverlayObject(ID); if (oOD != null) { SetOverlay(oOD); return; } UnderlayObjectData uOD = GOSet.GetUnderlayObject(ID); if (uOD != null) { SetUnderlay(uOD); return; } DynamicClickBombObjectData cdOD = GOSet.GetDynamicClickBombObject(ID); if (cdOD != null) { SetDynamicClickBomb(cdOD); return; } if (ID == GOSet.FallingObject.ID) { SetFalling(GOSet.FallingObject); return; } BaseObjectData bOD = GOSet.GetObject(ID); if (bOD != null && GameObjectsSet.IsDisabledObject(bOD.ID)) { SetDisabledObject(bOD); return; } if (bOD != null && GameObjectsSet.IsBlockedObject(bOD.ID)) { SetBlockedObject(bOD); } DynamicBlockerData dbOD = GOSet.GetDynamicBlockerObject(ID); if (dbOD != null) { SetDynamicBlockerObject(dbOD); return; } StaticBlockerData sbOD = GOSet.GetStaticBlockerObject(ID); if (sbOD != null) { SetStaticBlockerObject(sbOD); return; } }