10. 카메라를 물체에 대고 전체 조준 과정을 표시한다. 카메라 줌

4429 단어 oom
1. 버튼 이벤트에 코드를 넣고 호출하면 원하는 효과에 도달하지 못합니다
2. 의뢰하지 않아도 되지만 Update 함수에CameraZoonIn을 호출하는 코드를 써야 합니다
3. 개선해야 할 점이 많으니 iTween 플러그인을 참고하여 더욱 좋은 효과를 얻을 수 있다
using UnityEngine;

using System.Collections;



public class test : MonoBehaviour

{



    public delegate void dgCameraCompleted(Vector3 pos, Vector3 rot);

    public dgCameraCompleted CameraCompleted;



    public Camera currentCamera; //   



    public static float originFov;  //   



    private  Vector3 posStart;

    private  Vector3 rotStart;

    private static Vector3 posEnd;

    private static Vector3 rotEnd;

    private static Vector3 dPos;

    private static Vector3 dRot;



    public static bool cameraIsMoving = false;

    //          zoom in or out

    public static bool cameraIsZoomIn = false;



    public static float minFov = 5f;

    public static float maxFov = 90f;

    public static float sensitivity = 10f;

    private int i = 0;



    //               

    private static int closeFrames = 70;



    Vector3 posBe, rotBe;

    private static Vector3 localPositionOrigin;

    private static Vector3 localRotationOrigin;



    public GameObject target;

    void Start()

    {

        localPositionOrigin = currentCamera.transform.localPosition;

        localRotationOrigin = currentCamera.transform.localEulerAngles;



        originFov = currentCamera.fieldOfView;

       

        //    

        posBe = target.transform.position + new Vector3(-0.06f, 0.38f, -0.06f);

        rotBe = new Vector3(94f, 270f, 0f);

    }



    private void Update()

    {

        if (CameraCompleted != null)

        {

            CameraCompleted(posBe, rotBe);



        }

        //         

        if (cameraIsZoomIn)

        {

            if (cameraIsMoving)

            {

                i++;

                //                ,closeFrames        

                currentCamera.transform.position += dPos;

                currentCamera.transform.eulerAngles += dRot;



                if (i == closeFrames)

                {

                    cameraIsMoving = false;

                    i = 0;

                }

            }

        } //           

        else

        {

            float fov = currentCamera.fieldOfView;



            fov -= Input.GetAxis("Mouse ScrollWheel") * sensitivity;

            fov = Mathf.Clamp(fov, minFov, maxFov);



            currentCamera.fieldOfView = fov;

        }



    }

    public void CameraZoomIn(Vector3 posTar, Vector3 rotTar)

    {

        currentCamera.fieldOfView = originFov;



        posEnd = posTar;

        rotEnd = rotTar;

        Debug.Log("posTar=" + posTar);

        Debug.Log("rotTar=" + rotTar);



        posStart = currentCamera.transform.position;



        dPos = new Vector3((posEnd.x - posStart.x) / closeFrames, (posEnd.y - posStart.y) / closeFrames, (posEnd.z - posStart.z) / closeFrames);



        rotStart = currentCamera.transform.eulerAngles;

        dRot = (rotEnd - rotStart) / closeFrames;



        cameraIsMoving = true;

        cameraIsZoomIn = true;



        FixCameraView(true);

    }



    private static void FixCameraView(bool bFixed)

    {

        //            ,      

        if (cameraIsZoomIn == bFixed)

        {

            //mainCamera.transform.parent.GetComponent<CharacterMotor>().enabled = !bFixed;

            //mainCamera.GetComponent<MouseLook>().enabled = !bFixed;

            //mainCamera.transform.parent.GetComponent<MouseLook>().enabled = !bFixed;

        }

    }



    void OnGUI()

    {

        if (GUI.Button(new Rect(10, 10, 40, 40), "  "))

        {

            CameraCompleted += CameraZoomIn;

            Debug.Log(CameraCompleted);

        }

        if (GUI.Button(new Rect(10, 55, 40, 40), "  "))

        {

            CameraZoomOut();

            CameraCompleted = null;

        }

    }



    public void CameraZoomOut()

    {

        if (currentCamera == null)

            Debug.Log("camera");

        if (localPositionOrigin == null)

            Debug.Log("localposition");

        currentCamera.transform.localPosition = localPositionOrigin;

        currentCamera.transform.localEulerAngles = localRotationOrigin;

        cameraIsMoving = false;

        cameraIsZoomIn = false;

        FixCameraView(false);

    }



}


좋은 웹페이지 즐겨찾기