void LateUpdate()
    {
        //Drag detection (Horizontal motion)
        dragPhase = DetectDragPhase();
        switch (dragPhase)
        {
        case InputPhase.Began:
            break;

        case InputPhase.Moved:
            DragCamera();
            break;

        case InputPhase.Decelerating:
            DecelerateDrag();
            break;

        default: break;
        }

        //Zoom detection (Vertical motion)
        zoomPhase = DetectZoomPhase();
        switch (zoomPhase)
        {
        case InputPhase.Began:
        case InputPhase.Moved:
            ZoomCamera();
            break;

        case InputPhase.Decelerating:
            break;

        default: break;
        }
    }
    /// <summary>
    /// Switches between the moving and playing input phase
    /// </summary>
    public void ToggleInputPhase()
    {
        //If the game is in the placing phase
        if (inputPhase == InputPhase.Placing)
        {
            //Don't do anything
            return;
        }

        //If the game is in the playing phase
        if (inputPhase == InputPhase.Playing)
        {
            //Changes the phase
            inputPhase = InputPhase.Moving;
            //Changes the icon on the button
            UIManager.Instance.moveBoardButtonImage.sprite = UIManager.Instance.secondaryMoveBoardSprite;
            //Enables the rotationslider
            UIManager.Instance.rotationSlider.gameObject.SetActive(true);
            //Hides the tracked planes
            showTrackedPlanes = true;
        }
        //If the game is in the moving phase
        else
        {
            //Changes the phase
            inputPhase = InputPhase.Playing;
            //Changes the icon on the button
            UIManager.Instance.moveBoardButtonImage.sprite = UIManager.Instance.primaryMoveBoardSprite;
            //Disables the rotationslider
            UIManager.Instance.rotationSlider.gameObject.SetActive(false);
            //Shows the tracked planes
            showTrackedPlanes = false;
        }
    }
Example #3
0
    void TouchInput()
    {
        InputPhase    inputPhase    = GetInputPhase();
        MoveDirection moveDirection = MoveDirection.Idle;

        if (inputPhase.isValid)
        {
            if (inputPhase.phase == TouchPhase.Began)
            {
                this.beginPosition = inputPhase.position;
            }
            else if (inputPhase.phase == TouchPhase.Ended)
            {
                this.endPosition = inputPhase.position;
                Vector2 deltaDir = this.endPosition - this.beginPosition;
                if (deltaDir.sqrMagnitude > this.MinTouchMoveDis)
                {
                    if (Mathf.Abs(deltaDir.x) > Mathf.Abs(deltaDir.y))
                    {
                        moveDirection = deltaDir.x > 0 ? MoveDirection.Right : MoveDirection.Left;
                    }
                    if (Mathf.Abs(deltaDir.y) > Mathf.Abs(deltaDir.x))
                    {
                        moveDirection = deltaDir.y > 0 ? MoveDirection.Up : MoveDirection.Down;
                    }
                }
                if (moveDirection != MoveDirection.Idle)
                {
                    this.gameManager.Move(moveDirection);
                }
            }
        }
    }
Example #4
0
 public void iwantMove()
 {
     MenuButtonPressed(0);
     update     = true;
     inputPhase = InputPhase.Move;
     GridManager.instance.DisplayRelativeRangeAndPath(entityOnTurn, RangeType.Any);
 }
Example #5
0
        public void Execute()
        {
            var methods  = new InputPhase(BaseDirectory, Configuration.InputConfig).Execute().ToList();
            var mappings = new MapPhase(methods, Configuration.MapConfig).Execute().ToList();

            new GeneratePhase(mappings, Configuration.GenerateConfig).Execute();
        }
Example #6
0
 public void iwantNothing()
 {
     MenuButtonPressed(0);
     update            = true;
     inputPhase        = InputPhase.Looking;
     entityOnTurn.path = null;
     GridManager.instance.ResetGridColor();
 }
 public override bool CanUse(InputPhase phase)
 {
     return
         (phase == InputPhase.down &&
          IsUsing == false &&
          onCooldown == false &&
          characterComponents.characterSheet.HasResources(cost));
 }
Example #8
0
    private static KeyEvent CreateKeyEvent(InputPhase phase, KeyCode key)
    {
        KeyEvent newEvent = new KeyEvent();

        newEvent.phase = phase;
        newEvent.key   = key;

        return(newEvent);
    }
Example #9
0
    private static ButtonEvent CreateButtonEvent(InputPhase phase, string name)
    {
        ButtonEvent newEvent = new ButtonEvent
        {
            Phase = phase,
            Name  = name
        };


        return(newEvent);
    }
Example #10
0
    public override void Use(InputPhase phase)
    {
        characterComponents.characterSheet.IncreaseResources(-cost);
        characterComponents.animator.SetTrigger(AnimationConstants.EnumToID(parryTrigger));
        IsUsing = true;

        if (routine != null)
        {
            StopCoroutine(routine);
        }
        routine = StartCoroutine(ParryRoutine());
    }
Example #11
0
        private void Update()
        {
            if (currentEventSystem.IsPointerOverGameObject())
            {
                return;
            }

            if (Input.GetMouseButtonDown(0))
            {
                InputPhase = InputPhase.Began;
                var mouseInGameLocation = _camera.ScreenToWorldPoint(Input.mousePosition);
                var clickedOnObject     = DetectObject(mouseInGameLocation);

                if ((Time.time - _timeOfLastClick) < _maxDelayForDoubleClick)
                {
                    MessageBus.Publish(_userInputDoubleClickMessage
                                       .WithLcoation(mouseInGameLocation)
                                       .WithTransform(clickedOnObject));
                }
                else
                {
                    MessageBus.Publish(_userInputBeganMessage
                                       .WithLcoation(mouseInGameLocation)
                                       .WithTransform(clickedOnObject));
                }

                _timeOfLastHeldUpdate = _timeOfLastClick = Time.time;
            }
            else if (Input.GetMouseButton(0))
            {
                InputPhase = InputPhase.Stationary;

                if ((Time.time - _timeOfLastHeldUpdate) < _inputHeldUpdateInterval)
                {
                    return;
                }
                var mouseInGameLocation = _camera.ScreenToWorldPoint(Input.mousePosition);
                var clickedOnObject     = DetectObject(mouseInGameLocation);

                var inputHeldTime = Time.time - _timeOfLastClick;
                MessageBus.Publish(_userInputHeldMessage
                                   .WithLcoation(mouseInGameLocation)
                                   .WithTransform(clickedOnObject)
                                   .WithHeldTime(inputHeldTime));

                _timeOfLastHeldUpdate = Time.time;
            }
            else if (Input.GetMouseButtonUp(0))
            {
                InputPhase = InputPhase.Ended;
            }
        }
    void LateUpdate()
    {
        ////Tilt detection (Vertical motion) (Only on mobile)
        //tiltPhase = DetectTiltPhase();
        //switch (tiltPhase)
        //{
        //    case InputPhase.Began:
        //    case InputPhase.Moved:
        //        TiltCamera();
        //        break;
        //    case InputPhase.Decelerating:
        //        DecelerateTilt();
        //        break;
        //    default: break;
        //}

        //Drag detection (Horizontal motion)
        dragPhase = DetectDragPhase();
        switch (dragPhase)
        {
        case InputPhase.Began:
            break;

        case InputPhase.Moved:
            DragCamera();
            break;

        case InputPhase.Decelerating:
            DecelerateDrag();
            break;

        default: break;
        }

        //Pinch detection (Vertical motion)
        zoomPhase = DetectZoomPhase();
        switch (zoomPhase)
        {
        case InputPhase.Began:
            break;

        case InputPhase.Moved:
            ZoomCamera();
            break;

        case InputPhase.Decelerating:
            DecelerateZoom();
            break;

        default: break;
        }
    }
Example #13
0
    private void TriggerAbility(int index, InputPhase phase, out bool isProblem)
    {
        if (IsStaggered || currentAbilities[index] == null)
        {
            isProblem = true;
            return;
        }

        bool checkedCanUse = false;

        if (lastAbility != currentAbilities[index])
        {
            if (phase == InputPhase.hold)
            {
                if (HasLastAbilityEnded() == false)
                {
                    isProblem = true;
                    return;
                }
            }
            else
            {
                if (currentAbilities[index].CanUse(phase))
                {
                    TryStopLastAbility(out isProblem);
                    if (isProblem)
                    {
                        return;
                    }
                }
                else
                {
                    isProblem = true;
                    return;
                }
                checkedCanUse = true;
            }
        }

        if (checkedCanUse || currentAbilities[index].CanUse(phase))
        {
            lastAbility = currentAbilities[index];
            animator.SetBool(AnimationConstants.Mirror, lastAbility.Mirror);
            lastAbility.Use(phase);
            isProblem = false;
        }
        else
        {
            isProblem = true;
        }
    }
    //Decelerate camera speed
    void DecelerateDrag()
    {
        if (dragSpeed <= 0.001)
        {
            dragPhase = InputPhase.Stop;
            return;
        }

        Vector3 v = new Vector3(direction.x, 0, direction.z).normalized *dragSpeed;

        transform.position += v;

        dragSpeed = Mathf.Lerp(dragSpeed, 0, Time.deltaTime * 7);
    }
    //Decelerate camera speed
    void DecelerateTilt()
    {
        if (tiltSpeed <= 0.5)
        {
            tiltPhase = InputPhase.Stop;
            return;
        }

        tiltSpeed *= 0.2f;

        tiltSpeed = Mathf.Lerp(tiltSpeed, 0, Time.deltaTime);

        transform.eulerAngles += new Vector3(0, Mathf.Sign(tiltDelta) * tiltSpeed, 0);
    }
Example #16
0
 private static KeyEvent GetKeyEventFromList(InputPhase phase, KeyCode key)
 {
     if (keyEventList != null)
     {
         foreach (KeyEvent e in keyEventList.ToArray())
         {
             if (e.phase == phase && e.key == key)
             {
                 return(e);
             }
         }
     }
     return(null);
 }
        public static void RegisterInputEvent(string name, InputPhase phase, InputDelegate method)
        {
            if (inputEventList == null)
            {
                inputEventList = new List <InputEvent>();
            }

            InputEvent inputEvent = new InputEvent();

            inputEvent.name    = name;
            inputEvent.phase   = phase;
            inputEvent.method += method;
            inputEventList.Add(inputEvent);
        }
Example #18
0
    private static ButtonEvent GetButtonEventFromList(InputPhase phase, string name)
    {
        if (buttonEventList != null)
        {
            foreach (ButtonEvent e in buttonEventList)
            {
                if (e.Phase == phase && e.Name == name)
                {
                    return(e);
                }
            }
        }

        return(null);
    }
Example #19
0
    public static void RegisterKeyEvent(InputPhase phase, KeyCode key, InputDelegate method)
    {
        if (keyEventList == null)
        {
            keyEventList = new List <KeyEvent>();
        }

        KeyEvent existing = GetKeyEventFromList(phase, key);

        if (existing == null)
        {
            existing = CreateKeyEvent(phase, key);
            keyEventList.Add(existing);
        }

        existing.method += method;
    }
 public override bool CanUse(InputPhase phase)
 {
     if ((phase == InputPhase.down || phase == InputPhase.hold) &&
         HasEnded())
     {
         return(characterComponents.characterSheet.HasResources(cost) &&
                IsDrained() == false);
     }
     else if (phase == InputPhase.up && HasEnded() == false)
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #21
0
    public static void RegisterButtonEvent(InputPhase phase, string name, InputDelegate method)
    {
        if (buttonEventList == null)
        {
            buttonEventList = new List <ButtonEvent>();
        }

        ButtonEvent existingEvent = GetButtonEventFromList(phase, name);

        if (existingEvent == null)
        {
            existingEvent = CreateButtonEvent(phase, name);
            buttonEventList.Add(existingEvent);
        }

        existingEvent.method += method;
    }
    public override void Use(InputPhase phase)
    {
        if (phase == InputPhase.down || phase == InputPhase.hold)
        {
            characterComponents.animator.SetTrigger(AnimationConstants.EnumToID(enableTrigger));
            characterComponents.animator.ResetTrigger(AnimationConstants.EnumToID(disableTrigger));
            characterComponents.characterSheet.AddEffect(useEffect, -1);
            characterComponents.characterSheet.AddAttackListener(this);
            characterComponents.characterSheet.IncreaseResources(-cost);
            characterComponents.attackIndicator.EnableBlockIndicator(blockConfig.blockAngle);
            IsUsing = true;

            routine = StartCoroutine(BlockRoutine());
        }
        else if (phase == InputPhase.up)
        {
            EndUse(false);
        }
    }
    public override bool CanUse(InputPhase phase)
    {
        if (base.CanUse(phase))
        {
            return(true);
        }

        else if (phase == InputPhase.down &&
                 HasEnded() &&
                 characterComponents.characterSheet.HasResources(cost))
        {
            return(true);
        }

        else
        {
            return(false);
        }
    }
    //Decelerate camera speed
    void DecelerateZoom()
    {
        zoomPhase = InputPhase.Stop;
        return;

        if (Mathf.Abs(zoomSpeed) <= 1)
        {
            zoomPhase = InputPhase.Stop;
            return;
        }

        zoomSpeed = Mathf.Clamp(zoomSpeed, 0, maxDragSpeed);
        zoomSpeed = Mathf.Lerp(zoomSpeed, 0, Time.deltaTime);

        float delta = zoomSpeed * Time.deltaTime;

        Vector3 v = transform.position + new Vector3(0, delta, 0);

        v.y = Mathf.Clamp(v.y, zoomDistanceMin, zoomDistanceMax);

        transform.position = v;
    }
    public override void Use(InputPhase phase)
    {
        if (phase == InputPhase.down)
        {
            characterComponents.characterSheet.IncreaseResources(-cost);
            IsUsing = true;
            characterComponents.animator.SetTrigger(AnimationConstants.EnumToID(attackTrigger));

            if (routine != null)
            {
                StopCoroutine(routine);
            }
            routine = StartCoroutine(AttackRoutine());
        }

        base.Use(phase);
        if (ChainIsUsing)
        {
            EndDamage();
            EndAbility();
        }
    }
Example #26
0
    private InputPhase GetInputPhase()
    {
        InputPhase inputPhase = new InputPhase {
            phase = TouchPhase.Canceled, position = new Vector3(), isValid = false
        };

        #if UNITY_EDITOR || UNITY_WEBGL
        if (Input.GetMouseButtonDown(0))
        {
            inputPhase.isValid  = true;
            inputPhase.phase    = TouchPhase.Began;
            inputPhase.position = Input.mousePosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            inputPhase.isValid  = true;
            inputPhase.phase    = TouchPhase.Ended;
            inputPhase.position = Input.mousePosition;
        }
        else if (Input.GetMouseButton(0))
        {
            inputPhase.isValid  = true;
            inputPhase.phase    = TouchPhase.Moved;
            inputPhase.position = Input.mousePosition;
        }
        #elif UNITY_IOS || UNITY_ANDROID
        if (Input.touchCount > 0)
        {
            Touch touch = Input.touches [0];
            inputPhase.phase    = touch.phase;
            inputPhase.position = touch.position;
            inputPhase.isValid  = true;
        }
        #else
        Debug.Log("Unable to identify the game running environment");
        #endif
        return(inputPhase);
    }
Example #27
0
    private InputPhase GetInputPhase()
    {
        InputPhase inputPhase = new InputPhase();

        inputPhase.inputCount = 0;
        #if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            inputPhase.inputCount = 1;
            inputPhase.phase      = TouchPhase.Began;
            inputPhase.position   = Input.mousePosition;
        }
        else if (Input.GetMouseButtonUp(0))
        {
            inputPhase.inputCount = 1;
            inputPhase.phase      = TouchPhase.Ended;
            inputPhase.position   = Input.mousePosition;
        }
        else if (Input.GetMouseButton(0))
        {
            inputPhase.inputCount = 1;
            inputPhase.phase      = TouchPhase.Moved;
            inputPhase.position   = Input.mousePosition;
        }
        #elif UNITY_IOS || UNITY_ANDROID || UNITY_IPHONE
        if (Input.touchCount > 0)
        {
            Touch touch = Input.touches [0];
            inputPhase.inputCount = Input.touchCount;
            inputPhase.phase      = touch.phase;
            inputPhase.position   = touch.position;
        }
        #else
        Debug.Log("Unable to identify the game running environment");
        #endif
        return(inputPhase);
    }
Example #28
0
 private InputData(Vector2 position, float seconds, InputPhase phase = InputPhase.None)
 {
     Phase    = phase;
     Position = position;
     Seconds  = seconds;
 }
Example #29
0
 public void iwantBattle()
 {
     MenuButtonPressed(0);
     update     = true;
     inputPhase = InputPhase.Battle;
 }
Example #30
0
    void Update()
    {
        //Goes through each touch
        foreach (Touch t in Input.touches)
        {
            //If any are over UI, then return
            if (EventSystem.current.IsPointerOverGameObject(t.fingerId))
            {
                return;
            }
        }

        //Returns out if a slider is being dragged
        if (UIManager.Instance.sliderIsBeingDragged)
        {
            return;
        }

        if (inputPhase == InputPhase.Placing)
        {
            //If the player is selecting
            if (inputType.IsHovering())
            {
                //Stores the data from the raycast
                TrackableHit trackableHit;

                //Shoots a ray that can only hit within the bounds of a tracked plane, and if it hits:
                if (Frame.Raycast(inputType.GetCursorPosition().x, inputType.GetCursorPosition().y, TrackableHitFlags.PlaneWithinBounds, out trackableHit))
                {
                    //Create an anchor at the hitPoint
                    Anchor anchor = Session.CreateAnchor(trackableHit.Pose);
                    //Instantiates the chessboard at the hitpoint, as a prefab of the anchor
                    chessBoard = Instantiate(chessBoardPrefab, trackableHit.Pose.position, Quaternion.identity, anchor.transform).transform;

                    //Face chessboard to player
                    chessBoard.LookAt(transform);
                    chessBoard.rotation = Quaternion.Euler(new Vector3(0, chessBoard.rotation.y, 0));

                    //Changes the input phase after the board is placed
                    inputPhase = InputPhase.Playing;

                    //Hides the tracked planes
                    showTrackedPlanes = false;

                    //Sets the move board button to interactable
                    UIManager.Instance.moveBoardButton.interactable = true;
                }
            }

            return;
        }

        else if (inputPhase == InputPhase.Playing)
        {
            //Cast a ray from its mouse position
            Ray ray = cam.ScreenPointToRay(inputType.GetCursorPosition());
            //Temp variable
            RaycastHit hit;
            //If the ray hits
            if (Physics.Raycast(ray, out hit))
            {
                //If it hits a square
                if (hit.collider.tag == "Square")
                {
                    Square selectedSquare = hit.transform.GetComponent <Square>();

                    if (selectedObject != null && inputType.IsSelecting())
                    {
                        //Get the piece script
                        Piece selectedPiece = selectedObject.GetComponent <Piece>();

                        //If the piece is on the team whose turn it is, and it can move to the spot
                        if (selectedPiece.team == TeamManager.Instance.currentPlayingTeam && selectedPiece.Move(selectedSquare.boardPosition))
                        {
                            //Resets the selected piece
                            selectedPiece.UnHighlight();
                            selectedObject = null;
                            hoveredObject  = null;
                            return;
                        }
                    }

                    //If the square has a piece
                    if (selectedSquare.currentPiece != null)
                    {
                        Piece selectedPiece = selectedSquare.currentPiece;
                        //If the player is selecting
                        if (inputType.IsSelecting())
                        {
                            //If the piece belongs to the team whose turn it is
                            if (selectedPiece.team == TeamManager.Instance.currentPlayingTeam)
                            {
                                //If the selected piece is a new piece
                                if (selectedPiece.gameObject != selectedObject && selectedObject != null)
                                {
                                    //Unhighlights the old object
                                    selectedObject.GetComponent <Piece>().UnHighlight();
                                }

                                //Set as selected object
                                selectedObject = selectedPiece.gameObject;
                                //Highlight the squares it can move to
                                selectedPiece.HighlightAllPossibleMoves();
                                //Selects the piece graphically
                                selectedPiece.Select();
                            }
                        }
                        //If the player is hovering and the piece isn't already selected
                        else if (inputType.IsHovering() && !selectedPiece.selected)
                        {
                            if (selectedPiece != (Object)hoveredObject)
                            {
                                if (hoveredObject != null && !hoveredObject.selected)
                                {
                                    hoveredObject.UnHighlight();
                                }
                            }

                            hoveredObject = selectedPiece;
                            hoveredObject.Highlight(Piece.hoverMagnitude);
                        }
                    }
                    else
                    {
                        if (inputType.IsHovering() && !selectedSquare.selected)
                        {
                            if (selectedSquare != (Object)hoveredObject)
                            {
                                if (hoveredObject != null && !hoveredObject.selected)
                                {
                                    hoveredObject.UnHighlight();
                                }
                            }

                            hoveredObject = selectedSquare;
                            hoveredObject.Highlight(Square.hoverHighlightMagnitude);
                        }
                    }
                }
            }
        }


        else if (inputPhase == InputPhase.Moving)
        {
            //If there are 2 fingers on the screen
            if (Input.touchCount > 1)
            {
                //Gets both of the touches
                Touch touch1 = Input.GetTouch(0);
                Touch touch2 = Input.GetTouch(1);

                //Gets the positions of the touches last frame
                Vector2 previousPos1 = touch1.position - touch1.deltaPosition;
                Vector2 previousPos2 = touch2.position - touch2.deltaPosition;

                //Gets the distance between both fingers last frame
                float previousDistance = (previousPos1 - previousPos2).magnitude;
                //Gets the distance between both fingers this frame
                float currentDistance = (touch1.position - touch2.position).magnitude;

                //Gets the change in distance between the 2 fingers in this frame
                float distanceMagnitude = (currentDistance - previousDistance);
                //Multiplies it with scaleSpeed
                float changeAmount = distanceMagnitude * scaleSpeed;

                //What the new scale of the board will be
                Vector3 newScale = chessBoard.localScale + new Vector3(changeAmount, changeAmount, changeAmount);


                //If the new scale is bigger than the max scale, set the scale to the max scale
                if (newScale.x > maxBoardSize)
                {
                    chessBoard.transform.localScale = new Vector3(maxBoardSize, maxBoardSize, maxBoardSize);
                }

                //If the new scale is smaller than the min scale, set the scale to the min scale
                else if (newScale.x < minimumBoardSize)
                {
                    chessBoard.transform.localScale = new Vector3(minimumBoardSize, minimumBoardSize, minimumBoardSize);
                }

                //If the new scale is within the set bounds, set it to the new scale
                else
                {
                    chessBoard.transform.localScale = newScale;
                }
            }

            //If the player is selecting
            else if (inputType.IsHovering())
            {
                //Stores the data from the raycast
                TrackableHit trackableHit;

                //Shoots a ray that can only hit within the bounds of a tracked plane, and if it hits:
                if (Frame.Raycast(inputType.GetCursorPosition().x, inputType.GetCursorPosition().y, TrackableHitFlags.PlaneWithinBounds, out trackableHit))
                {
                    //Moves the chessboard to the selected point
                    chessBoard.position = trackableHit.Pose.position;
                }
            }
        }

        debugText.text = UIManager.Instance.sliderIsBeingDragged.ToString();
    }