摄像机控制(ITween)

CameraCtrl

using UnityEngine;
using System.Collections;

public class CameraCtrl : MonoBehaviour {
    
    public Transform cam; //当前的Cam
    public bool isCamRotateAndTranslate = false; //摄像机是否旋转和移动
    public bool isRotate = false;               //摄像机是否旋转
    /// 
    /// 摄像机平滑的移动
    /// 
    /// 
    /// 
    public void camSmTo(Transform camPt, float tm)
    {
        iTween.MoveTo(cam.gameObject,
                      iTween.Hash("x", camPt.position.x,
                      "y", camPt.position.y,
                      "z", camPt.position.z,
                      "time", tm,
                      "easetype", iTween.EaseType.linear));
        iTween.RotateTo(cam.gameObject, iTween.Hash("x", camPt.eulerAngles.x,
                                                "y", camPt.eulerAngles.y,
                                                "z", camPt.eulerAngles.z,
                                               "time", tm,
                                               "easetype", iTween.EaseType.linear));
    }

    public void camSmTo(string camPtName, float tm)
    {
        Transform camPt = transform.Find(camPtName);
        camSmTo(camPt, tm);
       // Debug.LogWarning(camPtName);
    }

    /// 
    /// 摄像机移动
    /// 
    /// 
    public void camTo(string camPtName)
    {
        Transform camPt = transform.Find(camPtName);
        camTo(camPt);
    }
    public void camTo(Transform camPt)
    {
        cam.position = camPt.position;
        cam.rotation = camPt.rotation;
    }

    void FixedUpdate()
    {
        if (isCamRotateAndTranslate)
        {
            camRotateandTranslate(cam);
        }
        if (isRotate)
        {
            camRotate(cam);
        }
    }
    public void camRotateandTranslate(Transform campt)
    {
        campt.RotateAround(new Vector3(0,30,0),new Vector3(0,1,0),1f ); 
        campt.transform.Translate(Vector3.up * 0.6f);
        campt.transform.Translate(Vector3.forward * 0.5f);
    }

    public void camRotate(Transform campt)
    {
        campt.RotateAround(new Vector3(0,69f,0),new Vector3(0,1,0),(290/14)*Time.deltaTime); 
       // campt.Translate(Vector3.up*0.1f);  
    }

}

你可能感兴趣的:(摄像机控制(ITween))