cinemachine_2D Cinemachine:提示和技巧「建议收藏」

cinemachine_2D Cinemachine:提示和技巧「建议收藏」cinemachineHaveyoubeenworkingonacamerasystemforyour2DgameforagesandwishtherewassomethinglikeCinemachinefor2D?Notmanypeopleknowaboutit,buttherealreadyis!Thisblogpost…

大家好,又见面了,我是你们的朋友全栈君。

cinemachine_2D Cinemachine:提示和技巧「建议收藏」

cinemachine

Have you been working on a camera system for your 2D game for ages and wish there was something like Cinemachine for 2D? Not many people know about it, but there already is! This blog post gives you some tips for getting the best out of Cinemachine, and how this tool can benefit and speed up the development of your 2D game significantly. Keep reading to find out more about Cinemachine Virtual Cameras, Confiners and more, specifically for use in 2D games.

您是否一直在为2D游戏开发摄影机系统,并希望有类似Cinemachine的2D游戏? 没有多少人知道这一点,但是已经有! 这篇博客文章为您提供了一些技巧,帮助您充分利用Cinemachine,以及该工具如何使2D游戏受益并加速其开发。 继续阅读以了解有关Cinemachine虚拟相机,限制器等的更多信息,这些信息专门用于2D游戏。

获取电影机 (Getting Cinemachine)

You can get Cinemachine from our Package Manager within Unity if you are using any version greater than 2018.1.0b7.

如果您使用的版本大于2018.1.0b7,则可以从Unity中的包管理器中获取Cinemachine。

This can be done by going to Window > Package Manager > All and then selecting Cinemachine.

可以通过转到窗口>程序包管理器>全部 ,然后选择Cinemachine来完成。

cinemachine_2D Cinemachine:提示和技巧「建议收藏」

Importing from PackageManager

从PackageManager导入

创建2D相机 (Creating a Camera for 2D)

With Cinemachine, it’s relatively easy to start creating your camera system for a 2D environment. Let’s take a look at creating a Virtual Camera for 2D.

使用Cinemachine,相对容易地开始为2D环境创建相机系统。 让我们看一下为2D创建虚拟相机。

  1. Create a 2D Virtual Camera by going to the menu bar and selecting Cinemachine > Create 2D Camera. This will create a Virtual Camera set up for a 2D environment. If it’s your first Virtual Camera in the scene, it will also add a Cinemachine Brain Component  to your Main Camera.

    通过转到菜单栏并选择Cinemachine>创建2D摄像机来创建2D虚拟摄像机。 这将创建一个用于2D环境的虚拟相机。 如果这是您场景中的第一台虚拟摄像机,它还将为您的主摄像机添加一个Cinemachine Brain组件。

    cinemachine_2D Cinemachine:提示和技巧「建议收藏」

The main thing you will notice between a 2D Virtual Camera and a 3D Virtual Camera is the fact that we are using a Framing Transposer. This special transposer will follow a target on the camera’s X-Y plane, and stop the camera from rotating. For the framing transposer to work correctly we need to ensure that the Virtual Cameras ‘LookAt target’ is null. Another thing to note is that 2D games use an Orthographic View, when first creating your Virtual Camera you will need to change the projection to Orthographic on the Cinemachine Brain Camera of your Scene.

您会在2D虚拟相机和3D虚拟相机之间注意到的主要事实是我们正在使用取景器。 这个特殊的转座器将跟随相机XY平面上的目标,并停止相机旋转。 为了使框架转储器正常工作,我们需要确保虚拟摄像机的“ LookAt目标”为空。 要注意的另一件事是2D游戏使用正交视图,在首次创建虚拟相机时,您需要将场景的Cinemachine Brain Camera上的投影更改为正交。

cinemachine_2D Cinemachine:提示和技巧「建议收藏」

An important thing to remember is that with Cinemachine you shouldn’t try to make one camera do everything. Instead, you can have different ‘Virtual Cameras’ around your scene and blend between them using the Cinemachine Brain. This blending can occur if the player is low health, the player has entered a certain area or any other scenario you can imagine that requires a change of Camera framing or Post Processing. You can adjust the blend settings on the Cinemachine Brain depending on how you want the visuals to be.

要记住的重要一件事是,使用Cinemachine时,您不应尝试让一台相机完成所有操作。 相反,您可以在场景周围使用不同的“虚拟相机”,并使用Cinemachine Brain在它们之间进行融合。 如果播放器健康状况不佳,播放器进入某个区域或您可以想象需要更改照相机取景或后期处理的任何其他场景,则可能会发生这种融合。 您可以根据想要的视觉效果来调整Cinemachine Brain上的混合设置。

Check out the video below to see how you can adjust your Virtual Camera during Play Mode.

观看下面的视频,了解如何在播放模式下调整虚拟相机。

提示:在“播放模式”下,您可以调整相机设置,只要您在虚拟相机上选中“在播放过程中保存” ,它们就会保存 (Tip: You can adjust the camera settings while in Play Mode and they will save as long as you have “Save During Play” checked on the Virtual Camera)

限制相机 (Confining a Camera)

Another cool thing we can do with Cinemachine is to use a boundary box to confine the Virtual Camera to a certain area. This feature is available in the extension section of the Virtual Camera. Below are the steps to create this effect.

我们对Cinemachine可以做的另一件很酷的事情是使用边界框将虚拟摄像机限制在特定区域。 该功能在虚拟相机的扩展部分中可用。 以下是创建此效果的步骤。

  1. Set up a boundary box for our level. This will be used to confine the level. This is done by:

    为我们的关卡设置一个边界框。 这将用于限制级别。 这是通过以下方式完成的:

    • Set the ‘BoxCollider2D’ to be “Used by Composite”.

      将“ BoxCollider2D”设置为“复合使用”。

      cinemachine_2D Cinemachine:提示和技巧「建议收藏」

See the results of this below:

请参阅下面的结果:

提示:使用“限制屏幕边缘”复选框时,边界区域必须大于虚拟摄像机的正投影大小。 如果边框小于屏幕,则限制器在该区域将无法正确运行。 (Tip: When using the “Confine Screen Edges” checkbox the bounding area needs to be bigger than the orthographic size of the Virtual Camera. If the bounding box is smaller than the screen, the confiner will not behave correctly in that area.)

Video Example:

视频示例:

集体相机 (Group Camera)

Another cool feature from Cinemachine that we can use in 2D is the Group Camera. This camera allows us to create a target group for our camera to look at. A Group Camera is useful if you’re doing a cutscene where you want to show something of importance, you want to keep more than one object in each frame, or if you want to create a local multiplayer game in 2D.

我们可以在2D中使用的Cinemachine的另一个很酷的功能是组相机。 通过此摄像机,我们可以为摄像机创建目标组以供查看。 如果您要进行过场动画以显示重要的内容,要在每个帧中保留多个对象,或者想要以2D方式创建本地多人游戏,则“组摄像机”很有用。

In Cinemachine we can do this the following way:

在Cinemachine中,我们可以通过以下方式进行操作:

  1. Create a new GameObject in the scene

    在场景中创建一个新的GameObject

    cinemachine_2D Cinemachine:提示和技巧「建议收藏」

A ‘Target Group’ is a Cinemachine component that allows you to view multiple targets on the same Virtual Camera. It adjusts the camera’s size to ensure that the targets are visible depending on the weight. For example, if all of the targets have a weight of 1, the target group will ensure that all targets are visible.

“目标组”是Cinemachine组件,可让您查看同一虚拟摄像机上的多个目标。 它会调整相机的尺寸,以确保根据重量可见目标。 例如,如果所有目标的权重均为1,则目标组将确保所有目标可见。

Here’s an example of a Group Camera that focuses on the player and a chest.

这是一个专注于玩家和箱子的集体摄像机的示例。

cinemachine_2D Cinemachine:提示和技巧「建议收藏」

提示:在组虚拟摄像机处于活动状态时添加或删除组成员时,将成员的权重限制为零。 这将使相机平稳地重新构图。 (Tip: When adding or removing group members while the Group Virtual Camera is live, lerp the member’s weight to and from zero. This will allow the Camera to reframe smoothly.)

使用脉冲相机震动 (Camera Shake using Impulse)

With Cinemachine V2.2, we’ve added in a new Impulse Extension. This extension allows users to create camera shake effects without creating any code. Impulse Extension can be added as an extension to your Virtual Camera. I’m going to walk you through how to add this to your scene:

使用Cinemachine V2.2,我们添加了新的Impulse Extension。 此扩展允许用户创建相机抖动效果而无需创建任何代码。 可以将Impulse Extension作为扩展添加到您的Virtual Camera。 我将指导您如何将其添加到场景中:

  1. Under the ‘Signal Shape’ heading, we’re going to select a Signal for the Raw Signal variable. This is a ‘NoiseSettings’ profile. We can either use the default ones or create our own.

    在“信号形状”标题下,我们将为原始信号变量选择一个信号。 这是一个“ NoiseSettings”配置文件。 我们可以使用默认值,也可以创建自己的默认值。

    If we wanted to we could adjust the Dissipation Mode to change the decay type. There are other settings we can adjust, but for now, that’s all we need.

    如果我们愿意,可以调整“耗散模式”以更改衰减类型。 我们还有其他可以调整的设置,但是到目前为止,这就是我们所需要的。

    You can see the result below:

    您可以在下面看到结果:

    cinemachine_2D Cinemachine:提示和技巧「建议收藏」

    So, to summarize, we now know how to:

    因此,总而言之,我们现在知道如何:

      I hope you enjoyed this blog post and now feel ready to use Cinemachine in your next 2D project! If you want to keep up to date with Cinemachine? Join in the discussion on our forum.

      希望您喜欢这篇博客文章,现在就准备在下一个2D项目中使用Cinemachine! 如果您想了解Cinemachine的最新信息? 参加我们论坛上的讨论

      翻译自: https://blogs.unity3d.com/2018/07/17/cinemachine-for-2d-tips-and-tricks/

      cinemachine

      版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

      发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/140331.html原文链接:https://javaforall.net

      (0)
      全栈程序员-站长的头像全栈程序员-站长


      相关推荐

      • Ngixn动静分离详细配置方法

        Ngixn动静分离详细配置方法目录前言:准备工作一.静态主机配置二.动态主机配置三.动静分离配置四.配置文件目录结构五.测试前言:  为了加快网站的解析速度,可以把动态页面和静态页面由不同的服务器来解析,加快解析速度。降低原来单个服务器的压力。在动静分离的tomcat的时候比较明显,因为tomcat解析静态很慢,其实这些原理的话都很好理解,简单来说,使用正则表达式匹配过滤,然后交给不同的服务器。  静态页面一般直接由Nginx来处理,动态页面则是通过反向代理,代理到后端的Tomcat,然后在做负载均衡,是选择本地静态页面,还是后

        2022年6月2日
        40
      • 免费搭建属于自己的域名个性邮箱

        免费搭建属于自己的域名个性邮箱

        2022年2月18日
        55
      • 卷积神经网络超详细介绍

        卷积神经网络超详细介绍1、卷积神经网络的概念2、发展过程3、如何利用CNN实现图像识别的任务4、CNN的特征5、CNN的求解6、卷积神经网络注意事项7、CNN发展综合介绍8、LeNet-5结构分析9、AlexNet10、ZFNet10.1意义10.2实现方法10.3训练细节10.4卷积网络可视化10.6总结11、VGGNet11.1结构11.2网络特点:1…

        2022年6月11日
        32
      • Eclipse导入Maven项目详解(新手初学)

        Eclipse导入Maven项目详解(新手初学)最近遇到Maven管理下的SpringMVC项目,组内某位将项目代码扔过来,一脸懵逼(囧),查阅了一些资料后终于将此项目运行通了(>_<),特此记录下来与各位分享。通俗的来说,Maven就是个类似于git的项目管理工具。而SpringMVC就是将M(Model)、V(View)、C(Controller)三者进行分离进行处理,更有利于开发的进行。下面我将介绍一个别人已经编译好的Maven项

        2022年5月31日
        44
      • 《前端运维》一、Linux基础–10定时任务「建议收藏」

        一、进程管理进程(Process)是计算机中的程序关于某数据集合上的一次运行活动,是系统进行资源分配和调度的基本单位,是操作系统结构的基础。在早期面向进程设计的计算机结构中,进程是程序的基本执行实体

        2022年3月25日
        46
      • 看完此文,必须明白一致性Hash算法「建议收藏」

        看完此文,必须明白一致性Hash算法「建议收藏」  一致性Hash算法在1997年由麻省理工学院提出的一种分布式哈希(DHT)实现算法,设计目标是为了解决因特网中的热点(HotSpot)问题,初衷和CARP十分相似。一致性Hash修正了CARP使用的简单哈希算法带来的问题,使得分布式哈希(DHT)可以在P2P环境中真正得到应用。  一致性Hash算法提出了在动态变化的Cache环境中,判定哈希算法好坏的四个定义:1、平衡性(Bal…

        2022年9月26日
        0

      发表回复

      您的邮箱地址不会被公开。 必填项已用 * 标注

      关注全栈程序员社区公众号