Skip to content

Commit

Permalink
auto disable xr if is in editor
Browse files Browse the repository at this point in the history
  • Loading branch information
Cafezinhu committed May 8, 2023
1 parent 59733fa commit 391c231
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Spatial.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[ext_resource type="PackedScene" uid="uid://fiul51tsyoop" path="res://addons/godot-xr-tools/functions/function_teleport.tscn" id="3_isyx6"]
[ext_resource type="PackedScene" uid="uid://diyu06cw06syv" path="res://addons/godot-xr-tools/player/player_body.tscn" id="3_m4pts"]
[ext_resource type="PackedScene" uid="uid://c8l60rnugru40" path="res://addons/godot-xr-tools/objects/pickable.tscn" id="5_r3xxt"]
[ext_resource type="PackedScene" path="res://addons/xr-simulator/XRSimulator.tscn" id="7_yovyb"]
[ext_resource type="PackedScene" uid="uid://ctltchlf2j2r4" path="res://addons/xr-simulator/XRSimulator.tscn" id="7_yovyb"]
[ext_resource type="PackedScene" uid="uid://clc5dre31iskm" path="res://addons/godot-xr-tools/xr/start_xr.tscn" id="8_qoqsw"]

[sub_resource type="BoxShape3D" id="1"]
Expand Down Expand Up @@ -117,7 +117,6 @@ transform = Transform3D(0.402254, -0.874811, 0.269994, -0.530985, 0.0173175, 0.8
shadow_enabled = true

[node name="XRSimulator" parent="." instance=ExtResource("7_yovyb")]
is_camera_y_limited = false
xr_origin = NodePath("../XROrigin3D")

[node name="StartXR" parent="." instance=ExtResource("8_qoqsw")]
Expand Down
9 changes: 7 additions & 2 deletions addons/xr-simulator/XRSimulator.gd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
extends Node

@export var enabled: bool
@export var disable_xr_in_editor: bool = true
@export var device_x_sensitivity: float = 1
@export var device_y_sensitivity: float = 1
@export var scroll_sensitivity: float = 1
Expand Down Expand Up @@ -33,6 +34,8 @@ var key_map = {
KEY_ENTER: "menu_button"
}

@onready var viewport: Viewport = get_viewport()

func _ready():
if not enabled or \
XRServer.get_tracker("left_hand") or \
Expand Down Expand Up @@ -68,13 +71,15 @@ func _ready():
XRServer.add_tracker(right_tracker)


func _process(_delta):
if enabled and disable_xr_in_editor and OS.has_feature("editor") and viewport.use_xr:
viewport.use_xr = false

func _input(event):
if not enabled:
return
if Input.is_key_pressed(KEY_ESCAPE):
Input.mouse_mode = Input.MOUSE_MODE_VISIBLE
elif Input.is_key_pressed(KEY_F11):
get_viewport().use_xr = !get_viewport().use_xr
elif Input.mouse_mode != Input.MOUSE_MODE_CAPTURED and event is InputEventMouseButton:
Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

Expand Down

0 comments on commit 391c231

Please sign in to comment.