CinemachineBrain的属性简介

CinemachineBrain的属性简介

CinemachineBrain是Unity Cinemachine的核心组件,它和Camera组件挂载在一起,监控场景中所有的virtual camera。CinemachineBrain在inspector中暴露的属性如下:

CinemachineBrain的属性简介1

Live Camera和Live Blend分别表示当前active的virtual camera以及blend的进度(如果有的话)。相关的代码可以在CinemachineBrainEditor找到:

[CustomEditor(typeof(CinemachineBrain))]
[CanEditMultipleObjects]
class CinemachineBrainEditor : UnityEditor.Editor
{CinemachineBrain Target => target as CinemachineBrain;public override VisualElement CreateInspectorGUI(){var ux = new VisualElement();ux.ContinuousUpdate(() =>{if (target == null || liveCamera == null)return;liveCamera.value = Target.ActiveVirtualCamera as CinemachineVirtualCameraBase;liveBlend.value = Target.ActiveBlend != null ? Target.ActiveBlend.Description : string.Empty;});return ux;}
}

可以看到引用的是CinemachineBrain的ActiveVirtualCamera和ActiveBlend字段。

public class CinemachineBrain : MonoBehaviour, ICameraOverrideStack, ICinemachineMixer
{/// <summary>/// Get the current active virtual camera./// </summary>public ICinemachineCamera ActiveVirtualCamera => CinemachineCore.SoloCamera ?? m_BlendManager.ActiveVirtualCamera;/// <summary>/// Get the current blend in progress.  Returns null if none./// It is also possible to set the current blend, but this is not a recommended usage/// unless it is to set the active blend to null, which will force completion of the blend./// </summary>public CinemachineBlend ActiveBlend {get => m_BlendManager.ActiveBlend;set => m_BlendManager.ActiveBlend = value;}
}

ActiveBlend.Description描述了从当前virtual camera切换到下一个virtual camera的进度。

CinemachineBrain的属性简介2

Show Debug Text字段,如果勾上,就会在Game窗口中显示当前live的virtual camera信息。

CinemachineBrain的属性简介3

Show Camera Frustum字段,如果勾上,就会在Scene窗口显示当前live的virtual camera视锥体,不用选中任何GameObject。

CinemachineBrain的属性简介4

Ignore Time Scale字段,勾上的话会使Cinemachine实时响应用户输入和阻尼,说白了就是不受time scale的影响。这里同样可以查看相关代码:

float GetEffectiveDeltaTime(bool fixedDelta)
{if (CinemachineCore.UniformDeltaTimeOverride >= 0)return CinemachineCore.UniformDeltaTimeOverride;if (CinemachineCore.SoloCamera != null)return Time.unscaledDeltaTime;if (!Application.isPlaying)return m_BlendManager.GetDeltaTimeOverride();if (IgnoreTimeScale)return fixedDelta ? Time.fixedDeltaTime : Time.unscaledDeltaTime;return fixedDelta ? Time.fixedDeltaTime : Time.deltaTime;
}

fixedDelta参数表示是否要使用Time.fixedDeltaTime,如果为false,在勾选的情况下,就会选择Time.unscaledDeltaTime,而不是Time.deltaTime

World Up Override字段,指定的transform的Y轴定义了Cinemachine在世界空间的up向量。如果为空,则默认为(0,1,0)。这点在代码中同样有体现:

/// <summary>Get the default world up for the virtual cameras.</summary>
public Vector3 DefaultWorldUp => (WorldUpOverride != null) ? WorldUpOverride.transform.up : Vector3.up;

Channel Mask字段主要用于分屏效果的实现。这种情况下,场景中会有多个camera,也就会有多个CinemachineBrain组件的存在。为了确定某一个virtual camera是属于哪个CinemachineBrain管理,就需要用到Channel Mask字段。相关的判断代码如下:

/// <summary>Returns true if camera is on a channel that is handles by this Brain.</summary>
/// <param name="vcam">The camera to check</param>
/// <returns></returns>
public bool IsValidChannel(CinemachineVirtualCameraBase vcam) => vcam != null && ((uint)vcam.OutputChannel & (uint)ChannelMask) != 0;

不过在大部分情况下,只需要一个屏幕,场景中也就只有一个CinemachineBrain,此时Channel Mask字段保持默认值即可,默认值为-1,这样转为uint就是0xffffffff了。

/// <summary>The CinemachineBrain will find the highest-priority CinemachineCamera that outputs 
/// to any of the channels selected.  CinemachineCameras that do not output to one of these 
/// channels will be ignored.  Use this in situations where multiple CinemachineBrains are 
/// needed (for example, Split-screen).</summary>
[Tooltip("The CinemachineBrain will find the highest-priority CinemachineCamera that outputs to "+ "any of the channels selected.  CinemachineCameras that do not output to one of these "+ "channels will be ignored.  Use this in situations where multiple CinemachineBrains are "+ "needed (for example, Split-screen).")]
public OutputChannels ChannelMask = (OutputChannels)(-1);  // default is Everything

Update Method字段表示virtual camera更新position和rotation的时机,有以下几种。

Update Method
Fixed Update和物理模块保持同步,在FixedUpdate时更新
Late Update在MonoBehaviour的LateUpdate时更新
Smart Update根据virtual camera当前的更新情况更新,推荐设置
Manual Updatevirtual camera不会自动更新,需要手动调用brain.ManualUpdate()

Smart Update具体是如何实现的呢?通过搜索UpdateMethods.SmartUpdate,可以查到相关的代码集中在ManualUpdateDoFixedUpdate这两个函数上。容易猜到,触发这两个函数的时机,一个是在LateUpdate,一个是在FixedUpdate期间:

void LateUpdate()
{if (UpdateMethod != UpdateMethods.ManualUpdate)ManualUpdate();
}
// Instead of FixedUpdate() we have this, to ensure that it happens
// after all physics updates have taken place
IEnumerator AfterPhysics()
{while (true){// FixedUpdate can be called multiple times per frameyield return m_WaitForFixedUpdate;DoFixedUpdate();}
}

由Unity的脚本执行顺序[3]可知,DoFixedUpdate会在Unity所有的FixedUpdate执行之后立刻执行。

决定在哪个Update阶段进行更新的逻辑,位于UpdateTracker.OnUpdate这个函数:

public void OnUpdate(int currentFrame, UpdateClock currentClock, Matrix4x4 pos)
{if (lastPos == pos)return;if (currentClock == UpdateClock.Late)++numWindowLateUpdateMoves;else if (lastFrameUpdated != currentFrame) // only count 1 per rendered frame++numWindowFixedUpdateMoves;lastPos = pos;UpdateClock choice;if (numWindowFixedUpdateMoves > 3 && numWindowLateUpdateMoves < numWindowFixedUpdateMoves / 3)choice = UpdateClock.Fixed;elsechoice =  UpdateClock.Late;if (numWindows == 0)PreferredUpdate = choice;if (windowStart + kWindowSize <= currentFrame){
#if DEBUG_LOG_NAMEDebug.Log(name + ": Window " + numWindows + ": Late=" + numWindowLateUpdateMoves + ", Fixed=" + numWindowFixedUpdateMoves);
#endifPreferredUpdate = choice;++numWindows;windowStart = currentFrame;numWindowLateUpdateMoves = (PreferredUpdate == UpdateClock.Late) ? 1 : 0;numWindowFixedUpdateMoves = (PreferredUpdate == UpdateClock.Fixed) ? 1 : 0;}
}

其主要逻辑,就是采样前一段时间kWindowSize = 30帧内,virtual camera的target position在LateUpdate和FixedUpdate时发生变化的次数,如果FixedUpdate次数是LateUpdate次数的三倍以上,那就选择在FixedUpdate更新virtual camera,否则选择LateUpdate。

Blend Update Method表示混合并更新主相机的时机,推荐使用Late Update。

Lens Mode Override表示是否允许virtual camera修改主相机的模式(透视,正交,物理)。如果不勾上,那么在virtual camera的设置里修改是不生效的:

CinemachineBrain的属性简介5

Default Blend表示两个virtual camera混合的方式,Unity默认提供了若干种,当然也可以自定义。

btw,在旧版本中CinemachineBrain监听的事件也在CinemachineBrain组件中,而新版本(3.1.0)这部分已经剥离出来,单独作为Cinemachine Brain Event组件存在了。现在支持六种事件:

CinemachineBrain的属性简介6

Reference

[1] Cinemachine Brain component

[2] Cinemachine(一)VirtualCamera和Brain的简单介绍

[3] Order of execution for event functions

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/870029.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python-26-零基础自学python-如何创建文件、读取数据、处理多个文件及程序异常处理等

学习内容&#xff1a;《python编程&#xff1a;从入门到实践》第二版第10章 知识点&#xff1a; 程序异常如何处理&#xff1f;try-except-else 多个文件处理 创建文件&#xff1a;在文件中储存数据 练习内容&#xff1a; 练习10-8&#xff1a;猫和狗 创建文件cats.txt和…

YOLOv10改进 | Conv篇 | CVPR2024最新DynamicConv替换下采样(解决低FLOPs陷阱)

一、本文介绍 本文给大家带来的改进机制是CVPR2024的最新改进机制DynamicConv其是CVPR2024的最新改进机制&#xff0c;这个论文中介绍了一个名为ParameterNet的新型设计原则&#xff0c;它旨在在大规模视觉预训练模型中增加参数数量&#xff0c;同时尽量不增加浮点运算&#x…

训练营第八天 | 344.反转字符串、541. 反转字符串II、卡码网:54.替换数字

344.反转字符串 做题思路 双指针库函数的实现 代码细节 class Solution { public:// 库函数swap的实现void swapString(char& a, char& b) {char tmp a;a b;b tmp;}void reverseString(vector<char>& s) {// 双指针库函数int i, j;for(i 0, j s.siz…

PyTorch复现PointNet——模型训练+可视化测试显示

因为项目涉及到3D点云项目&#xff0c;故学习下PointNet这个用来处理点云的神经网络 论文的话&#xff0c;大致都看了下&#xff0c;网络结构有了一定的了解&#xff0c;本博文主要为了下载调试PointNet网络源码&#xff0c;训练和测试调通而已。 我是在Anaconda下创建一个新的…

Harbor企业docker私服安装及SSL安全访问配置

基础环境 ubuntu server18 域名配置 sudo vi /etc/hosts www.node23.com 192.168.43.23 docker安装 一键安装 curl -sSL https://get.daocloud.io/docker | sh 配置docker vi /etc/docker/daemon.json { "registry-mirrors": ["https://squpqgby.mirr…

掌握SQLCMD魔术:在SQL Server中以SQLCMD模式执行脚本的全面指南

掌握SQLCMD魔术&#xff1a;在SQL Server中以SQLCMD模式执行脚本的全面指南 SQL Server提供了一个强大的命令行工具&#xff0c;名为SQLCMD&#xff0c;它允许用户执行包含变量替换和条件逻辑的脚本。这种模式特别适用于自动化数据库维护任务、批量处理数据和部署数据库更改。…

Python——使用Seaborn钻石数据可视化分析(1)

目录 🧾 1、数据集(部分数据) ✏️ 2、导入数据集与必要模块 1️⃣ 导入数据 📍 通过info函数查看所有列数据的类型信息 2️⃣ 导入Seaborn工具包 📍 set_context 设置图形绘制时的上下文参数 📍 set_style 设置绘图风格 📍 set_palette 设置图标全局颜色…

CentOS 设置手动同步指定NTP时钟服务器

1. 文件上传至服务器 2.进入文件路径 3.查看文件名称 4.安装rpm包 注意执行顺序 1&#xff0c;3&#xff0c;2 5.启动ntp并设置开机自启 6.配置ntp配置文件 修改为时间服务器ip&#xff08;同时要删除或注释掉其他三个server开头的外网的配置&#xff0c;防止因为外网不通导致…

C++基础学习笔记

1.命名空间(namespace) 1.什么是命名空间&命名空间的作用 1.在C/C中&#xff0c;变量、函数、类都是大量存在的&#xff0c;这些变量等的名称将都存在于全局作用域中&#xff0c;就会导致很多的命名冲突等。使用命名空间的目的就是对标识符的名称进行本地化&#xff0c;以…

自动驾驶革命:商汤科技突破性大模型UniAD震撼登场

自动驾驶革命&#xff1a;商汤科技突破性大模型UniAD震撼登场&#xff01; 在人工智能的浪潮中&#xff0c;自动驾驶技术一直是科技巨头们竞相追逐的圣杯。而今&#xff0c;商汤科技联合上海人工智能实验室与武汉大学&#xff0c;以一篇名为"Planning-oriented Autonomou…

京准电钟:云计算中NTP网络时间服务器的作用是什么?

京准电钟&#xff1a;云计算中NTP网络时间服务器的作用是什么&#xff1f; 京准电钟&#xff1a;云计算中NTP网络时间服务器的作用是什么&#xff1f; NTP是一种用于同步网络中设备时间的协议&#xff0c;广泛用于互联网和局域网中。NTP网络时间服务器则是基于NTP协议构建&…

内核调试方法

文章目录 printksysrqkdb/kgdbTRACE_EVENT&#xff0c;tracepoint使用参考 printk 通过proc/sys/kernel/printk查看打印等级 $ cat /proc/sys/kernel/printk 1 4 1 3四个数字分别对应: console_loglevel&#xff1a;控制台使用的日志级别&#xff1b; defa…

AI in Finance 金融领域AI应用-基于DeepNLP AI App Store 真实用户评论打分和排名

AI在金融领域应用 AI in Finance 金融服务领域的AI应用和传统的金融智能应用不同。传统金融智能应用包括如风险评估 (Risk assessment), 风险管理&#xff08;Risk management), 欺诈检测 (Fraud Detection&#xff09;等等。 通用AI大模型和人工智能应用如ChatGPT&#xff0c…

p12初步认识c语言

1.初识c语言 什么是c语言 c语言是一门计算机语言 计算机语言是什么 人和计算机交流语言 c/c/JAVA/python 语言发展&#xff1a; 二进制语言 硬件-电-正电/负电 1010001010101010101010101010手册 科学家 1010100010-ADD -助记符-汇编语言 B语言 C语言 C、---高级…

设置Llinux自带的led功能,在timer模式下设置delay_on后会把delay_off给清0

记录&#xff1a; 内核版本4.9.88. 问题复现方法是&#xff1a; 1. cd /sys/class/leds/cpu //cpu是内核自带led的节点名 2. echo timer > trigger 3. echo 100 > delay_on在设置完delay_on之后&#xff0c;发现delay_off自己设置为0了。同理设置delay_off后&#xff…

【C++精华铺】11.STL vector模拟实现

1.序言 STL&#xff08;Standard Template Library&#xff09;是C的标准库之一&#xff0c;提供了一系列的模板类和函数&#xff0c;用于实现常用的数据结构和算法。其中&#xff0c;STL的vector是一个动态数组&#xff0c;可以根据需要自动调整大小。 vector可以存储任意类型…

python JSON Lines (JSONL)的保存和读取;jsonl的数据保存和读取,大模型prompt文件保存常用格式

1. JSON Lines (JSONL)文件保存 将一个包含多个字典的列表保存为 JSON Lines (JSONL) 格式的文件&#xff0c;每个字典对应一个 JSONL 文件中的一行。以下是如何实现这一操作的 Python 代码 import json# 定义包含字典的列表 data [{"id": 1, "name": &qu…

数据库系统安全

数据库安全威胁 数据库作为信息系统中的核心组成部分&#xff0c;存储和管理着大量敏感和关键的数据&#xff0c;成为网络攻击者的主要目标之一。以下是常见的数据库安全威胁及其详细描述&#xff1a; 一、常见数据库安全威胁 SQL注入攻击&#xff08;SQL Injection&#xff…

37.深度学习中的梯度下降法及其实现

在深度学习的优化过程中&#xff0c;梯度下降法及其变体是必不可少的工具。通过对梯度下降法的理论学习&#xff0c;我们能够更好地理解深度学习模型的训练过程。本篇文章将介绍梯度下降的基本原理&#xff0c;并通过代码实现展示其具体应用。我们会从二维平面的简单梯度下降开…

使用nodejs进行截图

创建一个空文件夹 初始化项目 npm init -y下载插件 yarn add puppeteer根目录下创建app.js放入以下内容&#xff1a; const puppeteer require(puppeteer);(async () > {// 启动 Puppeteer 并创建一个新浏览器实例// const browser await puppeteer.launch(); // 会在…