You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Babushka/scripts/CSharp/Common/SpriteSwitcher.cs

36 lines
777 B

using Godot;
namespace Babushka.scripts.CSharp.Common;
/// <summary>
/// Switches between two Sprite Options.
/// </summary>
public partial class SpriteSwitcher : Node3D
{
[Export] private Sprite3D _trueSprite;
[Export] private Sprite3D _falseSprite;
[Export] private bool _state = true;
[Signal]
public delegate void SwitchEventHandler(bool state);
public override void _Ready()
{
SetState();
}
public void SwitchState()
{
_state = !_state;
EmitSignal(SignalName.Switch, _state);
SetState();
}
private void SetState()
{
if(_trueSprite != null)
_trueSprite.Visible = _state;
if(_falseSprite != null)
_falseSprite.Visible = !_state;
}
}