43 lines
938 B
GDScript3
43 lines
938 B
GDScript3
|
|
@tool
|
||
|
|
class_name CameraAnchor extends Node2D
|
||
|
|
|
||
|
|
## 该priority不会直接修改Anchor的priority
|
||
|
|
@export var priority: int = 0
|
||
|
|
@export var enabled: bool = true
|
||
|
|
@export var blend_time: float = 0.3
|
||
|
|
|
||
|
|
@export var zoom: Vector2 = Vector2.ONE
|
||
|
|
@export var offset: Vector2 = Vector2.ZERO
|
||
|
|
|
||
|
|
var _priority: int :
|
||
|
|
set(value):
|
||
|
|
if _priority != value:
|
||
|
|
_priority = value
|
||
|
|
on_priority_change.emit(_priority, self)
|
||
|
|
|
||
|
|
signal on_priority_change(_priority:int, anchor: CameraAnchor)
|
||
|
|
|
||
|
|
func _ready() -> void:
|
||
|
|
if not Engine.is_editor_hint():
|
||
|
|
_runtime_ready()
|
||
|
|
|
||
|
|
func _runtime_ready() -> void:
|
||
|
|
_priority = priority
|
||
|
|
|
||
|
|
func push_camera() -> void:
|
||
|
|
CameraSystem.reset_all_camera_priority()
|
||
|
|
_priority = 1000
|
||
|
|
|
||
|
|
func pop_camera() -> void:
|
||
|
|
_priority = 0
|
||
|
|
|
||
|
|
func _enter_tree() -> void:
|
||
|
|
if Engine.is_editor_hint():
|
||
|
|
return
|
||
|
|
CameraSystem.register_anchor(self)
|
||
|
|
|
||
|
|
func _exit_tree() -> void:
|
||
|
|
if Engine.is_editor_hint():
|
||
|
|
return
|
||
|
|
CameraSystem.unregister_anchor(self)
|