first commit
This commit is contained in:
49
Scripts/palette_manager.gd
Normal file
49
Scripts/palette_manager.gd
Normal file
@@ -0,0 +1,49 @@
|
||||
extends Node
|
||||
|
||||
@export_group("Gestione Palette")
|
||||
@export var materiale_da_cambiare: ShaderMaterial # Trascina qui il tuo materiale dall'Inspector
|
||||
@export var tempo_transizione: float = 2.0 # Quanto dura la sfumatura (in secondi)
|
||||
@export var valore_riga_2: float = 0.2 # Il valore target della seconda riga
|
||||
|
||||
var palette_spostata: bool = false
|
||||
var tween_palette: Tween
|
||||
|
||||
func _input(event: InputEvent) -> void:
|
||||
# Usiamo il tasto P (Palette) per innescare l'effetto
|
||||
if event is InputEventKey and event.pressed and not event.echo:
|
||||
if event.keycode == KEY_P:
|
||||
_cambia_palette_fluida()
|
||||
|
||||
func _cambia_palette_fluida() -> void:
|
||||
if materiale_da_cambiare == null:
|
||||
print("ERRORE: Non hai assegnato il materiale nell'Inspector!")
|
||||
return
|
||||
|
||||
# Invertiamo lo stato
|
||||
palette_spostata = !palette_spostata
|
||||
|
||||
# Decidiamo dove deve arrivare lo slider
|
||||
var target_shift = valore_riga_2 if palette_spostata else 0.0
|
||||
|
||||
# Se c'è già un'animazione in corso (es. hai premuto due volte velocemente), la fermiamo
|
||||
if tween_palette and tween_palette.is_valid():
|
||||
tween_palette.kill()
|
||||
|
||||
# Creiamo la nuova animazione fluida
|
||||
tween_palette = create_tween()
|
||||
|
||||
# Usiamo SINE e IN_OUT per renderla morbidissima in partenza e in arrivo
|
||||
tween_palette.set_trans(Tween.TRANS_SINE).set_ease(Tween.EASE_IN_OUT)
|
||||
|
||||
# Anima il parametro dello shader
|
||||
tween_palette.tween_property(
|
||||
materiale_da_cambiare,
|
||||
"shader_parameter/palette_shift_y", # Sintassi magica per parlare con lo shader
|
||||
target_shift,
|
||||
tempo_transizione
|
||||
)
|
||||
|
||||
if palette_spostata:
|
||||
print("Transizione verso la Palette 2 iniziata...")
|
||||
else:
|
||||
print("Ritorno alla Palette 1 originale...")
|
||||
Reference in New Issue
Block a user