/// <summary> /// Create new OverlayObject 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 StaticBlockerObject Create(GridCell parent, StaticBlockerData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent) { if (!parent || oData == null) { return(null); } GameObject gO = null; SpriteRenderer sR = null; StaticBlockerObject gridObject = null; sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); gO = sR.gameObject; gridObject = gO.GetOrAddComponent <StaticBlockerObject>(); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } #if UNITY_EDITOR gO.name = "static blocker " + parent.ToString(); #endif gridObject.SetData(oData); gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; return(gridObject); }
/// <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 FallingObject Create(GridCell parent, FallingObjectData 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; FallingObject gridObject = gO.AddComponent <FallingObject>(); 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.MainToFront); } gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; gridObject.SetData(oData); return(gridObject); }
public void Create(MatchGroup m, Action completeCallBack) { float delay = 0; ParallelTween collectTween = new ParallelTween(); MSound.SoundPlayMakeBomb(0.05f, null); foreach (GridCell c in m.Cells) // move and collect { Creator.CreateSprite(c.Match.transform, glow, c.Match.transform.position, SortingOrder.BombCreator - 1); collectTween.Add((callBack) => { c.MoveMatchAndCollect(m.lastMatchedCell, delay, false, false, true, false, callBack); }); } collectTween.Start(() => { SetBomb(m); completeCallBack?.Invoke(); }); }
/// <summary> /// Create new MainObject not initialized /// </summary> /// <param name="parent"></param> /// <param name="mData"></param> /// <param name="addCollider"></param> /// <param name="radius"></param> /// <param name="isTrigger"></param> /// <returns></returns> public static MatchObject Create(MatchObjectData mData, Vector3 position, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent, Action ScoreCollectEvent) { if (mData == null) { return(null); } SpriteRenderer sR = Creator.CreateSprite(MatchBoard.Instance.transform, mData.ObjectImage, position, SortingOrder.Main); GameObject gO = sR.gameObject; MatchObject gridObject = gO.AddComponent <MatchObject>(); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; gridObject.ScoreCollectEvent = ScoreCollectEvent; gridObject.SetData(mData); return(gridObject); }
/// <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 MatchObject Create(GridCell parent, MatchObjectData oData, bool addCollider, bool isTrigger, Action <int> TargetCollectEvent, Action ScoreCollectEvent) { if (!parent || oData == null) { return(null); } SpriteRenderer sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); GameObject gO = sR.gameObject; MatchObject gridObject = gO.AddComponent <MatchObject>(); // gObject.Init(parent.Row, parent.Column); if (addCollider) { BoxCollider2D cC = gridObject.gameObject.GetOrAddComponent <BoxCollider2D>(); cC.isTrigger = isTrigger; } gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; gridObject.ScoreCollectEvent = ScoreCollectEvent; gridObject.SetData(oData); return(gridObject); }
/// <summary> /// Create new OverlayObject 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 OverlayObject Create(GridCell parent, OverlayObjectData oData, Action <int> TargetCollectEvent) { if (!parent || oData == null) { return(null); } GameObject gO = null; SpriteRenderer sR = null; OverlayObject gridObject = null; sR = Creator.CreateSprite(parent.transform, oData.ObjectImage, parent.transform.position); gO = sR.gameObject; gridObject = gO.GetOrAddComponent <OverlayObject>(); #if UNITY_EDITOR gO.name = "overlay " + parent.ToString(); #endif gridObject.SetData(oData); gridObject.SRenderer = sR; gridObject.TargetCollectEvent = TargetCollectEvent; return(gridObject); }
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; } }
public void CreateBorder() { if (Left && LeftBotCorner) { if (!Neighbors.Left || Neighbors.Left.IsDisabled) { SpriteRenderer srL = Creator.CreateSprite(transform, Left, new Vector3(LeftBotCorner.position.x, transform.position.y, transform.position.z), 1); srL.name = "Left border: " + ToString(); } } if (Right && RightBotCorner) { if (!Neighbors.Right || Neighbors.Right.IsDisabled) { SpriteRenderer srR = Creator.CreateSprite(transform, Right, new Vector3(RightBotCorner.position.x, transform.position.y, transform.position.z), 1); srR.name = "Right border: " + ToString(); } } if (Top && RightTopCorner) { if (!Neighbors.Top || Neighbors.Top.IsDisabled) { SpriteRenderer srT = Creator.CreateSprite(transform, Top, new Vector3(transform.position.x, RightTopCorner.position.y, transform.position.z), 1); srT.name = "Top border: " + ToString(); } } if (Bottom && RightBotCorner) { if (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled) { SpriteRenderer srB = Creator.CreateSprite(transform, Bottom, new Vector3(transform.position.x, RightBotCorner.position.y, transform.position.z), 1); srB.name = "Bottom border: " + ToString(); } } if (OutTopLeft && LeftTopCorner) { if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && (!Neighbors.Top || Neighbors.Top.IsDisabled)) { SpriteRenderer srTL = Creator.CreateSprite(transform, OutTopLeft, LeftTopCorner.position, 1); srTL.name = "OutTopLeft border: " + ToString(); } } if (OutBotLeft && LeftBotCorner) { if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled)) { SpriteRenderer sr = Creator.CreateSprite(transform, OutBotLeft, LeftBotCorner.position, 1); sr.name = "OutBotLeft border: " + ToString(); } } if (OutBotRight && RightBotCorner) { if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && (!Neighbors.Bottom || Neighbors.Bottom.IsDisabled)) { SpriteRenderer sr = Creator.CreateSprite(transform, OutBotRight, RightBotCorner.position, 1); sr.name = "OutBotLeft border: " + ToString(); } } if (OutTopRight && RightTopCorner) { if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && (!Neighbors.Top || Neighbors.Top.IsDisabled)) { SpriteRenderer sr = Creator.CreateSprite(transform, OutTopRight, RightTopCorner.position, 1); sr.name = "OutBotLeft border: " + ToString(); } } NeighBors n = new NeighBors(this, true); if (InTopLeft && LeftTopCorner) { if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && n.TopLeft && !n.TopLeft.IsDisabled) { SpriteRenderer sr = Creator.CreateSprite(transform, InTopLeft, LeftTopCorner.position, 2); sr.name = "InTopLeft border: " + ToString(); } } if (InBotLeft && LeftBotCorner) { if ((!Neighbors.Left || Neighbors.Left.IsDisabled) && n.BottomLeft && !n.BottomLeft.IsDisabled) { SpriteRenderer sr = Creator.CreateSprite(transform, InBotLeft, LeftBotCorner.position, 2); sr.name = "InBotLeft border: " + ToString(); } } if (InTopRight && RightTopCorner) { if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && n.TopRight && !n.TopRight.IsDisabled) { SpriteRenderer sr = Creator.CreateSprite(transform, InTopRight, RightTopCorner.position, 2); sr.name = "InTopRight border: " + ToString(); } } if (InBotRight && RightBotCorner) { if ((!Neighbors.Right || Neighbors.Right.IsDisabled) && n.BottomRight && !n.BottomRight.IsDisabled) { SpriteRenderer sr = Creator.CreateSprite(transform, InBotRight, RightBotCorner.position, 2); sr.name = "InBotRight border: " + ToString(); } } }