public void ScaleTo(Vector3 toSize, int scalingTime, MovingFinishedDelegate scalingCallback) { if (isScaling) { LogFile.Message("isScaling is true", true); //movingCallback(gameObject, false); //return; } var gims = GetComponent<GameItemMovingScript>(); if(gims.IsMoving) { gims.ChangeDirection(gims.CurrentDestination.Destination.x, gims.CurrentDestination.Destination.y, gims.CurrentDestination.Speed, scalingCallback, gims.CurrentDestination.ShowFrom, toSize); return; } var newScaling = new Scaling2D { ScaleToSize = toSize, Speed = (toSize - transform.localScale)/scalingTime, ScalesLeft = scalingTime }; if (scalingCallback != null) newScaling.ScalingCallback = scalingCallback; else { LogFile.Message("ScaleTo: No scalingCallback", true); } //LogFile.Message("Current localPosition: " + transform.localPosition.x + " " + transform.localPosition.y + "Deirection: " + direction.x + " " + direction.y + "Destination: " + destination.x + " " + destination.y + " " + movementOrientation); _scalings.Add(newScaling); isScaling = true; }
public void SetTransparency(float value, MovingFinishedDelegate callback) { if (value < 0 || value > 1 || Math.Abs(value - Transparency) < 0.001) return; if (value < _toTransparency) { _transparencyChanger = -0.1f; _transparencyChanging = true; _toTransparency = value; _transparencyChangerCallback = callback; } else if (value > _toTransparency) { _transparencyChanger = 0.1f; _transparencyChanging = true; _toTransparency = value; _transparencyChangerCallback = callback; } }
public override void RevertMovedItem(int col, int row, MovingFinishedDelegate callback = null) { if (Items[col][row] == null || Items[col][row] == DisabledItem) return; var item1 = Items[col][row] as GameObject; if (item1 == null) return; var item = item1.GetComponent<GameItemMovingScript>(); if (item.IsMoving) return; base.RevertMovedItem(col, row, callback); //return; //var toPoint = GetCellCoordinates(col, row); //var cdc = item.CurrentDestination; //item.ChangeDirection(toPoint.x, toPoint.y >= (item.transform.localPosition.y - GameItemSize) ? toPoint.y : item.transform.localPosition.y - GameItemSize, // cdc.Speed.y, // (mItem, result) => // item.MoveTo(toPoint.x, toPoint.y, cdc.Speed.y, cdc.MovingCallback, null, null, true)); //item.MoveTo(toPoint.x, toPoint.y >= (item.transform.localPosition.y - GameItemSize) ? toPoint.y : item.transform.localPosition.y - GameItemSize, // cdc.Speed.y, null, null, null, true); //item.MoveTo(toPoint.x, toPoint.y, cdc.Speed.y, cdc.MovingCallback); //item.CancelMoving(); }
public override bool GameItemsExchange(int x1, int y1, int x2, int y2, float speed, bool isReverse, MovingFinishedDelegate exchangeCallback = null) { var gobj = Items[x1][y1] as GameObject; if (gobj == null) return false; var gims = gobj.GetComponent<GameItemMovingScript>(); if (!gims.IsMoving) { var res = base.GameItemsExchange(x1, y1, x2, y2, speed, isReverse, exchangeCallback ?? ((go, r) => { if (CallbacksCount != 1 || isReverse) return; while (ClearChains() > 0) { RemoveAdditionalItems(); //TODO: ? } })); return res; } if (isReverse) return true; y2 = -1; //TODO: add check on localPositionCoordinates for (var i = FieldSize - 1; i >= 0; i--) { if (Items[x2][i] != DisabledItem) continue; y2 = i; break; } if (y2 < 0) return false; var item1 = Items[x1][y1] as GameObject; var item = item1.GetComponent<GameItemMovingScript>(); if (!item.IsMoving) return false; Items[x1][y1] = Items[x2][y2]; Items[x2][y2] = item1; var toPoint = GetCellCoordinates(x2, y2); var cdc = item.CurrentDestination; item.ChangeDirection(toPoint.x, item.transform.localPosition.y - GameItemSize / 5, /* cdc.Speed.y + 4*/ speed, (mItem, result) => item.MoveTo(toPoint.x, toPoint.y, cdc.Speed, cdc.MovingCallback, null, null, true)); CurrentDroppingItem = new Point{X = x2, Y = y2}; //item.ChangeDirection(toPoint.x, toPoint.y >= (item.transform.localPosition.y - GameItemSize / 5) ? toPoint.y : item.transform.localPosition.y - GameItemSize / 5, // /* cdc.Speed.y + 4*/ speed, // (mItem, result) => // item.MoveTo(toPoint.x, toPoint.y, cdc.Speed.y, cdc.MovingCallback, null, null, true)); //item.MoveTo(toPoint.x, // toPoint.y >= (item.transform.localPosition.y - GameItemSize/5) // ? toPoint.y // : item.transform.localPosition.y - GameItemSize/5, // speed, null, null, null, true); //item.MoveTo(toPoint.x, toPoint.y, cdc.Speed.y, cdc.MovingCallback); //item.CancelMoving(); return true; }
public override GameObject GenerateGameItem(int i, int j, IList<GameItemType> deniedTypes = null, Vector2? generateOn = null, bool isItemDirectionChangable = false, float? dropSpeed = null, MovingFinishedDelegate movingCallback = null, GameItemMovingType? movingType = null) { var newType = RandomObject.Next((int)(/*MaxType > (GameItemType)FieldSize ? MinType + 1 :*/ GameItemType._1), (int)MaxInitialElementType + 1); if (deniedTypes == null || deniedTypes.Count == 0) return GenerateGameItem((GameItemType)newType, i, j, generateOn, null, isItemDirectionChangable, dropSpeed, movingCallback, movingType); while (deniedTypes.Contains((GameItemType)newType)) newType = RandomObject.Next((int)GameItemType._1, (int)MaxInitialElementType + 1); return GenerateGameItem((GameItemType)newType, i, j, generateOn, null, isItemDirectionChangable, dropSpeed, movingCallback); }
public override bool GameItemsExchange(int x1, int y1, int x2, int y2, float speed, bool isReverse, MovingFinishedDelegate exchangeCallback = null) { if (!Game.isExtreme) { var gobj = Items[x1][y1] as GameObject; if (gobj != null && Items[x1][y1] != DisabledItem) { lastMoved = gobj.GetComponent<GameItem>().Type; } } return base.GameItemsExchange(x1, y1, x2, y2, speed, isReverse, exchangeCallback); }
public void MoveTo(float? x, float? y, float movingSpeed, MovingFinishedDelegate movingCallback = null, Vector2? showFrom = null, Vector3? scaleTo = null, bool changingDirection = false, Int32? isHighPriority = null, String moveSound = null) { if (GetComponent<GameItemScalingScript>().isScaling) return; if (IsMoving) { LogFile.Message("isMoving is true", true); //movingCallback(gameObject, false); //return; } var newMove = new Destination2D(); float Xdir = 0, Ydir = 0, curX = transform.localPosition.x, toX = curX, curY = transform.localPosition.y, toY =curY, curZ = transform.localPosition.z,toZ = curZ; newMove.MovementOrientation = LineOrientation.Both; var hasX = false; if (x.HasValue && Math.Abs(x.Value - transform.localPosition.x) > 0.01) { Xdir = curX > x.Value ? -1 : 1; toX = x.Value; newMove.MovementOrientation = LineOrientation.Horizontal; hasX = true; } if (y.HasValue && Math.Abs(y.Value - transform.localPosition.y) > 0.01) { Ydir = curY > y.Value ? -1 : 1; toY = y.Value; newMove.MovementOrientation = LineOrientation.Vertical; if (hasX) { var X2dir = x.Value - curX; var Y2dir = y.Value - curY; if (Math.Abs(X2dir) > Math.Abs(Y2dir)) Ydir = Y2dir / Math.Abs(X2dir); else Xdir = X2dir / Math.Abs(Y2dir); newMove.MovementOrientation = LineOrientation.Both; } //newMove.MovementOrientation = newMove.MovementOrientation == LineOrientation.Both ? LineOrientation.Vertical : LineOrientation.Both; } else if (!hasX) { if (movingCallback != null) movingCallback(gameObject, true); return; } newMove.Direction = new Vector2(Xdir, Ydir); newMove.Destination = new Vector3(toX, toY, toZ); newMove.StartPoint = new Vector3(curX, curY, curZ); newMove.Speed = movingSpeed; newMove.Movement = new Vector3(newMove.Speed * Xdir, newMove.Speed * Ydir, 0f); newMove.ShowFrom = showFrom.HasValue ? showFrom.Value : Vector2.zero; newMove.ScaleTo = scaleTo.HasValue ? scaleTo.Value : Vector3.zero; newMove.MoveSound = moveSound; if (movingCallback != null) newMove.MovingCallback = movingCallback; else { LogFile.Message("MoveTo: No movingCallback", true); } //LogFile.Message("Current localPosition: " + transform.localPosition.x + " " + transform.localPosition.y + "Deirection: " + direction.x + " " + direction.y + "Destination: " + destination.x + " " + destination.y + " " + movementOrientation); if (isHighPriority.HasValue && isHighPriority.Value >= 0 && isHighPriority.Value < _destinations.Count) _destinations.Insert(isHighPriority.Value, newMove); else _destinations.Add(newMove); LogFile.Message("new move added", true); _isDirectionChangable = changingDirection; //newMove.ChangingDirection = changingDirection; IsMoving = true; }
public void ChangeDirection(float? x, float? y, float movingSpeed, MovingFinishedDelegate movingCallback, Vector2? showFrom = null, Vector3? scaleTo = null) { if (!IsMoving || !_isDirectionChangable) return; IsMoving = false; if (!showFrom.HasValue) showFrom = CurrentDestination.ShowFrom; if (!scaleTo.HasValue) scaleTo = CurrentDestination.ScaleTo; _destinations.Clear(); MoveTo(x, y, movingSpeed, (gO, result) => { //TODO: FIX: Additional direction added to moving and speeddrop tap not working right ChangingDirection = false; if(CurrentDestination.MovingCallback != null) CurrentDestination.MovingCallback(gO, result); if (movingCallback != null) movingCallback(gO, result); }, showFrom, scaleTo, false, 1); CurrentDestination.ChangingDirection = true; ChangingDirection = true; }
public override GameObject GenerateGameItem(GameItemType itemType, int i, int j, Vector2? generateOn = null, Vector3? scaleTo = null, bool isItemDirectionChangable = false, float? dropSpeed = null, MovingFinishedDelegate movingCallback = null, GameItemMovingType? movingType = null) { return base.GenerateGameItem(itemType, i, j, generateOn, Game.isExtreme && itemType == GameItemType._ToMoveItem ? _match3ItemsScale : scaleTo, isItemDirectionChangable, dropSpeed, movingCallback, movingType); }
public virtual void RevertMovedItem(int col, int row, MovingFinishedDelegate callback = null) { var gobj = Items[col][row] as GameObject; if (gobj == null) return; var toCell = GetCellCoordinates(col, row); LogFile.Message("Revert item to place: " + toCell.x + " " + toCell.y, true); var gims = gobj.GetComponent<GameItemMovingScript>(); CallbacksCount++; gims.MoveTo(toCell.x, toCell.y, Game.StandartItemSpeed, (s, e) => { CallbacksCount--; if (callback != null) callback(s, e); }); }
public virtual bool GameItemsExchange(int x1, int y1, int x2, int y2, float speed, bool isReverse, MovingFinishedDelegate exchangeCallback = null) { var item1 = Items[x1][y1] as GameObject; var item2 = Items[x2][y2] as GameObject; if (Game.isExtreme) { if (item1 != null && Items[x1][y1] != DisabledItem) { lastMoved = item1.GetComponent<GameItem>().Type; } } GameMovesCount++; if (item2 == null) { RevertMovedItem(x1, y1); if (exchangeCallback != null) exchangeCallback(gameObject, false); return false; } if (!isReverse) { Items[x1][y1] = item2; Items[x2][y2] = item1; } var position1 = GetCellCoordinates(x1, y1); var position2 = GetCellCoordinates(x2, y2); LogFile.Message("Exchange items: " + position1.x + position1.y + " " + position2.x + " " + position2.y, true); if (item1 == null || item2 == null) return false; isExchanging = true; CallbacksCount++; CurrentExchangeItemsCount++; item1.GetComponent<GameItemMovingScript>() .MoveTo(position2.x, position2.y, Game.StandartItemSpeed, (item, result) => { CallbacksCount--; //if (!result) return; var currentItem = item as GameObject; if (currentItem != null && isReverse) { CallbacksCount++; currentItem.GetComponent<GameItemMovingScript>() .MoveTo(position1.x, position1.y, Game.StandartItemSpeed, (reverseItem, reverseResult) => { CallbacksCount--; CurrentExchangeItemsCount--; if (CurrentExchangeItemsCount == 0) isExchanging = false; if (exchangeCallback != null) exchangeCallback(gameObject, true); if (CallbacksCount == 0 && CallClearChainsAfterExchange) { CallClearChainsAfterExchange = false; ClearChains(); } }); return; } CurrentExchangeItemsCount--; if (CurrentExchangeItemsCount == 0) isExchanging = false; if (exchangeCallback != null) exchangeCallback(gameObject, true); if (CallbacksCount == 0) { CallClearChainsAfterExchange = false; ClearChains(); } }); CallbacksCount++; CurrentExchangeItemsCount++; item2.GetComponent<GameItemMovingScript>() .MoveTo(position1.x, position1.y, Game.StandartItemSpeed, (item, result) => { CallbacksCount--; //if (!result) return; var currentItem = item as GameObject; if (currentItem != null && isReverse) { CallbacksCount++; currentItem.GetComponent<GameItemMovingScript>() .MoveTo(position2.x, position2.y, Game.StandartItemSpeed, (reverseItem, reverseResult) => { CallbacksCount--; CurrentExchangeItemsCount--; if (CurrentExchangeItemsCount == 0) isExchanging = false; if (exchangeCallback != null) exchangeCallback(gameObject, true); if (CallbacksCount == 0 && CallClearChainsAfterExchange) { CallClearChainsAfterExchange = false; ClearChains(); } }); return; } CurrentExchangeItemsCount--; if (CurrentExchangeItemsCount == 0) isExchanging = false; if (exchangeCallback != null) exchangeCallback(gameObject, true); if (CallbacksCount == 0) { CallClearChainsAfterExchange = false; ClearChains(); } }); return true; }
public void RemoveGameItem(int i, int j, MovingFinishedDelegate removingCallback = null) { var o = Items[i][j] as GameObject; if (o == null) return; if (o.GetComponent<GameItem>().IsTouched) { GetComponent<DragItemScript>().CancelDragging((s, e) => RemoveGameItem(i, j)); return; } var giss = o.GetComponent<GameItemScalingScript>(); var toSize = 0.5f; CallbacksCount++; Items[i][j] = null; _isDropDone = false; giss.ScaleTo(new Vector3(toSize, toSize, 0), 8, (item, r) => { CallbacksCount--; DestroyGameItem((GameObject)item); if (removingCallback != null) removingCallback(item, r); }); }
public virtual GameObject GenerateGameItem(int i, int j, IList<GameItemType> deniedTypes = null, Vector2? generateOn = null, bool isItemDirectionChangable = false, float? dropSpeed = null, MovingFinishedDelegate movingCallback = null, GameItemMovingType? movingType = null) { int newType; var possibility = RandomObject.Next(1, 101); var minItem = (int)MinType + _minTypePlus;//(int)MaxType > FieldSize ? (int)MinType + 1 + _minTypePlus : (int)GameItemType._1; var isEven = (i + j) % 2; if (possibility <= 50) possibility = isEven == 0 ? 50 : 20; else if (possibility <= 70) possibility = isEven == 0 ? 20 : 50; switch (possibility) { case 50: newType = minItem; break; case 20: newType = RandomObject.Next(minItem + 2, (int)MaxInitialElementType + 1); break; default: newType = minItem + 1; break; } if (deniedTypes == null || deniedTypes.Count == 0) return GenerateGameItem((GameItemType)newType, i, j, generateOn, GameItemScale, isItemDirectionChangable, dropSpeed, movingCallback, movingType); while (deniedTypes.Contains((GameItemType)newType)) newType = RandomObject.Next((int)GameItemType._1, (int)MaxInitialElementType + 1); return GenerateGameItem((GameItemType)newType, i, j, generateOn, GameItemScale, isItemDirectionChangable, dropSpeed, movingCallback); }
public virtual GameObject GenerateGameItem(GameItemType itemType, int i, int j, Vector2? generateOn = null, Vector3? scaleTo = null, bool isItemDirectionChangable = false, float? dropSpeed = null, MovingFinishedDelegate movingCallback = null, GameItemMovingType? movingType = null) { if (!generateOn.HasValue) generateOn = new Vector2(0, FieldSize - j); if (InitialGameItem == null) InitialGameItem = InitialGameItemPosition; var cell = GetCellCoordinates(i, j); var gobj = InstantiateGameItem(itemType, new Vector3( (float)Math.Round(cell.x + generateOn.Value.x * GameItemSize, 2), InitialGameItem.Y + generateOn.Value.y * GameItemSize, InitialGameItem.Z), Vector3.zero, movingType); var c = gobj.GetComponent<GameItemMovingScript>(); LogFile.Message("GameItem generated to X:" + gobj.transform.localPosition.x + " Y:" + (gobj.transform.localPosition.y - 6 * GameItemSize), true); CallbacksCount++; //var toS = GameItemSize / ScaleMultiplyer; c.MoveTo(cell.x, cell.y, dropSpeed.HasValue ? dropSpeed.Value : 10 - i % 2 + j * 1.5f, (item, result) => { CallbacksCount--; if (movingCallback != null) movingCallback(item, result); else { //if (!result) return; if (CallbacksCount == 0) ClearChains(); else if (isExchanging && CallbacksCount == CurrentExchangeItemsCount) CallClearChainsAfterExchange = true; } }, new Vector2(InitialGameItem.X, InitialGameItem.Y + GameItemSize / 2), scaleTo != null ? scaleTo : Vector3.one/*new Vector3(toS, toS, 1f)*/, isItemDirectionChangable, null, Power2Sounds.Drop); return gobj; }
// Update is called once per frame void Update() { var touch = TouchActionAdapter.GetTouch(); if (touch.Count == 0) return; if (PauseButtonScript.PauseMenuActive) return; var pg = gameObject.GetComponent<IPlayground>(); if (pg == null || pg.IsGameOver || pg.IsMixing) return; Vector3 realTouchPosition; var touchPhase = TouchPhase.Canceled; if (_cancelDraggingCallback != null /*&& _ExchangingItems == 0*/) touchPhase = TouchPhase.Ended; else touchPhase = touch[0].Phase; realTouchPosition = gameObject.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(touch[0].OriginalPosition)); //if (Application.platform != RuntimePlatform.WindowsEditor) //{ // if (Input.touchCount == 0) return; // var touch = Input.GetTouch(0); // touchPhase = touch.phase; // realTouchPosition = gameObject.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(touch.position)); // //LogFile.Message("touch.position: " + touch.position.x + " " + touch.position.y); // //LogFile.Message("realTouchPosition: " + realTouchPosition.x + " " + realTouchPosition.y); //} //else //{ // if (Input.GetMouseButtonDown(0)) // { // touchPhase = TouchPhase.Began; // MouseActive = true; // //LogFile.Message("MouseButtonDown"); // } // else if (Input.GetMouseButtonUp(0)) // { // //if (Input.GetAxisRaw("Mouse X") == 0 && Input.GetAxisRaw("Mouse Y") == 0) // // touchPhase = TouchPhase.Stationary; // //else // touchPhase = TouchPhase.Ended; // MouseActive = false; // //LogFile.Message("MouseButtonUp"); // } // else if (Input.GetMouseButton(0)) // { // touchPhase = TouchPhase.Moved; // //LogFile.Message("MouseButton"); // } // if (!MouseActive && touchPhase != TouchPhase.Ended) return; // LogFile.Message("touchPhase = " + touchPhase); // realTouchPosition = gameObject.transform.InverseTransformPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition)); // //LogFile.Message("Input.mousePosition: " + Input.mousePosition.x + " " + Input.mousePosition.y); // //LogFile.Message("realTouchPosition: " + realTouchPosition.x + " " + realTouchPosition.y); //} // -- Drag ------------------------------------------------ switch (touchPhase) { case TouchPhase.Stationary: if (!(pg is ModeDropsPlayground)) return; var dropsPG = pg as ModeDropsPlayground; touchOriginalPosition = realTouchPosition; if (dropsPG.Items == null || dropsPG.Items[dropsPG.CurrentDroppingItem.X][dropsPG.CurrentDroppingItem.Y] == null || dropsPG.Items[dropsPG.CurrentDroppingItem.X][dropsPG.CurrentDroppingItem.Y] == dropsPG.DisabledItem) break; var tapItem = dropsPG.CurrentDroppingItem; var dropGO = (dropsPG.Items[tapItem.X][tapItem.Y] as GameObject); if (dropGO == null) break; var dropGIMS = dropGO.GetComponent<GameItemMovingScript>(); if (dropGIMS == null || !dropGIMS.IsMoving) break; dropGIMS.ChangeSpeed(dropGIMS.CurrentDestination.Speed + 16); touchDirection = null; #region old //touchOriginalPosition = realTouchPosition; //for (var col = 0; col < pg.Items.Length; col++) //{ // for (var row = 0; row < pg.Items[col].Length; row++) // { // if (pg.Items[col][row] == null && pg.Items[col][row] == pg.DisabledItem) continue; // var gobj = (pg.Items[col][row] as GameObject); // if (gobj == null) continue; // var gobjPosition = new Vector2(gobj.transform.localPosition.x, gobj.transform.localPosition.y); // var gobjCollider = gobj.GetComponent<BoxCollider2D>(); // var half = gobjCollider.size.x/2; // if ((!(realTouchPosition.x > gobjPosition.x - half)) || // (!(realTouchPosition.x < gobjPosition.x + half)) || // (!(realTouchPosition.y > gobjPosition.y - half)) || // (!(realTouchPosition.y < gobjPosition.y + half))) continue; // var gims = gobj.GetComponent<GameItemMovingScript>(); // if (gims == null || !gims.IsMoving) continue; // gims.ChangeSpeed(gims.CurrentDestination.Speed.x + 16); // touchDirection = null; // return; // } //} #endregion break; case TouchPhase.Began: touchOriginalPosition = realTouchPosition; var found = false; for (var col = 0; col < pg.Items.Length; col++) { if (!found) for (var row = 0; row < pg.Items[col].Length; row++) { if (pg.Items[col][row] == null || pg.Items[col][row] == pg.DisabledItem) continue; var gobj = (pg.Items[col][row] as GameObject); if (gobj == null) continue; //var gobjPosition = new Vector2(gobj.transform.localPosition.x, gobj.transform.localPosition.y); var half = gobj.GetComponent<BoxCollider2D>().size.x / 2; if ((!(realTouchPosition.x > gobj.transform.localPosition.x - half)) || (!(realTouchPosition.x < gobj.transform.localPosition.x + half)) || (!(realTouchPosition.y > gobj.transform.localPosition.y - half)) || (!(realTouchPosition.y < gobj.transform.localPosition.y + half))) continue; var gims = gobj.GetComponent<GameItemMovingScript>(); var giss = gobj.GetComponent<GameItemScalingScript>(); var gi = gobj.GetComponent<GameItem>(); if (gims == null || gi == null || (!gi.IsDraggableWhileMoving && gims.IsMoving) || giss.isScaling || gi.MovingType == GameItemMovingType.Static) continue; TouchedItem = new Point { X = col, Y = row }; touchedItemOriginalPosition = pg.GetCellCoordinates(col, row); touchedItemOriginalPosition.z = gobj.transform.localPosition.z; touchDirection = null; //Vibration.Vibrate(); DeviceButtonsHelpers.OnSoundAction(Power2Sounds.KeyPress, true); found = true; break; } else break; } if (TouchedItem != null) return; if (TouchedItem == null && pg is ModeDropsPlayground) { var movingItem = (pg as ModeDropsPlayground).CurrentDroppingItem; if (movingItem == null) break; var movingItemGameObject = pg.Items[movingItem.X][movingItem.Y] as GameObject; if ( movingItemGameObject == null || !(movingItemGameObject.GetComponent<GameItemMovingScript>() .CurrentDestination.Visible)) break; TouchedItem = movingItem; touchedItemOriginalPosition = pg.GetCellCoordinates(movingItem.X, movingItem.Y); } break; case TouchPhase.Moved: if (TouchedItem == null) break; var firstX = TouchedItem.X; var firstY = TouchedItem.Y; var gobj1 = pg.Items[firstX][firstY] as GameObject; if (gobj1 == null) return; var giObject = gobj1.GetComponent<GameItem>(); /* if (giObject != null && giObject.MovingType == GameItemMovingType.Static) return; var gobj1Gims = gobj1.GetComponent<GameItemMovingScript>(); if (gobj1Gims.CurrentDestination != null && gobj1Gims.CurrentDestination.ChangingDirection) { touchedItemOriginalPosition = new Vector3(gobj1.transform.localPosition.x, gobj1.transform.localPosition.y, gobj1.transform.localPosition.z); touchOriginalPosition = touchedItemOriginalPosition; return; }*/ var deltaX = Math.Abs(realTouchPosition.x - touchOriginalPosition.x); var deltaY = Math.Abs(realTouchPosition.y - touchOriginalPosition.y); //if (deltaX < 0.0000001 && deltaY < 0.0000001) touchDirection = null; float deltaXYZ = 0; switch (giObject.MovingType) { case GameItemMovingType.Standart: case GameItemMovingType.StandartChangable: case GameItemMovingType.StandartExchangable: if (touchDirection != null) { switch(touchDirection) { case MoveDirections.Right: case MoveDirections.Left: deltaXYZ = deltaX; break; case MoveDirections.Up: case MoveDirections.Down: deltaXYZ = deltaY; break; } break; } if (deltaX > deltaY && deltaX > pg.DeltaToMove) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = realTouchPosition.x > touchOriginalPosition.x ? MoveDirections.Right : MoveDirections.Left).Value)) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = realTouchPosition.y > touchOriginalPosition.y ? MoveDirections.Up : MoveDirections.Down).Value)) { /*var movingItemGameObject = pg.Items[TouchedItem.X][TouchedItem.Y] as GameObject; if (touchDirection == MoveDirections.Down && pg is ModeDropsPlayground && movingItemGameObject != null && movingItemGameObject.GetComponent<GameItemMovingScript>() .IsMoving)*/ touchDirection = null; return; } deltaXYZ = deltaY; break; } deltaXYZ = deltaX; } else if (deltaX < deltaY && deltaY > pg.DeltaToMove) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = realTouchPosition.y > touchOriginalPosition.y ? MoveDirections.Up : MoveDirections.Down).Value)) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = realTouchPosition.x > touchOriginalPosition.x ? MoveDirections.Right : MoveDirections.Left).Value)) { /*var movingItemGameObject = pg.Items[TouchedItem.X][TouchedItem.Y] as GameObject; if( touchDirection == MoveDirections.Down && pg is ModeDropsPlayground && movingItemGameObject != null && movingItemGameObject.GetComponent<GameItemMovingScript>() .IsMoving)*/ touchDirection = null; return; } deltaXYZ = deltaX; break; } deltaXYZ = deltaY; } break; case GameItemMovingType.Diagonal: deltaXYZ = deltaX > deltaY ? deltaX : deltaY; if (realTouchPosition.y > touchOriginalPosition.y) { if (realTouchPosition.x > touchOriginalPosition.x) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = MoveDirections.UL).Value)) return; } else { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = MoveDirections.UR).Value)) return; } } else { if (realTouchPosition.x > touchOriginalPosition.x) { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = MoveDirections.DL).Value)) return; } else { if ( !pg.IsItemMovingAvailable(TouchedItem.X, TouchedItem.Y, (touchDirection = MoveDirections.DR).Value)) return; } } break; case GameItemMovingType.Free: deltaXYZ = (float)Math.Sqrt(Math.Pow(deltaX, 2) + Math.Pow(deltaY, 2)); break; } if (!touchDirection.HasValue) return; /*var secondX = touchedItem.X + (int)pg.AvailableMoveDirections[touchDirection.Value].x; var secondY = touchedItem.Y - (int)pg.AvailableMoveDirections[touchDirection.Value].y; if (!pg.isDisabledItemActive && pg.Items[secondX][secondY] != pg.DisabledItem) { var gobjCHck = pg.Items[secondX][secondY] as GameObject; if (gobjCHck == null) return; var gims2 = gobjCHck.GetComponent<GameItemMovingScript>(); var gi = gobjCHck.GetComponent<GameItem>(); if (gims2 == null || gi == null || gims2.IsMoving) return; }*/ //LogFile.Message("dELTA: " + deltaXYZ + "D2E: " + pg.DeltaToExchange); if (deltaXYZ > pg.DeltaToExchange) { var secondX = TouchedItem.X + (int)pg.AvailableMoveDirections[touchDirection.Value].x; var secondY = TouchedItem.Y - (int)pg.AvailableMoveDirections[touchDirection.Value].y; //here we check touchDirection , select GameItem for exchange and call pg.GameItemsExchange(...) exchangeSpeedMultiple += 1.7f; LogFile.Message("From:" + firstX + " " + firstY, true); LogFile.Message("To:" + secondX + " " + secondY, true); var result = pg.TryMakeMove(firstX, firstY, secondX, secondY); LogFile.Message("Result:" + result, true); touchDirection = null; TouchedItem = null; /*if (gobj != null) { var gi = gobj.GetComponent<GameItem>(); gi.IsTouched = false; }*/ float speed = 10 * exchangeSpeedMultiple; //_ExchangingItems+=2; if (result) { if (!pg.GameItemsExchange(firstX, firstY, secondX, secondY, speed, false, (obj, e) => { //_ExchangingItems--; if (_cancelDraggingCallback != null && pg.CallbacksCount == 0) { var _cdc = _cancelDraggingCallback; _cancelDraggingCallback = null; _cdc(obj, true); } })) return; //DeviceButtonsHelpers.OnSoundAction(Power2Sounds.Line, false); //var o = pg.Items[secondX][secondY] as GameObject; //if (o != null) //{ // var cd = o.GetComponent<GameItemMovingScript>().CurrentDestination; // touchedItem = cd != null && o.GetComponent<GameItemMovingScript>().ChangingDirection//cd.ChangingDirection // ? new Point {X = secondX, Y = secondY} // : null; //} //else LogFile.Message("After exchange From:" + firstX + " " + firstY, true); LogFile.Message("After exchange To:" + secondX + " " + secondY, true); } else { pg.GameItemsExchange(firstX, firstY, secondX, secondY, speed, true, (obj, e) => { //_ExchangingItems--; if (_cancelDraggingCallback != null && pg.CallbacksCount == 0) { var _cdc = _cancelDraggingCallback; _cancelDraggingCallback = null; _cdc(obj, true); } }); DeviceButtonsHelpers.OnSoundAction(Power2Sounds.Fault, false); //var gi = gobj1.GetComponent<GameItem>(); } } else { exchangeSpeedMultiple = 0; var gims = gobj1.GetComponent<GameItemMovingScript>(); if (!gims.IsMoving) { switch (giObject.MovingType) { case GameItemMovingType.Standart: case GameItemMovingType.StandartChangable: case GameItemMovingType.Diagonal: gims.transform.localPosition = new Vector3(touchedItemOriginalPosition.x + pg.AvailableMoveDirections[touchDirection.Value].x * deltaXYZ, touchedItemOriginalPosition.y + pg.AvailableMoveDirections[touchDirection.Value].y * deltaXYZ, touchedItemOriginalPosition.z); break; case GameItemMovingType.Free: gims.transform.localPosition = new Vector3(realTouchPosition.x, realTouchPosition.y, touchedItemOriginalPosition.z); break; } } //var gi = gobj1.GetComponent<GameItem>(); //if (gi != null && gi.IsDraggableWhileMoving) // touchDirection = null; } break; case TouchPhase.Ended: exchangeSpeedMultiple = 0; if (TouchedItem != null) { if (pg.Items == null || pg.Items[TouchedItem.X][TouchedItem.Y] == null || pg.Items[TouchedItem.X][TouchedItem.Y] == pg.DisabledItem) { TouchedItem = null; return; }; var gobj = pg.Items[TouchedItem.X][TouchedItem.Y] as GameObject; if (gobj != null) { if (touchDirection == null) { var gims = gobj.GetComponent<GameItemMovingScript>(); if (gims.IsMoving) { TouchedItem = null; gims.ChangeSpeed(gims.CurrentDestination.Speed + 16); //gobj.GetComponent<GameItem>().IsTouched = false; return; } } //gobj.GetComponent<GameItem>().IsTouched = false; //var gi = gobj.GetComponent<GameItem>(); //if (gi != null && gi.IsDraggableWhileMoving) touchDirection = null; var _cdc = _cancelDraggingCallback; _cancelDraggingCallback = null; pg.RevertMovedItem(TouchedItem.X, TouchedItem.Y, _cdc); } //LogFile.Message("TouchPhase.Ended"); //if (Math.Abs(realTouchPosition.x - touchedItemOriginalPosition.x) > 0.000000000000000001 && // Math.Abs(realTouchPosition.y - touchedItemOriginalPosition.y) > 0.000000000000000001) TouchedItem = null; } break; } }
public void CancelDragging(MovingFinishedDelegate callback) { if (_cancelDraggingCallback != null) return; _cancelDraggingCallback = callback; }