FANDOM


This custom Action allows you to change the priority of a Cinemachine camera. It is provided by @shredingskin on the AC forum.

using UnityEngine;
using System.Collections;
using Cinemachine;

#if UNITY_EDITOR
using UnityEditor;
#endif
namespace AC
{

[System.Serializable]
public class ActionCinemachineCamera : Action
{

// Declare variables here
public CinemachineVirtualCameraBase CM_cam;
public int Priority;

public ActionCinemachineCamera()
{
this.isDisplayed = true;
category = ActionCategory.Camera;
title = "CM Priority";
description = "Changes CM priority";
}


override public float Run()
{
if (CM_cam)
{
if (CM_cam.GetComponent<CinemachineVirtualCameraBase>())
{
CM_cam.GetComponent<CinemachineVirtualCameraBase>().enabled = true;
CM_cam.MoveToTopOfPrioritySubqueue();
}
CM_cam.Priority = Priority;
}
return 0f;
}


#if UNITY_EDITOR

override public void ShowGUI ()
{
CM_cam = (CinemachineVirtualCameraBase)EditorGUILayout.ObjectField("CM Camera:", CM_cam, typeof(CinemachineVirtualCameraBase), true);
Priority = EditorGUILayout.IntField("Priority:", Priority);
AfterRunningOption();
}

public override string SetLabel ()
{
string labelAdd = "Changes virtual camera priority and moves to top queue";
return labelAdd;
}

#endif

}

}