项目设置
依次点击配置(Config)-> 项目设置(Project Settings),打开项目设置窗口。
项目设置界面会罗列所有继承自LProjectSettingsBase的类型。
C++加载方法:LWorld::GetProjectSettings
Lua加载方法:LWorld::GetProjectSetting
编辑页面关闭后,相关配置会存放在[project_path]/res/content/config/[module_name]/[class_name].setting文件中。配置类如果标记了"Preload"的meta,会在启动编辑器或者游戏时预加载。
效果质量配置文件
①选择效果质量设置页签
②选择质量配置文件后面的浏览按钮
③在打开的文件浏览窗口中选择需要查找的文件
④⑤选择目标配置文件
⑥点击确认,完成配置
多效果配置预设
在效果质量设置页签上右键可新增配置或取消当前选择的预设效果。
在配置名称上右键可删除配置或者取消当前选择的预设效果。
通过点击选择不同的配置名称进行查看对应配置详情。
通过双击勾选不同的配置名称,应用对应的预设效果。
世界设置
通用项目设置
①用户输入配置文件
②默认启动关卡配置
③属性大类隐藏配置文件
④属性排序配置文件
⑤默认相机模式(飞行模式默认状态)
⑥场景流送类型配置
输入配置
- 启用鼠标平滑开关:控制鼠标平滑
- 启用视场(FOV)缩放开关:开启后使用摄像机管理器视场(FOV)缩放鼠标输入
- 是否启动时捕获鼠标
- 视场(FOV)缩放值:视场(FOV)缩放系数
- 双击时间:两次按键输入间隔时间小于该值时认为是双击
- 默认鼠标捕获模式
- 默认鼠标锁定模式
- 轴属性映射列表:轴逻辑名称与轴属性的映射表(例如:轴的缩放系数、是否取反)
- 组合键映射列表:组合逻辑名称与按键组合的映射表(例如:“跳跃”-“SpaceBar”)
- 轴映射列表:轴逻辑名称与按键的映射表(例如:“向前移动”-“W”)
添加/删除/编辑轴属性
添加/删除/编辑组合键映射
添加/删除/编辑轴映射
跳跃示例
玩家输入:按键输入SpaceBar键
输入配置:组合映射将SpaceBar键映射到“跳跃(Jump)”
输入组件:绑定组合映射回调
C++:
input_character_demo.cpp
void LInputCharacterDemo::SetupPlayerInputComponent(LInputComponent* pIC)
{
Assert(pIC);
{ ... }
{
// 添加组合回调
CCombinationCallback& cJumpPressedCC = pIC->TAddCombinationCallback(
"Jump", INPUT_EVENT_ENUM::Pressed,
this, &LInputCharacterDemo::OnJumpPressed);
cJumpPressedCC.bConsumeInput = true;
CCombinationCallback& cJumpReleasedCC = pIC->TAddCombinationCallback(
"Jump", INPUT_EVENT_ENUM::Released,
this, &LInputCharacterDemo::OnJumpReleased);
cJumpReleasedCC.bConsumeInput = true;
}
}Lua:
script_input_character.lua
--用此函数进行初始化
function on_begin_play(component)
local owner = component.GameObjectOwner
if nx_is_valid(owner) then
local input_comp = owner.InputComponent
if nx_is_valid(input_comp) then
nx_bind_script(owner, nx_current())
--绑定轴映射回调
input_comp:AddAxisBinding("MoveForward", true, false, true, "InputAxisEvent_MoveForward")
input_comp:AddAxisBinding("MoveRight", true, false, true, "InputAxisEvent_MoveRight")
input_comp:AddAxisBinding("Turn", true, false, true, "InputAxisEvent_Turn")
input_comp:AddAxisBinding("LookUp", true, false, true, "InputAxisEvent_LookUp")
--绑定组合映射回调
input_comp:AddCombinationBinding("Jump", IE_Pressed, true, false, true,
"InputActionEvent_Jump_Pressed")
input_comp:AddCombinationBinding("Jump", IE_Released, true, false, true,
"InputActionEvent_Jump_Released")
--轴映射回调
nx_callback(owner, "InputAxisEvent_MoveForward", "on_moveforward")
nx_callback(owner, "InputAxisEvent_MoveRight", "on_moveright")
nx_callback(owner, "InputAxisEvent_Turn", "on_turn")
nx_callback(owner, "InputAxisEvent_LookUp", "on_lookup")
--组合映射回调
nx_callback(owner, "InputActionEvent_Jump_Pressed", "on_jump_pressed")
nx_callback(owner, "InputActionEvent_Jump_Released", "on_jump_released")
nx_callback(owner, "on_velocity_changed", "on_velocity_changed")
--鼠标左击打开帮助文档
input_comp:AddCombinationBinding("LeftClick", IE_Pressed, true, false, true,
"InputActionEvent_LeftClick_Pressed")
input_comp:AddCombinationBinding("LeftClick", IE_Released, true, false, true,
"InputActionEvent_LeftClick_Released")
nx_callback(owner, "InputActionEvent_LeftClick_Pressed", "on_leftclick")
nx_callback(owner, "InputActionEvent_LeftClick_Released", "on_leftclick_up")
end
end
nx_callback(component, "on_tick", "tick")
end游戏逻辑:绑定的回调函数的处理
C++:
input_character_demo.cpp
void LInputCharacterDemo::OnJumpPressed()
{
Jump();
}
void LInputCharacterDemo::OnJumpReleased()
{
StopJumping();
}Lua:
script_input_character.lua
--用此函数进行初始化
function on_begin_play(component)
local owner = component.GameObjectOwner
if nx_is_valid(owner) then
local input_comp = owner.InputComponent
if nx_is_valid(input_comp) then
nx_bind_script(owner, nx_current())
--绑定轴映射回调
input_comp:AddAxisBinding("MoveForward", true, false, true, "InputAxisEvent_MoveForward")
input_comp:AddAxisBinding("MoveRight", true, false, true, "InputAxisEvent_MoveRight")
input_comp:AddAxisBinding("Turn", true, false, true, "InputAxisEvent_Turn")
input_comp:AddAxisBinding("LookUp", true, false, true, "InputAxisEvent_LookUp")
--绑定组合映射回调
input_comp:AddCombinationBinding("Jump", IE_Pressed, true, false, true,
"InputActionEvent_Jump_Pressed")
input_comp:AddCombinationBinding("Jump", IE_Released, true, false, true,
"InputActionEvent_Jump_Released")
--轴映射回调
nx_callback(owner, "InputAxisEvent_MoveForward", "on_moveforward")
nx_callback(owner, "InputAxisEvent_MoveRight", "on_moveright")
nx_callback(owner, "InputAxisEvent_Turn", "on_turn")
nx_callback(owner, "InputAxisEvent_LookUp", "on_lookup")
--组合映射回调
nx_callback(owner, "InputActionEvent_Jump_Pressed", "on_jump_pressed")
nx_callback(owner, "InputActionEvent_Jump_Released", "on_jump_released")
nx_callback(owner, "on_velocity_changed", "on_velocity_changed")
--鼠标左击打开帮助文档
input_comp:AddCombinationBinding("LeftClick", IE_Pressed, true, false, true,
"InputActionEvent_LeftClick_Pressed")
input_comp:AddCombinationBinding("LeftClick", IE_Released, true, false, true,
"InputActionEvent_LeftClick_Released")
nx_callback(owner, "InputActionEvent_LeftClick_Pressed", "on_leftclick")
nx_callback(owner, "InputActionEvent_LeftClick_Released", "on_leftclick_up")
end
end
nx_callback(component, "on_tick", "tick")
end--跳跃键按下回调
function on_jump_pressed(owner)
if nx_find_custom(owner, "JumpAgainLock") and owner.JumpAgainLock then
return 1
end
--角色跳跃
owner:Jump()
return 1
end
向前移动示例
玩家输入:按键输入W键
输入配置:轴映射将W键映射到“向前移动(MoveForward)”
输入组件:绑定轴映射回调
C++:
input_character_demo.cpp
void LInputCharacterDemo::SetupPlayerInputComponent(LInputComponent* pIC)
{
Assert(pIC);
{
// 添加轴回调
CAxisCallback& cMoveForwardAC = pIC->TAddAxisCallback("MoveForward",
this, &LInputCharacterDemo::OnMoveForward);
cMoveForwardAC.bConsumeInput = true;
CAxisCallback& cMoveRightAC = pIC->TAddAxisCallback("MoveRight",
this, &LInputCharacterDemo::OnMoveRight);
cMoveRightAC.bConsumeInput = true;
CAxisCallback& cTurnAC = pIC->TAddAxisCallback("Turn",
this, &LInputCharacterDemo::OnTurn);
cTurnAC.bConsumeInput = true;
CAxisCallback& cLookUpAC = pIC->TAddAxisCallback("LookUp",
this, &LInputCharacterDemo::OnLookUp);
cLookUpAC.bConsumeInput = true;
}
{ ... }
}Lua:
script_input_character.lua
local IE_MAX = 5
---------------------
--默认回调--
---------------------
--用此函数进行初始化
function on_begin_play(component)
local owner = component.GameObjectOwner
if nx_is_valid(owner) then
local input_comp = owner.InputComponent
if nx_is_valid(input_comp) then
nx_bind_script(owner, nx_current())
--绑定轴映射回调
input_comp:AddAxisBinding("MoveForward", true, false, true, "InputAxisEvent_MoveForward")
input_comp:AddAxisBinding("MoveRight", true, false, true, "InputAxisEvent_MoveRight")
input_comp:AddAxisBinding("Turn", true, false, true, "InputAxisEvent_Turn")
input_comp:AddAxisBinding("LookUp", true, false, true, "InputAxisEvent_LookUp")
--绑定组合映射回调
input_comp:AddCombinationBinding("Jump", IE_Pressed, true, false, true,
"InputActionEvent_Jump_Pressed")
input_comp:AddCombinationBinding("Jump", IE_Released, true, false, true,
"InputActionEvent_Jump_Released")
--轴映射回调
nx_callback(owner, "InputAxisEvent_MoveForward", "on_moveforward")
nx_callback(owner, "InputAxisEvent_MoveRight", "on_moveright")
nx_callback(owner, "InputAxisEvent_Turn", "on_turn")
nx_callback(owner, "InputAxisEvent_LookUp", "on_lookup")
--组合映射回调
nx_callback(owner, "InputActionEvent_Jump_Pressed", "on_jump_pressed")
nx_callback(owner, "InputActionEvent_Jump_Released", "on_jump_released")
nx_callback(owner, "on_velocity_changed", "on_velocity_changed")游戏逻辑:绑定的回调函数的处理
C++:
input_character_demo.cpp
void LInputCharacterDemo::OnMoveForward(float val)
{
LController* pController = GetController();
if (pController != NULL)
{
CXMVECTOR vAngle = pController->GetAngle();
AddMovementInput(FXMath::AngleGetForward(vAngle), val);
}
}Lua:
script_input_character.lua
--用此函数进行初始化
function on_begin_play(component)
local owner = component.GameObjectOwner
if nx_is_valid(owner) then
local input_comp = owner.InputComponent
if nx_is_valid(input_comp) then
nx_bind_script(owner, nx_current())
--绑定轴映射回调
input_comp:AddAxisBinding("MoveForward", true, false, true, "InputAxisEvent_MoveForward")
input_comp:AddAxisBinding("MoveRight", true, false, true, "InputAxisEvent_MoveRight")
input_comp:AddAxisBinding("Turn", true, false, true, "InputAxisEvent_Turn")
input_comp:AddAxisBinding("LookUp", true, false, true, "InputAxisEvent_LookUp")
--绑定组合映射回调
input_comp:AddCombinationBinding("Jump", IE_Pressed, true, false, true,
"InputActionEvent_Jump_Pressed")
input_comp:AddCombinationBinding("Jump", IE_Released, true, false, true,
"InputActionEvent_Jump_Released")
--轴映射回调
nx_callback(owner, "InputAxisEvent_MoveForward", "on_moveforward")
nx_callback(owner, "InputAxisEvent_MoveRight", "on_moveright")
nx_callback(owner, "InputAxisEvent_Turn", "on_turn")
nx_callback(owner, "InputAxisEvent_LookUp", "on_lookup")
--组合映射回调
nx_callback(owner, "InputActionEvent_Jump_Pressed", "on_jump_pressed")
nx_callback(owner, "InputActionEvent_Jump_Released", "on_jump_released")
nx_callback(owner, "on_velocity_changed", "on_velocity_changed")--向前移动回调
function on_moveforward(owner, axis_value)
if not nx_is_valid(owner) then
return 0
end
--获得控制器Y轴角度
local controller = owner.Controller
if nx_is_valid(controller) then
local yaw = controller.AngleY
--获得向前方向
local x, y, z = nx_function("ext_angle_get_forward_vector", 0.0, yaw, 0.0)
--增加移动量
owner:AddMovementInput(x, y, z, axis_value)
end
return 1
end