mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 11:15:33 +00:00
113 lines
No EOL
2.5 KiB
C#
113 lines
No EOL
2.5 KiB
C#
using System;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Cirno.Scripts.Actors._3D;
|
|
|
|
[Tool]
|
|
public partial class ForceField3D : AnimatableBody3D, IActivable
|
|
{
|
|
[Export] public StringName TargetName { get; set; }
|
|
|
|
[Export] public bool StartActive { get; set; }
|
|
|
|
[Signal]
|
|
public delegate void EnabledEventHandler();
|
|
|
|
[Signal]
|
|
public delegate void DisabledEventHandler();
|
|
|
|
private bool _enabled = false;
|
|
|
|
private CollisionShape3D _collisionShape;
|
|
|
|
public bool Activate(ActivationType activationType = ActivationType.Toggle)
|
|
{
|
|
if (Engine.IsEditorHint()) return false;
|
|
|
|
switch (activationType)
|
|
{
|
|
case ActivationType.Toggle:
|
|
case ActivationType.Use:
|
|
if (_enabled)
|
|
{
|
|
Disable();
|
|
}
|
|
else
|
|
{
|
|
Enable();
|
|
}
|
|
break;
|
|
case ActivationType.Enable:
|
|
case ActivationType.Close:
|
|
Enable();
|
|
break;
|
|
case ActivationType.Disable:
|
|
case ActivationType.Open:
|
|
Disable();
|
|
break;
|
|
case ActivationType.Destroy:
|
|
return false;
|
|
break;
|
|
|
|
default:
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public void Toggle()
|
|
{
|
|
this.Activate();
|
|
}
|
|
|
|
public void _func_godot_apply_properties(Dictionary<string, Variant> props)
|
|
{
|
|
TargetName = props["targetname"].AsStringName();
|
|
StartActive = props["startenabled"].AsBool();
|
|
}
|
|
|
|
public override void _Ready()
|
|
{
|
|
if (Engine.IsEditorHint()) return;
|
|
if (!string.IsNullOrWhiteSpace(TargetName))
|
|
{
|
|
this.AddToGroup(TargetName);
|
|
}
|
|
|
|
_collisionShape = GetNode<CollisionShape3D>("CollisionShape3D");
|
|
|
|
if (StartActive)
|
|
{
|
|
Enable();
|
|
}
|
|
else
|
|
{
|
|
Disable();
|
|
}
|
|
}
|
|
|
|
public void Enable()
|
|
{
|
|
_enabled = true;
|
|
EmitSignalEnabled();
|
|
|
|
CallDeferred(MethodName.ToggleCollisionDeferred, true);
|
|
Show();
|
|
}
|
|
|
|
public void Disable()
|
|
{
|
|
_enabled = false;
|
|
EmitSignalDisabled();
|
|
|
|
CallDeferred(MethodName.ToggleCollisionDeferred, false);
|
|
Hide();
|
|
}
|
|
|
|
private void ToggleCollisionDeferred(bool enable)
|
|
{
|
|
_collisionShape.Disabled = !enable;
|
|
}
|
|
} |