Exemplo n.º 1
0
    public void Start()
    {
        positionFromATileClose = transform.position;

        GameObject goCameraCloseRef = GameObject.Find("CameraCloseRef");

        tClose.rotation         = goCameraCloseRef.transform.rotation;
        tClose.position         = goCameraCloseRef.transform.position;
        referenceTClosePosition = tClose.position;
        Destroy(goCameraCloseRef);

        GameObject goCameraFarRef = GameObject.Find("CameraFarRef");

        tFar.rotation = goCameraFarRef.transform.rotation;
        tFar.position = goCameraFarRef.transform.position;
        Destroy(goCameraFarRef);

        closeToFar = tFar.position - tClose.position;

        zoomState                   = eZoomState.forward;
        state                       = CameraState.Close;
        FZoomLerp                   = .85f;
        fLerpTarget                 = .85f;
        fZoomLerpOrigin             = .85f;
        isUpdateNeeded              = true;
        isFirstCallToUpdatePosition = false;
        hasMainQuestBeenShown       = false;

        GameManager.Instance.RegisterCameraManager(this);
    }
Exemplo n.º 2
0
    private void ControlZoom()
    {
        float fScrollValue = Input.GetAxis("Mouse ScrollWheel");

        if (fScrollValue != 0)
        {
            if ((fScrollValue > 0 && fZoomLerp < 1) || (fScrollValue < 0 && fZoomLerp > 0))
            {
                switch (zoomState)
                {
                case eZoomState.idle:
                    fZoomLerpOrigin = fZoomLerp;
                    fLerpTarget     = fZoomLerp;
                    break;

                case eZoomState.forward:
                    if (fScrollValue < 0)
                    {
                        fZoomLerpOrigin = fZoomLerp;
                        fLerpTarget     = fZoomLerp;
                    }
                    break;

                case eZoomState.backward:
                    if (fScrollValue > 0)
                    {
                        fZoomLerpOrigin = fZoomLerp;
                        fLerpTarget     = fZoomLerp;
                    }
                    break;

                default:
                    break;
                }

                fLerpTarget += fLerpNotch * (fScrollValue * 10);

                if (fLerpTarget > 1)
                {
                    fLerpTarget = 1;
                }
                else if (fLerpTarget < 0)
                {
                    fLerpTarget = 0;
                }

                if (fScrollValue > 0)
                {
                    zoomState = eZoomState.forward;
                }
                else
                {
                    zoomState = eZoomState.backward;
                }
            }
        }
        ControlZoomKeyboard();
    }
Exemplo n.º 3
0
 public void UpdateCameraPosition(Vector3 _newPosition)
 {
     isUpdateNeeded  = true;
     oldPosition     = tClose.position;
     newPosition     = _newPosition;
     zoomState       = eZoomState.forward;
     fZoomLerpOrigin = fZoomLerp;
     fLerpTarget     = 1.0f;
 }
Exemplo n.º 4
0
    private void UpdateCamZoom()
    {
        FZoomLerp = fZoomLerp + (fLerpTarget - fZoomLerpOrigin) * fZoomSpeed * Time.unscaledDeltaTime;

        if ((zoomState == eZoomState.forward && fZoomLerp > fLerpTarget) || (zoomState == eZoomState.backward && fZoomLerp < fLerpTarget) || (fLerpTarget == fZoomLerp))
        {
            FZoomLerp = fLerpTarget;
            zoomState = eZoomState.idle;
        }

        transform.position = Vector3.Lerp(tFar.position, tClose.position, fZoomLerp);
        transform.rotation = Quaternion.Lerp(tFar.rotation, tClose.rotation, fZoomLerp);
    }
Exemplo n.º 5
0
    // TODO: find a better way
    private void ControlZoomKeyboard()
    {
        if (Input.GetKey(KeyCode.KeypadPlus) || Input.GetKey(KeyCode.PageUp))
        {
            if (fZoomLerp < 1 && fZoomLerp > 0)
            {
                fZoomLerpOrigin = fZoomLerp;
                fLerpTarget     = fZoomLerp;
                fLerpTarget    += fLerpNotch;

                if (fLerpTarget > 1)
                {
                    fLerpTarget = 1;
                }
                else if (fLerpTarget < 0)
                {
                    fLerpTarget = 0;
                }

                zoomState = eZoomState.forward;
            }
        }

        if (Input.GetKey(KeyCode.PageDown) || Input.GetKey(KeyCode.KeypadMinus))
        {
            if (fZoomLerp < 1 && fZoomLerp > 0)
            {
                fZoomLerpOrigin = fZoomLerp;
                fLerpTarget     = fZoomLerp;
                fLerpTarget    -= fLerpNotch;

                if (fLerpTarget > 1)
                {
                    fLerpTarget = 1;
                }
                else if (fLerpTarget < 0)
                {
                    fLerpTarget = 0;
                }

                zoomState = eZoomState.backward;
            }
        }
    }
Exemplo n.º 6
0
    // WTF fonction spaghetti
    public void UpdateCameraPositionWithOffset(Vector3 _newTileCenter, Tile _newTile, Direction directionDuDeplacement)
    {
        isSpecialUpdate = true;
        oldPosition     = tClose.position;
        activeTile      = _newTile.Neighbors[(int)Utils.GetOppositeDirection(directionDuDeplacement)];
        if (directionDuDeplacement == Direction.South || directionDuDeplacement == Direction.South_East || directionDuDeplacement == Direction.South_West)
        {
            newPosition = _newTileCenter + Vector3.back;
        }
        else
        {
            if (activeTile != null)
            {
                newPosition = positionFromATileClose + activeTile.transform.position;
            }
        }

        fZoomLerpOrigin = fZoomLerp;

        fLerpTarget = 1 - (2 * fLerpNotch);
        zoomState   = eZoomState.backward;
    }
Exemplo n.º 7
0
    void Update()
    {
        if (GameManager.Instance != null &&
            ((GameManager.Instance.CurrentState == GameState.Normal || GameManager.Instance.CurrentState == GameState.InPause) ||
             (GameManager.Instance.CurrentState == GameState.InTuto && TutoManager.s_instance.PlayingSequence != null && (TutoManager.s_instance.PlayingSequence.GetType() == typeof(SeqMoraleExplained) || TutoManager.s_instance.PlayingSequence.GetType() == typeof(seqTeamCrocket)))))
        {
            if (isUpdateNeeded)
            {
                lerpParameter += Time.deltaTime;

                Vector3 v3NewPos = Vector3.Lerp(oldPosition, positionFromATileClose + activeTile.transform.position + Vector3.back, Mathf.Min(lerpParameter, 1.0f));

                v3NewPos.y      = tClose.position.y;
                tClose.position = v3NewPos;

                tFar.position = tClose.position + closeToFar;

                transform.position = Vector3.Lerp(tFar.position, tClose.position, fZoomLerp);
                transform.rotation = Quaternion.Lerp(tFar.rotation, tClose.rotation, fZoomLerp);

                if (lerpParameter >= 1.0f)
                {
                    isUpdateNeeded = false;
                    oldPosition    = Vector3.zero;
                    lerpParameter -= 1.0f;
                    if (isFirstCallToUpdatePosition && !hasMainQuestBeenShown)
                    {
                        // show main quest
                        GameManager.Instance.ShowMainQuest();
                        hasMainQuestBeenShown = true;
                    }

                    // Ajout par rémi
                    if ((zoomState == eZoomState.forward && fZoomLerp > fLerpTarget) || (zoomState == eZoomState.backward && fZoomLerp < fLerpTarget) || (fLerpTarget == fZoomLerp))
                    {
                        FZoomLerp = fLerpTarget;
                        zoomState = eZoomState.idle;
                    }
                }

                //Vector3 pos = transform.position;
                //pos.x = Mathf.Clamp(pos.x, cameraBounds.GetChild((int)CameraBound.West).position.x, cameraBounds.GetChild((int)CameraBound.East).position.x);
                //pos.z = Mathf.Clamp(pos.z, cameraBounds.GetChild((int)CameraBound.South).position.z, cameraBounds.GetChild((int)CameraBound.North).position.z);
                //transform.position = pos;
            }
            else if (isSpecialUpdate == true)
            {
                lerpParameter += Time.deltaTime;

                Vector3 v3NewPos = Vector3.Lerp(oldPosition, newPosition, Mathf.Min(lerpParameter, 1.0f));

                v3NewPos.y      = tClose.position.y;
                tClose.position = v3NewPos;

                tFar.position = tClose.position + closeToFar;

                transform.position = Vector3.Lerp(tFar.position, tClose.position, fZoomLerp);
                transform.rotation = Quaternion.Lerp(tFar.rotation, tClose.rotation, fZoomLerp);

                if (lerpParameter >= 1.0f)
                {
                    oldPosition   = Vector3.zero;
                    lerpParameter = 0.0f;

                    isSpecialUpdate = false;
                    newPosition     = Vector3.zero;
                }
            }

            if (GameManager.Instance.CurrentState != GameState.InPause)
            {
                Controls();
            }

            if (zoomState != eZoomState.idle)
            {
                UpdateCamZoom();
            }
        }
        else if (GameManager.Instance.CurrentState == GameState.InBattle ||
                 (GameManager.Instance.CurrentState == GameState.InTuto && TutoManager.s_instance.PlayingSequence != null && TutoManager.s_instance.PlayingSequence.GetType() == typeof(SeqTutoCombat)))
        {
            if (isUpdateNeeded)
            {
                lerpParameter += Time.deltaTime;

                Vector3 v3NewPos = Vector3.Lerp(oldPosition, newPosition + activeTile.transform.position, Mathf.Min(lerpParameter, 1.0f));

                v3NewPos.y      = tClose.position.y;
                tClose.position = v3NewPos;

                tFar.position = tClose.position + closeToFar;

                transform.position = Vector3.Lerp(tFar.position, tClose.position, fZoomLerp);
                transform.rotation = Quaternion.Lerp(tFar.rotation, tClose.rotation, fZoomLerp);

                if (lerpParameter >= 1.0f)
                {
                    isUpdateNeeded = false;
                    oldPosition    = Vector3.zero;
                    lerpParameter  = 0.0f;
                }
            }

            if (zoomState != eZoomState.idle)
            {
                UpdateCamZoom();
            }
        }
        foreach (GreyTileCameraAdapter ca in greyTileCameraAdapters)
        {
            ca.RecalculateOrientation(Camera.main);
        }

        foreach (SelectionPointerCameraAdapter ca in selectionPointerCameraAdapters)
        {
            ca.RecalculateOrientationAndScale();
        }

        foreach (WorldspaceCanvasCameraAdapter ca in worldspaceCanvasCameraAdapters)
        {
            ca.RecalculateActionCanvas(Camera.main);
        }

        if (fZoomLerp < 0.6f)
        {
            state = CameraState.Far;
        }
        else
        {
            state = CameraState.Close;
        }
    }