forked from xiangwang25/whale-town-front-v2
Initial WhaleTown V2 frontend
This commit is contained in:
32
scenes/Maps/ScenePortal.gd
Normal file
32
scenes/Maps/ScenePortal.gd
Normal file
@@ -0,0 +1,32 @@
|
||||
class_name ScenePortal
|
||||
extends Area2D
|
||||
|
||||
# ============================================================================
|
||||
# ScenePortal.gd - 场景入口传送组件
|
||||
# ============================================================================
|
||||
# 提供轻量级场景跳转能力,用于广场、小区和个人空间之间的入口。
|
||||
# ============================================================================
|
||||
|
||||
@export var targetSceneName: String = ""
|
||||
@export var targetSpawnName: String = ""
|
||||
@export var targetPosition: Vector2 = Vector2.ZERO
|
||||
|
||||
func _ready() -> void:
|
||||
body_entered.connect(_on_body_entered)
|
||||
|
||||
func _on_body_entered(body: Node2D) -> void:
|
||||
if not (body is PlayerController):
|
||||
return
|
||||
_change_scene()
|
||||
|
||||
func _change_scene() -> void:
|
||||
if targetSceneName.is_empty():
|
||||
push_warning("ScenePortal: targetSceneName is empty.")
|
||||
return
|
||||
|
||||
if not targetSpawnName.is_empty():
|
||||
SceneManager.set_next_spawn_name(targetSpawnName)
|
||||
elif targetPosition != Vector2.ZERO:
|
||||
SceneManager.set_next_scene_position(targetPosition)
|
||||
|
||||
SceneManager.change_scene(targetSceneName)
|
||||
Reference in New Issue
Block a user