mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Forcefield Shader
This commit is contained in:
parent
a13355be42
commit
f23d84071a
9 changed files with 210 additions and 14 deletions
52
Scripts/Activables/ForceField.cs
Normal file
52
Scripts/Activables/ForceField.cs
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
using Godot;
|
||||
using System;
|
||||
using Cirno.Scripts;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public partial class ForceField : Door
|
||||
{
|
||||
[Export]
|
||||
public Shader TurnOffShader { get; private set; }
|
||||
|
||||
[Export]
|
||||
public Shader ActiveShader { get; private set; }
|
||||
|
||||
// Disable
|
||||
public override void Open()
|
||||
{
|
||||
base.Open();
|
||||
if (TurnOffShader is null) return;
|
||||
|
||||
((ShaderMaterial)_animatedSprite.Material).Shader = TurnOffShader;
|
||||
|
||||
_ = AnimateShutdownAsync();
|
||||
}
|
||||
|
||||
protected async Task AnimateShutdownAsync()
|
||||
{
|
||||
Tween tween = GetTree().CreateTween();
|
||||
tween.TweenMethod(Callable.From((float value) => SetShaderScanlineDensity(value)), 0f, 50f, 0.5);
|
||||
tween.Parallel().TweenMethod(Callable.From((float value) => SetShaderTeleportProgress(value)), 0f, 1f, 0.5);
|
||||
|
||||
await ToSignal(tween, "finished");
|
||||
}
|
||||
|
||||
// Enable
|
||||
public override void Close()
|
||||
{
|
||||
base.Close();
|
||||
|
||||
if (ActiveShader is null) return;
|
||||
((ShaderMaterial)_animatedSprite.Material).Shader = ActiveShader;
|
||||
}
|
||||
|
||||
private void SetShaderTeleportProgress(float value)
|
||||
{
|
||||
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("teleport_progress", value);
|
||||
}
|
||||
|
||||
private void SetShaderScanlineDensity(float value)
|
||||
{
|
||||
((ShaderMaterial)_animatedSprite.Material).SetShaderParameter("scanline_density", value);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue