unity相机插件Cinemachine的使用笔记

首先导入插件,本插件主要用于做相机控制,先

记录三个小功能的使用方法。

第一,多个视角的切换。如果在场景中需要进行视角切换,首先点击菜单栏Cinemachine->Create Virtual Camera,就可以得到一个虚拟相机。

unity相机插件Cinemachine的使用笔记

这些虚拟相机都是被主摄像机控制的,并不是真实存在的。

调整相机的角度,可以点击虚拟相机上的solo按钮来查看当前相机的视角

unity相机插件Cinemachine的使用笔记

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.PostProcessing;

public class CameraManager : MonoBehaviour
{
    public static CameraManager Instance;
     
    public CinemachineBrain CameraBrainScript;

    public List<CinemachineVirtualCamera> childCameraLst = new List<CinemachineVirtualCamera>();

    public CinemachineVirtualCamera CameraFollow;

    private PostProcessingBehaviour localProfile;

    public FireItem TargetFireItem;

    void Awake()
    {
        Instance = this;
    }
	// Use this for initialization
	void Start ()
    {
        CinemachineVirtualCamera[] cameras = this.transform.GetComponentsInChildren<CinemachineVirtualCamera>();
        for (int i = 0; i < cameras.Length; i++)
        {
            childCameraLst.Add(cameras[i]);
        }
        childCameraLst[0].MoveToTopOfPrioritySubqueue();

        localProfile = CameraBrainScript.transform.GetComponent<PostProcessingBehaviour>();

        localProfile.profile.vignette.settings = new VignetteModel.Settings()
        {
            mode = VignetteModel.Mode.Classic,
            color = Color.black,
            center = new Vector2(0.5f, 0.5f),
            intensity = 0.45f,
            smoothness = 0.2f,
            roundness = 1,
            rounded = false,
        };

    }


    private float i=0;
	// Update is called once per frame
	void Update ()
    {
        if (TargetFireItem.IsHappened)
        {
            i += 0.01f;
            localProfile.profile.vignette.settings = new VignetteModel.Settings()
            {
                mode = VignetteModel.Mode.Classic,
                color = Color.red,
                center = new Vector2(0.5f, 0.5f),
                intensity = Mathf.PingPong(i,0.5f),
                smoothness = 0.28f,
                roundness = 1,
                rounded = false,
            };
        }
        else
        {
            localProfile.profile.vignette.settings = new VignetteModel.Settings()
            {
                mode = VignetteModel.Mode.Classic,
                color = Color.white,
                center = new Vector2(0.5f, 0.5f),
                intensity = Mathf.PingPong(i, 0.5f),
                smoothness = 0.28f,
                roundness = 1,
                rounded = false,
            };
        }
	}

    public int index = 0;
    public void SwitchCamera()
    {
        index++;
        index = index % 5;
        Debug.Log("难道没有执行" + index);
        for (int i = 0; i < childCameraLst.Count; i++)
        {
            if (index==i)
            {
                Debug.Log("开启了Camera的相机"+index);
                childCameraLst[index].MoveToTopOfPrioritySubqueue();
            }
        } 
    }

 

第二个作用是做人物跟随,在虚拟相机的面板设置任务跟随的对象以及注视的对象部位,就可以实现跟随了,同时可以设置跟随抖动等特效。

第三,结合timeline实现相机融合。

unity相机插件Cinemachine的使用笔记


将拍摄对象动画放在上面,然后分别设置三个虚拟相机对着对象不同的身体部位,本例子实现了镜头从腿到头到背后的镜头过度融合。

 

。。。。。。未完待续