当前位置:网站首页>Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
Unity SKFramework框架(十七)、FreeCameraController 上帝视角/自由视角相机控制脚本
2022-07-02 09:45:00 【CoderZ1010】
目录
一、简介
FreeCameraController是用于上帝视角、自由视角的相机控制脚本,同时支持Input System Package(New)和Input Manager(Old)新、旧两种输入系统。

该工具已经上传至我的框架SKFramework中的开发工具箱,如图所示。


框架已经在Github开源,地址:https://github.com/136512892/SKFramework

二、功能
1.键盘控制平移
通过键盘W、S、A、D、E、Q按键分别实现向前、后、左、右、上、下方向的平移:

2.鼠标控制平移
通过按住鼠标左键进行拖拽实现平移:

3.视角拉近拉远
通过鼠标滚轮的滚动实现视角的拉近或拉远:

4.绕视角中心旋转
通过按住鼠标右键并拖拽实现视角绕中心点旋转:

5.视角聚焦
通过调用Focus函数实现视角的聚焦:
/// <summary>
/// 聚焦
/// </summary>
/// <param name="position">目标位置</param>
/// <param name="rotation">目标旋转</param>
/// <param name="duration">时长</param>
public void Focus(Vector3 position, Vector3 rotation, float duration);
6.活动区域限制
通过启用IsRangeClamped来实现活动范围的限制:

通过设置xMinValue...zMaxValue调整活动范围,如图所示,绿色线条形成的区域即活动的范围,相机运动不会超出该区域:

7.闲置时绕视角中心旋转
当用户在一定的时长内没有任何操作时,进入闲置状态,相机自动绕视角中心旋转,该功能通过启用enableAutoIdle实现:


三、核心变量

toggle:控制系统的开关
isRangeClamped:是否启用活动区域限制
xMinValue、xMaxValue:在x轴上的活动区域范围,当isRangeClamped为true时起作用
yMinValue、yMaxValue:在y轴上的活动区域范围,当isRangeClamped为true时起作用
zMinValue、zMaxValue:在z轴上的活动区域范围,当isRangeClamped为true时起作用
translateSpeed:平移的速度
boost:加速系数,当按下键盘左边的Shift键时会加速移动
positionLerpTime:坐标插值到目标值所需时长
rotationLerpTime:旋转插值到目标值所需时长
mouseMovementSensitivity:鼠标左键拖拽移动的灵敏度
mouseRotationSensitivityCurve:鼠标右键拖拽旋转的灵敏度
mouseScrollMoveSpeed:鼠标滚轮滚动时视角拉近拉远的速度
invertScrollDirection:是否反转鼠标滚轮滚动时视角拉近拉远的方向
enableAutoIdle:是否启用自动进入闲置状态
idleWaitTime:当用户在该时长内没有任何操作时,进入闲置状态,相机自动绕视角中心旋转,当enableAutoIdle为true时起作用
idleRotateSpeed:处于闲置状态时,绕视角中心旋转的速度
边栏推荐
- [opencv learning] [image histogram and equalization]
- How to get the operating system running PHP- How to get the OS on which PHP is running?
- Js6day (search, add and delete DOM nodes. Instantiation time, timestamp, timestamp cases, redrawing and reflow)
- About wechat enterprise payment to change x509certificate2 read certificate information, publish to the server can not access the solution
- 一些突然迸发出的程序思想(模块化处理)
- To bypass obregistercallbacks, you need to drive the signature method
- 计数类DP AcWing 900. 整数划分
- Win10 system OmniPeek wireless packet capturing network card driver failed to install due to digital signature problem solution
- 8A 同步降压稳压器 TPS568230RJER_规格信息
- Dijkstra AcWing 850. Dijkstra求最短路 II
猜你喜欢
![[200 opencv routines] 100 Adaptive local noise reduction filter](/img/89/9e9b667dd28cb25af005b6028ef26c.jpg)
[200 opencv routines] 100 Adaptive local noise reduction filter

计数类DP AcWing 900. 整数划分
![[opencv learning] [Canny edge detection]](/img/8b/37694ae2f0f13f829f3c033da0605e.jpg)
[opencv learning] [Canny edge detection]

线性DP AcWing 902. 最短编辑距离
![[opencv] [image gradient]](/img/37/1f366501e2b4e70ecee6365088167c.jpg)
[opencv] [image gradient]

Js1day (syntaxe d'entrée / sortie, type de données, conversion de type de données, Var et let différenciés)

国产免费数据仓库ETL调度自动化运维专家—TASKCTL

Js5day (event monitoring, function assignment to variables, callback function, environment object this, select all, invert selection cases, tab column cases)

js5day(事件监听,函数赋值给变量,回调函数,环境对象this,全选反选案例,tab栏案例)
![JDBC prevent SQL injection problems and solutions [preparedstatement]](/img/32/f71f5a31cdf710704267ff100b85d7.png)
JDBC prevent SQL injection problems and solutions [preparedstatement]
随机推荐
3 a VTT terminal regulator ncp51200mntxg data
Modular commonjs es module
JDBC prevent SQL injection problems and solutions [preparedstatement]
Does C language srand need to reseed? Should srand be placed in the loop? Pseudo random function Rand
JS10day(api 阶段性完结,正则表达式简介,自定义属性,过滤敏感词案例,注册模块验证案例)
Day4 operator, self increasing, self decreasing, logical operator, bit operation, binary conversion decimal, ternary operator, package mechanism, document comment
spfa AcWing 851. spfa求最短路
VIM super practical guide collection of this one is enough
[opencv learning] [image pyramid]
腾讯三面:进程写文件过程中,进程崩溃了,文件数据会丢吗?
[200 opencv routines] 100 Adaptive local noise reduction filter
Ali on three sides, it's really difficult to successfully get the offer rated P7
NTMFS4C05NT1G N-CH 30V 11.9A MOS管,PDF
About the loading of layer web spring layer components, the position of the layer is centered
自主可控三维云CAD:CrownCAD赋能企业创新设计
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
bellman-ford AcWing 853. Shortest path with side limit
线性DP AcWing 899. 编辑距离
Interval DP acwing 282 Stone merging
C#修饰符