Ejemplo n.º 1
0
//	public void OnMouseDown()
//	{
//		if (GameManager.Instance.CurrentMenu != UISetType.ClassicGame && GameManager.Instance.CurrentMenu != UISetType.LeveledGame)
//		{
//			return;
//		}
//		if (Pipe == null || GameManager.Instance.BoardData.GameState != EGameState.Play || GameManager.Instance.BoardData.DragSlot != null)
//		{
//			// can't drag
//			return;
//		}
//
//		if (GameManager.Instance.GameFlow.IsSomeWindow())
//		{
//			//			if (GameManager.Instance.GameFlow.GetCurrentActiveWindowId() == UIConsts.FORM_ID.TUTOR_WINDOW)
//			//			{
//			//				GameManager.Instance.HideTutorial("");
//			//			} else
//			{
//				return;
//			}
//		}
//
//		GameBoard board = GameManager.Instance.BoardData.AGameBoard;
//		if (board.BreakePowerup)
//		{
//			board.OnBreakePowerupUsed(this);
//			return;
//		} else
//		if (board.ChainPowerup)
//		{
//			board.OnChainPowerupUsed(this);
//			return;
//		} else
//		if (board.DestroyColorPowerup)
//		{
//			board.OnDestroyColorPowerupUsed(this);
//			return;
//		}
//
//		if (!IsMovable() || !Pipe.IsMovable())
//		{
//			// can't drag - pipe or slot is immovable
//			return;
//		} else
//		{
//			// mark as slot that we drag now
//			GameManager.Instance.BoardData.DragSlot = this;
//			if (Application.isEditor)
//			{
//				MouseDownPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//			}
//			else
//			{
//				#if UNITY_ANDROID || UNITY_IOS
//				if (Input.touchCount > 0)
//				{
//					Touch touch = Input.GetTouch(Input.touchCount - 1);
//					MouseDownPos = Camera.main.ScreenToWorldPoint(touch.position);
//					TouchId = touch.fingerId;
//				}
//				#else
//				MouseDownPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//				#endif
//			}
//			GameManager.Instance.BoardData.AGameBoard.ShowSelection(transform.position);
//		}
//	}
//
//	public void OnMouseUp()
//	{
//		if (GameManager.Instance.CurrentMenu != UISetType.ClassicGame && GameManager.Instance.CurrentMenu != UISetType.LeveledGame)
//		{
//			return;
//		}
//		if (GameManager.Instance.BoardData.DragSlot == this)
//		{
//			GameManager.Instance.BoardData.AGameBoard.HideSelection();
//			GameManager.Instance.BoardData.DragSlot = null;
//
//			Vector2 endPos = Vector2.zero;
//			if (Application.isEditor)
//			{
//				endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//			}
//			else
//			{
//				#if UNITY_ANDROID || UNITY_IOS
//				foreach (Touch touch in Input.touches)
//				{
//					if (touch.fingerId == TouchId)
//					{
//						endPos = Camera.main.ScreenToWorldPoint(touch.position);
//						break;
//					}
//				}
//				#else
//				endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//				#endif
//			}
//			// check if enough distance to slide and find direction
//			float dx = endPos.x - MouseDownPos.x;
//			float dy = endPos.y - MouseDownPos.y;
//			float absDx = Mathf.Abs(dx);
//			float absDy = Mathf.Abs(dy);
//			if (Mathf.Max(absDx, absDy) < Consts.IMPULSE_DISTANCE)
//			{
//				// impulse too short (cancelled impulse)
//
//			} else
//			{
//				if (absDx > absDy)
//				{
//					// try horizontal impulse
//					if (dx > 0)
//					{
//						// impulse to right
//						GameManager.Instance.BoardData.AGameBoard.SlidePipe(this, 1, 0);
//					} else
//					{
//						// impulse to left
//						GameManager.Instance.BoardData.AGameBoard.SlidePipe(this, -1, 0);
//					}
//				} else
//				{
//					// try vertical impulse
//					if (dy > 0)
//					{
//						// impulse to top
//						GameManager.Instance.BoardData.AGameBoard.SlidePipe(this, 0, 1);
//					} else
//					{
//						// impulse to bottom
//						GameManager.Instance.BoardData.AGameBoard.SlidePipe(this, 0, -1);
//					}
//				}
//			}
//		}
//	}

    // INPUT USING POSITIONS

    public void OnMouseDownByPosition(Vector2 pos)
    {
        GameBoard board = GameManager.Instance.BoardData.AGameBoard;

        if (board.BreakePowerup)
        {
            board.OnBreakePowerupUsed(this);
            return;
        }
        else
        if (board.ChainPowerup)
        {
            board.OnChainPowerupUsed(this);
            return;
        }
        else
        if (board.DestroyColorPowerup)
        {
            board.OnDestroyColorPowerupUsed(this);
            return;
        }

        if (!IsMovable() || !Pipe.IsMovable())
        {
            // can't drag - pipe or slot is immovable
            return;
        }
        else
        {
            // mark as slot that we drag now
            GameManager.Instance.BoardData.DragSlot = this;
            MouseDownPos = pos;
            GameManager.Instance.BoardData.AGameBoard.ShowSelection(transform.position);
        }
    }
Ejemplo n.º 2
0
//	public void OnMouseDown()
//	{
//		if (GameManager.Instance.CurrentMenu != UISetType.ClassicGame && GameManager.Instance.CurrentMenu != UISetType.LeveledGame)
//		{
//			return;
//		}
//		if (Pipe == null || GameManager.Instance.BoardData.GameState != EGameState.Play || GameManager.Instance.BoardData.DragSlot != null)
//		{
//			// can't drag
//			return;
//		}
//
//		if (GameManager.Instance.GameFlow.IsSomeWindow())
//		{
//			//			if (GameManager.Instance.GameFlow.GetCurrentActiveWindowId() == UIConsts.FORM_ID.TUTOR_WINDOW)
//			//			{
//			//				GameManager.Instance.HideTutorial("");
//			//			} else
//			{
//				return;
//			}
//		}
//
//		GameBoard board = GameManager.Instance.Game;
//		if (board.BreakePowerup)
//		{
//			board.OnBreakePowerupUsed(this);
//			return;
//		} else
//		if (board.ChainPowerup)
//		{
//			board.OnChainPowerupUsed(this);
//			return;
//		} else
//		if (board.DestroyColorPowerup)
//		{
//			board.OnDestroyColorPowerupUsed(this);
//			return;
//		}
//
//		if (!IsMovable() || !Pipe.IsMovable())
//		{
//			// can't drag - pipe or slot is immovable
//			return;
//		} else
//		{
//			// mark as slot that we drag now
//			GameManager.Instance.BoardData.DragSlot = this;
//			if (Application.isEditor)
//			{
//				MouseDownPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//			}
//			else
//			{
//				#if UNITY_ANDROID || UNITY_IOS
//				if (Input.touchCount > 0)
//				{
//					Touch touch = Input.GetTouch(Input.touchCount - 1);
//					MouseDownPos = Camera.main.ScreenToWorldPoint(touch.position);
//					TouchId = touch.fingerId;
//				}
//				#else
//				MouseDownPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//				#endif
//			}
//			GameManager.Instance.Game.ShowSelection(transform.position);
//		}
//	}
//
//	public void OnMouseUp()
//	{
//		if (GameManager.Instance.CurrentMenu != UISetType.ClassicGame && GameManager.Instance.CurrentMenu != UISetType.LeveledGame)
//		{
//			return;
//		}
//		if (GameManager.Instance.BoardData.DragSlot == this)
//		{
//			GameManager.Instance.Game.HideSelection();
//			GameManager.Instance.BoardData.DragSlot = null;
//
//			Vector2 endPos = Vector2.zero;
//			if (Application.isEditor)
//			{
//				endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//			}
//			else
//			{
//				#if UNITY_ANDROID || UNITY_IOS
//				foreach (Touch touch in Input.touches)
//				{
//					if (touch.fingerId == TouchId)
//					{
//						endPos = Camera.main.ScreenToWorldPoint(touch.position);
//						break;
//					}
//				}
//				#else
//				endPos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
//				#endif
//			}
//			// check if enough distance to slide and find direction
//			float dx = endPos.x - MouseDownPos.x;
//			float dy = endPos.y - MouseDownPos.y;
//			float absDx = Mathf.Abs(dx);
//			float absDy = Mathf.Abs(dy);
//			if (Mathf.Max(absDx, absDy) < Consts.IMPULSE_DISTANCE)
//			{
//				// impulse too short (cancelled impulse)
//
//			} else
//			{
//				if (absDx > absDy)
//				{
//					// try horizontal impulse
//					if (dx > 0)
//					{
//						// impulse to right
//						GameManager.Instance.Game.SlidePipe(this, 1, 0);
//					} else
//					{
//						// impulse to left
//						GameManager.Instance.Game.SlidePipe(this, -1, 0);
//					}
//				} else
//				{
//					// try vertical impulse
//					if (dy > 0)
//					{
//						// impulse to top
//						GameManager.Instance.Game.SlidePipe(this, 0, 1);
//					} else
//					{
//						// impulse to bottom
//						GameManager.Instance.Game.SlidePipe(this, 0, -1);
//					}
//				}
//			}
//		}
//	}

    // INPUT USING POSITIONS

    public void OnMouseDownByPosition(Vector2 pos)
    {
        bool canSelect = true;

        _justClick = !IsMovable() || !Pipe.IsMovable();
        if (Pipe.IsCharacter())
        {
            if (Pipe.GetComponent <Pipe_Character>().IsDead())
            {
                canSelect = false;
            }
        }
        else
        {
            if (_justClick)
            {
                // can't drag - pipe or slot is immovable
                canSelect = false;
            }
        }

        if (!canSelect)
        {
            return;
        }
        else
        {
            // mark as slot that we drag now
            GameManager.Instance.Game.DragSlot = this;
            MouseDownPos = pos;
            GameManager.Instance.Game.ShowSelection(transform.position);
        }
    }