godot-psd-training/SceneLoader.gd
soul-walker e1cc2fb498 完善语音会话场景功能
场景加载添加token参数获取设置
2024-05-20 10:28:59 +08:00

31 lines
877 B
GDScript

extends Node
class_name SceneLoader
var ConfigParams = preload("res://config_params.gd")
func _ready():
# 监听JavaScript发送的场景名称
var training_name = JavaScriptBridge.eval("""
var urlParams = new URLSearchParams(window.location.search);
urlParams.get('training');
""")
var token = JavaScriptBridge.eval("""
var urlParams = new URLSearchParams(window.location.search);
urlParams.get('token');
""")
print(training_name, ", token=", token)
ConfigParams.Token = token
if not training_name:
$ErrMsg.text = "未指定实训"
else:
_on_scene_name_received(training_name)
func _on_scene_name_received(training_name):
print("load training: ", training_name)
var scene = load("res://trainings/" + training_name + ".tscn")
if not scene:
$ErrMsg.text = "未找到实训: %s" % training_name
if scene:
get_tree().change_scene_to_packed(scene)