internal void NotifyMouseUp(MouseInteractable obj)
    {
        IsMouseDown = false;

        if (!IsMouseDragging)
        {
            if (TimeUtility.localTimeInMilisecond - MouseDownTime > mouseFocusThreshold)
            {
#if UNITY_EDITOR
                Debug.Log(LogUtility.MakeLogString("MouseInputManager", "Focus " + obj));
#endif
                onMouseFocus.Invoke(obj);
            }
            else
            {
#if UNITY_EDITOR
                Debug.Log(LogUtility.MakeLogString("MouseInputManager", "Click " + obj));
#endif
                onMouseClick.Invoke(obj);
            }
        }
        else
        {
#if UNITY_EDITOR
            Debug.Log(LogUtility.MakeLogString("MouseInputManager", "End dragging (started from " + obj + ")"));
#endif
            IsMouseDragging = false;
            onMouseDragEnd.Invoke(obj);
        }

        //onMouseUp.Invoke(obj);
    }
    internal void NotifyMouseDown(MouseInteractable obj)
    {
        IsMouseDown       = true;
        MouseDownTime     = TimeUtility.localTimeInMilisecond;
        MouseDownPosition = Input.mousePosition;

        //onMouseDown.Invoke(obj);
    }
Esempio n. 3
0
 /// <summary>
 /// An event listener for MouseInputManager.Singleton.onMouseDragEnd
 /// </summary>
 /// <param name="obj"> The object from which the player starts to drag </param>
 private void HandleMouseDragEnd(MouseInteractable obj)
 {
     switch (currentPlayerState)
     {
     case PlayerState.MovementPlanning:
         if (path.Count > 0 && (obj == this || obj.GetComponent <Tile>() == path.Start))
         {
             CurrentPlayerState = PlayerState.MovementConfirmation;
         }
         break;
     }
 }
    internal void NotifyMouseEnter(MouseInteractable obj)
    {
        if (!IsMouseDragging && IsMouseDown)
        {
#if UNITY_EDITOR
            Debug.Log(LogUtility.MakeLogString("MouseInputManager", "Start dragging"));
#endif
            IsMouseDragging = true;
        }

        CurrentMouseTarget = obj;

        onMouseEnter.Invoke(obj);
    }
    internal void NotifyMouseDrag(MouseInteractable obj)
    {
        if (!IsMouseDragging)
        {
            if (Vector3.Distance(Input.mousePosition, MouseDownPosition) > mouseDragThreshold)
            {
#if UNITY_EDITOR
                Debug.Log(LogUtility.MakeLogString("MouseInputManager", "Start dragging"));
#endif
                IsMouseDragging = true;
            }
        }
        else
        {
            onMouseDrag.Invoke(obj);
        }
    }
Esempio n. 6
0
    /// <summary>
    /// Handle casting from screen and telling the gameobject that an interaction has occured.
    /// </summary>
    /// <param name="actionId"></param>
    private void HandleMouseInput(int actionId)
    {
        RaycastHit hit;
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        if (Physics.Raycast(ray, out hit, MAX_MOUSE_RAYCAST_DISTANCE, m_MouseInteractionLayerMask))
        {
            if (hit.collider.gameObject != null)
            {
                MouseInteractable interactComp = hit.collider.gameObject.GetComponent <MouseInteractable>();

                if (interactComp != null)
                {
                    interactComp.OnMouseInteraction(actionId);
                }
            }
        }
    }
Esempio n. 7
0
    /// <summary>
    /// An event listener for MouseInputManager.Singleton.onMouseEnter
    /// </summary>
    /// <param name="obj"> The object at which the mouse is pointing at </param>
    private void HandleMouseTargetChange(MouseInteractable obj)
    {
        if (MouseInputManager.Singleton.IsMouseDragging)
        {
            switch (currentPlayerState)
            {
            case PlayerState.MovementPlanning:
                if (obj == this)
                {
                    if (path.Count == 1)
                    {
                        RemoveWayPoint();
                    }
                }
                else if (obj.GetComponent <Tile>())
                {
                    Tile tile = obj.GetComponent <Tile>();

                    if (path.Count > 0)
                    {
                        if (tile == path.Last.Previous.Value)
                        {
                            RemoveWayPoint();
                        }
                        else if (path.Count < Player.Ap && tile.IsHighlighted(Tile.HighlightColor.Blue) && GridManager.Instance.IsAdjacent(tile, path.Last.Value))
                        {
                            AddWayPoint(tile);
                        }
                    }
                    else if (path.Count < Player.Ap && tile.IsHighlighted(Tile.HighlightColor.Blue) && GridManager.Instance.IsAdjacent(tile, path.Start))
                    {
                        AddWayPoint(tile);
                    }
                }
                break;
            }
        }
    }
    private void HandleMouseDrag(MouseInteractable obj)
    {
        if (LevelManager.Instance.playerController.CurrentPlayerState == PlayerState.Idle)
        {
            Vector3 d = Input.mousePosition - MouseInputManager.Singleton.MouseDownPosition;

            if (d.magnitude > 0)
            {
                Vector3 mouseMovement = Camera.main.ScreenToViewportPoint(d);
                Vector3 move          = new Vector3(mouseMovement.x * dragSpeed * Time.deltaTime, 0, mouseMovement.y * dragSpeed * Time.deltaTime);

                transform.Translate(-move);

                if (CameraManager.Instance.Bounds)
                {
                    // if there is a bounds for camera movement
                    transform.position = new Vector3(
                        Mathf.Clamp(transform.position.x, CameraManager.Instance.minCameraPos.x, CameraManager.Instance.maxCanmeraPos.x),
                        transform.position.y,
                        Mathf.Clamp(transform.position.z, CameraManager.Instance.minCameraPos.z, CameraManager.Instance.maxCanmeraPos.z));
                }
            }
        }
    }
Esempio n. 9
0
    /// <summary>
    /// An event listener for MouseInputManager.Singleton.onMouseClick
    /// </summary>
    /// <param name="obj"> The clicked object </param>
    private void HandleMouseClick(MouseInteractable obj)
    {
        // handle click sound
        //AudioSource audioSource = gameObject.GetComponent<AudioSource>();

        switch (currentPlayerState)
        {
        case PlayerState.Idle:
            if (obj == this || (obj.GetComponent <Tile>() == GridManager.Instance.GetTile(Player.transform.position)))
            {
                CurrentPlayerState = PlayerState.MovementPlanning;
                SoundManager.Instance.TapTile();
                //audioSource.PlayOneShot(TapTile);
            }
            else if (obj.GetComponent <Enemy>())
            {
                GridManager.Instance.ToggleDetectionArea(obj.GetComponent <EnemyController>().UID);
                //audioSource.PlayOneShot(TapTile);
                SoundManager.Instance.TapTile();
            }
            else if (obj.GetComponent <UICard>())
            {
                //audioSource.PlayOneShot(TapCard);
                SoundManager.Instance.TapTile();
                CurrentPlayerState = PlayerState.CardBrowsing;
            }
            break;

        case PlayerState.MovementPlanning:
            SoundManager.Instance.TapTile();
            //audioSource.PlayOneShot(TapTile);
            if (obj == this)
            {
                CurrentPlayerState = PlayerState.Idle;
            }
            else if (obj.GetComponent <Enemy>())
            {
                GridManager.Instance.ToggleDetectionArea(obj.GetComponent <EnemyController>().UID);
            }
            else if (obj.GetComponent <Tile>())
            {
                Tile tile = obj.GetComponent <Tile>();

                if (tile == path.Start)
                {
                    CurrentPlayerState = PlayerState.Idle;
                }
                else
                {
                    Tile playerTile = GridManager.Instance.GetTile(Player.transform.position);

                    if (tile.IsHighlighted(Tile.HighlightColor.Blue))
                    {
                        Path = Navigation.FindPath(GridManager.Instance, playerTile, tile, Player.IsAccessibleTo);
                        CurrentPlayerState = PlayerState.MovementConfirmation;
                    }
                }
            }
            break;

        case PlayerState.CardBrowsing:
            if (obj.GetComponent <UICard>())
            {
                CardToUse = obj.GetComponent <UICard>().Card;
                //audioSource.PlayOneShot(TapCard);
                SoundManager.Instance.TapCard();
                CurrentPlayerState = PlayerState.CardUsagePlanning;
            }
            break;

        case PlayerState.CardUsagePlanning:
            if (obj == this)
            {
                targetTile = GridManager.Instance.GetTile(transform.position);

                if (targetTile.IsHighlighted(Tile.HighlightColor.Green))
                {
                    CurrentPlayerState = PlayerState.CardUsageConfirmation;
                }
                else
                {
                    targetTile = null;
                }
            }
            else if (obj.GetComponent <Enemy>())
            {
                targetTile = GridManager.Instance.GetTile(obj.transform.position);

                if (targetTile.IsHighlighted(Tile.HighlightColor.Green))
                {
                    CurrentPlayerState = PlayerState.CardUsageConfirmation;
                }
                else
                {
                    GridManager.Instance.ToggleDetectionArea(obj.GetComponent <EnemyController>().UID);
                    targetTile = null;
                }
            }
            else if (obj.GetComponent <Tile>())
            {
                targetTile = obj.GetComponent <Tile>();

                if (targetTile.IsHighlighted(Tile.HighlightColor.Green))
                {
                    CurrentPlayerState = PlayerState.CardUsageConfirmation;
                }
                else
                {
                    targetTile = null;
                }
            }
            break;
        }
    }
 public bool isContainedInWhiteList(MouseInteractable obj)
 {
     return(typeWhiteList.Contains(obj.Type));
 }