mirror of
https://github.com/godotengine/godot-demo-projects.git
synced 2026-01-05 07:20:07 +01:00
Improve style in many demos (#1263)
This commit is contained in:
@@ -1,25 +1,27 @@
|
||||
extends Camera3D
|
||||
|
||||
|
||||
const MOUSE_SENSITIVITY = 0.002
|
||||
const MOVE_SPEED = 1.5
|
||||
|
||||
var rot := Vector3()
|
||||
var velocity := Vector3()
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED
|
||||
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
# Mouse look (only if the mouse is captured).
|
||||
if event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
if input_event is InputEventMouseMotion and Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
# Horizontal mouse look.
|
||||
rot.y -= event.screen_relative.x * MOUSE_SENSITIVITY
|
||||
rot.y -= input_event.screen_relative.x * MOUSE_SENSITIVITY
|
||||
# Vertical mouse look.
|
||||
rot.x = clamp(rot.x - event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57)
|
||||
rot.x = clamp(rot.x - input_event.screen_relative.y * MOUSE_SENSITIVITY, -1.57, 1.57)
|
||||
transform.basis = Basis.from_euler(rot)
|
||||
|
||||
if event.is_action_pressed(&"toggle_mouse_capture"):
|
||||
if input_event.is_action_pressed(&"toggle_mouse_capture"):
|
||||
if Input.get_mouse_mode() == Input.MOUSE_MODE_CAPTURED:
|
||||
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
|
||||
else:
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
extends Node3D
|
||||
|
||||
var open := false
|
||||
var open: bool = false
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"toggle_doors"):
|
||||
if open:
|
||||
# Close the door.
|
||||
# The occluder will be re-enabled when the animation ends
|
||||
# using `_on_animation_player_animation_finished()`.
|
||||
$AnimationPlayer.play_backwards(&"open")
|
||||
open = false
|
||||
else:
|
||||
# Open the door.
|
||||
$AnimationPlayer.play(&"open")
|
||||
open = true
|
||||
# Disable the occluder as soon as the door starts opening.
|
||||
# The occluder is not part of the pivot to prevent it from having its
|
||||
# position changed every frame, which causes the occlusion culling BVH
|
||||
# to be rebuilt each frame. This causes a CPU performance penalty.
|
||||
$OccluderInstance3D.visible = false
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
if not input_event.is_action_pressed(&"toggle_doors"):
|
||||
return
|
||||
if open:
|
||||
# Close the door.
|
||||
# The occluder will be re-enabled when the animation ends
|
||||
# using `_on_animation_player_animation_finished()`.
|
||||
$AnimationPlayer.play_backwards(&"open")
|
||||
open = false
|
||||
else:
|
||||
# Open the door.
|
||||
$AnimationPlayer.play(&"open")
|
||||
open = true
|
||||
# Disable the occluder as soon as the door starts opening.
|
||||
# The occluder is not part of the pivot to prevent it from having its
|
||||
# position changed every frame, which causes the occlusion culling BVH
|
||||
# to be rebuilt each frame. This causes a CPU performance penalty.
|
||||
$OccluderInstance3D.visible = false
|
||||
|
||||
|
||||
func _on_animation_player_animation_finished(_anim_name: StringName) -> void:
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
extends Node3D
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed(&"toggle_occlusion_culling"):
|
||||
|
||||
func _input(input_event: InputEvent) -> void:
|
||||
if input_event.is_action_pressed(&"toggle_occlusion_culling"):
|
||||
get_viewport().use_occlusion_culling = not get_viewport().use_occlusion_culling
|
||||
update_labels()
|
||||
if event.is_action_pressed(&"toggle_mesh_lod"):
|
||||
if input_event.is_action_pressed(&"toggle_mesh_lod"):
|
||||
get_viewport().mesh_lod_threshold = 1.0 if is_zero_approx(get_viewport().mesh_lod_threshold) else 0.0
|
||||
update_labels()
|
||||
if event.is_action_pressed(&"cycle_draw_mode"):
|
||||
if input_event.is_action_pressed(&"cycle_draw_mode"):
|
||||
get_viewport().debug_draw = wrapi(get_viewport().debug_draw + 1, 0, 5) as Viewport.DebugDraw
|
||||
update_labels()
|
||||
if event.is_action_pressed(&"toggle_vsync"):
|
||||
if input_event.is_action_pressed(&"toggle_vsync"):
|
||||
if DisplayServer.window_get_vsync_mode() == DisplayServer.VSYNC_DISABLED:
|
||||
DisplayServer.window_set_vsync_mode(DisplayServer.VSYNC_ENABLED)
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user