当前位置:网站首页>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]
- 哈希表 AcWing 840. 模拟散列表
- Redis avalanche, penetration, breakdown
- spfa AcWing 852. spfa判断负环
- 3 A VTT端接 稳压器 NCP51200MNTXG资料
- Do you know all the interface test interview questions?
- [opencv learning] [Canny edge detection]
- . Net, C # basic knowledge
- js1day(輸入輸出語法,數據類型,數據類型轉換,var和let區別)
- JDBC prevent SQL injection problems and solutions [preparedstatement]
猜你喜欢

Js10day (API phased completion, regular expression introduction, custom attributes, filtering sensitive word cases, registration module verification cases)
![[opencv learning] [moving object detection]](/img/2e/9b437b7fe22f1d57334529eda68e37.jpg)
[opencv learning] [moving object detection]

线性DP AcWing 902. 最短编辑距离

js3day(数组操作,js冒泡排序,函数,调试窗口,作用域及作用域链,匿名函数,对象,Math对象)

Unforgettable Ali, 4 skills, 5 hr additional written tests, it's really difficult and sad to walk

Tencent three sides: in the process of writing files, the process crashes, and will the file data be lost?

bellman-ford AcWing 853. 有边数限制的最短路

js1day(输入输出语法,数据类型,数据类型转换,var和let区别)

Direct control PTZ PTZ PTZ PTZ camera debugging (c)

线性DP AcWing 897. 最长公共子序列
随机推荐
JDBC 预防sql注入问题与解决方法[PreparedStatement]
Rust language document Lite (Part 1) - cargo, output, basic syntax, data type, ownership, structure, enumeration and pattern matching
[opencv] [image gradient]
Jerry's weather code table [chapter]
C#运算符
Ali on three sides, it's really difficult to successfully get the offer rated P7
The coloring method determines the bipartite graph acwing 860 Chromatic judgement bipartite graph
Direct control PTZ PTZ PTZ PTZ camera debugging (c)
国产免费数据仓库ETL调度自动化运维专家—TASKCTL
Fully autonomous and controllable 3D cloud CAD: crowncad's convenient command search can quickly locate the specific location of the required command.
Mui WebView down refresh pull-up load implementation
. Net wechat message template push
绕过ObRegisterCallbacks需要驱动签名方法
Heap acwing 839 Simulated reactor
堆 AcWing 838. 堆排序
Docsify deploy IIS
Hundreds of web page special effects can be used. Don't you come and have a look?
[opencv learning] [Canny edge detection]
spfa AcWing 851. spfa求最短路
Jerry's weather code table [chapter]