mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
force fields
This commit is contained in:
parent
c0a1853468
commit
22936c4678
19 changed files with 854 additions and 682 deletions
113
Scripts/Actors/3D/ForceField3D.cs
Normal file
113
Scripts/Actors/3D/ForceField3D.cs
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
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 props)
|
||||
{
|
||||
TargetName = (string)props["targetname"];
|
||||
StartActive = (bool)props["startenabled"];
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
1
Scripts/Actors/3D/ForceField3D.cs.uid
Normal file
1
Scripts/Actors/3D/ForceField3D.cs.uid
Normal file
|
|
@ -0,0 +1 @@
|
|||
uid://buneqosduiwkm
|
||||
Loading…
Add table
Add a link
Reference in a new issue