init
This commit is contained in:
79
Meeting.cs
Normal file
79
Meeting.cs
Normal file
@@ -0,0 +1,79 @@
|
||||
using System;
|
||||
using Godot;
|
||||
|
||||
public partial class Meeting : RigidBody2D
|
||||
{
|
||||
private bool _mouseInside;
|
||||
private bool _isDragging;
|
||||
private Vector2 _dragTarget;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
FreezeMode = FreezeModeEnum.Kinematic;
|
||||
|
||||
MouseEntered += () =>
|
||||
{
|
||||
_mouseInside = true;
|
||||
CanSleep = false;
|
||||
};
|
||||
MouseExited += () =>
|
||||
{
|
||||
_mouseInside = false;
|
||||
CanSleep = true;
|
||||
};
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
// TODO: probably memory problem
|
||||
if (@event is InputEventMouse mouseEvent)
|
||||
{
|
||||
if (_mouseInside)
|
||||
{
|
||||
if (mouseEvent.IsPressed() && mouseEvent.ButtonMask == MouseButtonMask.Left)
|
||||
{
|
||||
GD.Print("Start Dragging");
|
||||
StartDragging();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_isDragging && @event is InputEventMouseButton { Pressed: false })
|
||||
{
|
||||
GD.Print("Let me free");
|
||||
StopDragging();
|
||||
}
|
||||
}
|
||||
|
||||
public override void _PhysicsProcess(double delta)
|
||||
{
|
||||
_dragTarget = GetGlobalMousePosition();
|
||||
}
|
||||
|
||||
public override void _IntegrateForces(PhysicsDirectBodyState2D state)
|
||||
{
|
||||
if (!_isDragging)
|
||||
return;
|
||||
|
||||
var t = state.Transform;
|
||||
t.Origin = _dragTarget;
|
||||
|
||||
state.Transform = t;
|
||||
state.LinearVelocity = Vector2.Zero;
|
||||
state.AngularVelocity = 0;
|
||||
}
|
||||
|
||||
private void StartDragging()
|
||||
{
|
||||
Freeze = true;
|
||||
_isDragging = true;
|
||||
CollisionLayer = 0;
|
||||
}
|
||||
|
||||
private void StopDragging()
|
||||
{
|
||||
Freeze = false;
|
||||
_isDragging = false;
|
||||
CollisionLayer = 1;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user