// Update is called once per frame
 void LateUpdate()
 {
     if (StateManager.Instance.State == GameState.targetingAbility)
     {
         if (Input.GetButtonDown("Cancel"))
         {
             Cancel();
         }
         else if (Input.GetMouseButtonDown(0))
         {
             Tile clicked = MousePosition.GetTile();
             if (listener.GetAvailableTargets().Contains(clicked))
             {
                 StateManager.Instance.DebugPop();
                 listener.Notify(clicked);
                 Tile.UnColourAll();
             }
         }
         else if (_aoe == AreaOfEffect.Burst)
         {
             Tile.UnColourAll();
             // colour tiles in the Area
             foreach (Tile t in _targets)
             {
                 t.ColourMe(Color.green);
             }
             // colours tiles in the area of effect
             Tile mt = MousePosition.GetTile();
             if (_targets.Contains(mt))
             {
                 foreach (Tile t in Burst(mt))
                 {
                     t.ColourMe(Color.red);
                 }
             }
         }
         else if (_aoe == AreaOfEffect.Line)
         {
             Tile.UnColourAll();
             // colour tiles in the Area
             foreach (Tile t in _targets)
             {
                 t.ColourMe(Color.green);
             }
             // colours tiles in the area of effect
             Tile mt = MousePosition.GetTile();
             if (_targets.Contains(mt))
             {
                 foreach (Tile t in Line3(_orig, mt))
                 {
                     t.ColourMe(Color.red);
                 }
             }
         }
     }
 }
Example #2
0
    // Update is called once per frame
    void Update()
    {
        Camera cam = Camera.main;

        if (Input.GetButtonDown("Zoom"))
        {
            // Debug.Log("Zoom?");
            // cam.orthographicSize *= Input.GetAxis("Zoom")*Time.deltaTime;
            if (Input.GetAxis("Zoom") < 0)
            {
                cam.orthographicSize *= zoomSpeed;
            }
            else
            {
                cam.orthographicSize /= zoomSpeed;
            }
        }
        else if (Input.GetAxis("Mouse ScrollWheel") != 0)
        {
            // Debug.Log("Zoom?");
            // cam.orthographicSize *= Input.GetAxis("Zoom")*Time.deltaTime;
            if (Input.GetAxis("Mouse ScrollWheel") < 0)
            {
                cam.orthographicSize *= zoomSpeed;
            }
            else
            {
                cam.orthographicSize /= zoomSpeed;
            }
        }

        Vector3 mousePos = Input.mousePosition;

        float mx = mousePos.x / Screen.width;
        float my = mousePos.y / Screen.height;

        if (StateManager.Instance.State == GameState.movingCamera)
        {
            if (_focusFrameDelay > 0)
            {
                cam.transform.position = _focusTarget * _focusSpeed + cam.transform.position * (1f - _focusSpeed);
                _focusTimer           += 0.03f;
                _focusFrameDelay      -= 0.03f;
            }
            _focusFrameDelay += Time.deltaTime;
            if (_focusTimer > 1f)
            {
                StateManager.Instance.DebugPop();
            }
        }
        // Border Scrolling
        else if (borderScroll && mx > -0.015f && mx < 1.015f && my > -0.015f && my < 1.015f)
        {
            Vector3 cameraPos = cam.transform.position;
            if (mx < xBorderScrollZone)
            {
                //Debug.Log("left!");
                float dx = (xBorderScrollZone - mx) / xBorderScrollZone;
                cameraPos.x -= scrollSpeed * Time.deltaTime * dx;
            }
            else if (mx > 1f - xBorderScrollZone)
            {
                // Debug.Log("right!");
                float dx = (mx - 1f + xBorderScrollZone) / xBorderScrollZone;
                cameraPos.x += scrollSpeed * Time.deltaTime * dx;
            }
            if (my < yBorderScrollZone)
            {
                // Debug.Log("up!");
                float dy = (yBorderScrollZone - my) / xBorderScrollZone;
                cameraPos.y -= scrollSpeed * Time.deltaTime * dy;
            }
            else if (my > 1f - yBorderScrollZone)
            {
                // Debug.Log("down!");
                float dy = (my - 1f + yBorderScrollZone) / yBorderScrollZone;
                cameraPos.y += scrollSpeed * Time.deltaTime * dy;
            }

            cam.transform.position = cameraPos;
        }

        if (StateManager.Instance.State != GameState.movingCamera)         // if moving camera, no player move camera!

        {
#if UNITY_STANDALONE
            if (Input.GetMouseButtonDown(1))
            {
                // register where we press down the button.
                _PressPosition        = MousePosition.Get();
                _Velocity             = Vector3.zero;
                _PressScreenPoisition = Input.mousePosition;
            }
            else if (Input.GetMouseButton(1))
            {
                Vector3 _curr = _PressPosition - MousePosition.Get();
                cam.transform.position = cam.transform.position + _curr;
                _Velocity = (_Velocity + _curr / Time.deltaTime) / 2;
            }
            else if (enableLerp)
            {
                float momentum = 1 / Mathf.Pow(10, Drag);
                _Velocity *= Mathf.Pow(momentum, Time.deltaTime);
                if (_Velocity.magnitude < 0.01f)
                {
                    _Velocity = Vector3.zero;
                }
                cam.transform.position += _Velocity * Time.deltaTime;
            }
            if (Input.GetMouseButtonUp(1))
            {
                //check if we moved the mouse since pressing RMB
                if ((_PressScreenPoisition - Input.mousePosition).magnitude < 45f)
                {
                    // open character sheet

                    if (Input.mousePosition.y > BottomBorder && MousePosition.GetTile().isOccuppied)
                    {
                        GameState s = StateManager.Instance.State;
                        if (s == GameState.playerTurn || s == GameState.unitSelected)
                        {
                            BattleSheet.Instance.Open(MousePosition.GetTile().Unit);
                        }
                    }
                }
            }
#endif
#if UNITY_EDITOR
            if (Input.GetMouseButtonDown(1))
            {
                // register where we press down the button.
                _PressPosition = MousePosition.Get();
            }
            else if (Input.GetMouseButton(1))
            {
                Vector3 _curr = _PressPosition - MousePosition.Get();
                cam.transform.position = cam.transform.position + _curr;
            }
#endif
#if UNITY_ANDROID
            // drag move
            if (Input.touchCount == 1)
            {
                if (_lastFingerNumber != 1)
                {
                    _PressPosition = MousePosition.Get();
                    _Velocity      = Vector3.zero;
                }
                else
                {
                    Vector3 _curr = _PressPosition - MousePosition.Get();
                    cam.transform.position = cam.transform.position + _curr;
                    _Velocity = (_Velocity + _curr / Time.deltaTime) / 2;
                }
            }
            // pinch zoom plus double drag move
            else if (Input.touchCount == 2)
            {
                Touch touchZero = Input.GetTouch(0);
                Touch touchOne  = Input.GetTouch(1);

                float magnitude = (touchOne.position - touchZero.position).magnitude;
                if (_lastFingerNumber != 2)
                {
                    _startMagnitude = magnitude;
                    _PressPosition  = MousePosition.Get();
                    _Velocity       = (_Velocity + _curr / Time.deltaTime) / 2;
                }
                else
                {
                    Camera.main.orthographicSize = (Camera.main.orthographicSize * 3 + _startZoom * _startMagnitude / magnitude) / 4;
                    Vector3 _curr = _PressPosition - MousePosition.Get();
                    cam.transform.position = cam.transform.position + _curr;
                    _Velocity = (_Velocity + _curr / Time.deltaTime) / 2;
                }
            }
            else
            {
                _startMagnitude = 0f;
                _startZoom      = Camera.main.orthographicSize;
                if (enableLerp)
                {
                    float momentum = 1 / Mathf.Pow(10, Drag);
                    _Velocity *= Mathf.Pow(momentum, Time.deltaTime);
                    if (_Velocity.magnitude < 0.01f)
                    {
                        _Velocity = Vector3.zero;
                    }
                    cam.transform.position += _Velocity * Time.deltaTime;
                }
            }
            _lastFingerNumber = Input.touchCount;
#endif
        }
        Constrain();
    }