コード例 #1
0
 IEnumerator Start()
 {
     if (GameManager.Instance == null)
     {
         Instantiate(Resources.Load <GameObject>("Game"));
     }
     while (GameManager.Instance == null)
     {
         yield return(null);
     }
     if (introCam == null)
     {
         introCam = FindTaggedInScene <IntroCam>("K_INTRO_CAM");
     }
     if (gameCam == null)
     {
         gameCam = FindTaggedInScene <GameCam>("K_GAMECAM");
     }
     if (winCam == null)
     {
         winCam = FindTaggedInScene <KCam>("K_WIN_CAM");
     }
     if (mapCam == null)
     {
         mapCam = FindTaggedInScene <DragCam>("K_MAP_CAM");
     }
     GameManager.Instance.currentLevel = this;
     cameraController.RegisterCamera("Game", gameCam);
     cameraController.RegisterCamera("Map", mapCam);
     cameraController.RegisterCamera("Intro", introCam);
     cameraController.RegisterCamera("Win", winCam);
     cameraController.SwitchToCamera("Game");
 }
コード例 #2
0
    IEnumerator CameraLerp(KCam fromCam, KCam toCam, float time)
    {
        inTransition = true;
        toCam.SetActive(true);

        float lerpTime = 0;

        while (lerpTime < time)
        {
            float t = lerpTime / time;
            mainCamera.transform.position = Vector3.Lerp(fromCam.transform.position, toCam.transform.position, t);
            mainCamera.transform.rotation = Quaternion.Lerp(fromCam.transform.rotation, toCam.transform.rotation, t);
            mainCamera.fieldOfView        = Mathf.Lerp(fromCam.camera.fieldOfView, toCam.camera.fieldOfView, t);
            mainCamera.aspect             = Mathf.Lerp(fromCam.camera.aspect, toCam.camera.aspect, t);
            lerpTime += Time.deltaTime;
            yield return(null);
        }

        mainCamera.transform.SetParent(toCam.transform, false);
        mainCamera.CopyFrom(toCam.camera);

        activeCam = toCam;
        if (fromCam != toCam)
        {
            fromCam.SetActive(false);
        }
        inTransition = false;
    }
コード例 #3
0
    public void RegisterCamera(string tag, KCam cam)
    {
        cameras.Add(tag, cam);
        camList.Add(cam);

        cam.camera.enabled = false;

        cam.SetActive(false);
    }
コード例 #4
0
    public void CopyPositionFromActive(KCam cam)
    {
        if (cam == activeCam || activeCam == null)
        {
            return;
        }

        cam.transform.position = activeCam.transform.position;
        cam.transform.rotation = activeCam.transform.rotation;
    }
コード例 #5
0
    public void UpdateCamera(KCam cam)
    {
        var     pos    = cam.camera.transform.position;
        Vector2 relPos = Vector2.zero;

        if (Test(pos, ref relPos))
        {
            cam.inForbiddenZone = true;
            float vPos = (1f - Mathf.Clamp(relPos.y, 0, 1f));
            cam.forbiddenStrength = Mathf.Lerp(strengthMin, strengthMax, vPos);
            Debug.Log("Forbidden: " + cam.forbiddenStrength);

            cam.forbiddenDirection = -transform.up;
            cam.forbiddenExit      = pos + transform.up * vPos * extentVPos;
        }
    }
コード例 #6
0
    public void UpdateCamera(KCam cam)
    {
        if (cam.inForbiddenZone)
        {
            return;
        }

        var pos = cam.camera.transform.position;

        if (IsOutsideWorld(pos, ref backToWorld))
        {
            cam.inForbiddenZone   = true;
            cam.forbiddenStrength = Mathf.Clamp(backToWorld.magnitude * 0.1f, 0, 1f);

            cam.forbiddenDirection = -backToWorld.normalized;
            cam.forbiddenExit      = pos + backToWorld;
        }
    }
コード例 #7
0
 public void LerpToKCam(KCam toCam, float time)
 {
     if (inTransition)
     {
         return;
     }
     if (activeCam == null)
     {
         SwitchToKCam(toCam);
         return;
     }
     if (!camList.Contains(toCam))
     {
         camList.Add(toCam);
     }
     mainCamera.enabled = true;
     StartCoroutine(CameraLerp(activeCam, toCam, time));
 }
コード例 #8
0
    public void SwitchToKCam(KCam toCam)
    {
        activeCam          = toCam;
        mainCamera.enabled = true;
        GameManager.SetAudioListener(audioListener);

        mainCamera.transform.SetParent(activeCam.transform, false);
        mainCamera.CopyFrom(activeCam.camera);
        foreach (KCam c in camList)
        {
            c.SetActive(c == activeCam);
        }

        if (!camList.Contains(toCam))
        {
            camList.Add(toCam);
        }
    }