Added Entity event OnCollisionEnter2D

This commit is contained in:
Simon Lübeß
2025-08-08 19:09:34 +02:00
parent bf03e99e4a
commit 74243cd285
5 changed files with 35 additions and 2 deletions
+7 -1
View File
@@ -14,7 +14,7 @@ namespace GlitchyEngine;
/// <summary>
/// The base class for all entities and scripts in the current world.
/// </summary>
public class Entity : EngineObject
public partial class Entity : EngineObject
{
/// <summary>
/// Gets or sets the name of the <see cref="Entity"/>.
@@ -451,4 +451,10 @@ public class Entity : EngineObject
/// Will be called once when the entity is being destroyed.
/// </summary>
protected internal virtual void OnDestroy() { }
/// <summary>
/// Will be called
/// </summary>
/// <param name="collision"></param>
protected internal virtual void OnCollisionEnter2D(Collision2D collision) { }
}
+17 -1
View File
@@ -152,7 +152,8 @@ internal static unsafe partial class ScriptGlue
None = 0,
OnCreate = 0x1,
OnUpdate = 0x2,
OnDestroy = 0x4
OnDestroy = 0x4,
OnCollisionEnter2D = 0x8
}
/// <summary>
@@ -210,6 +211,7 @@ internal static unsafe partial class ScriptGlue
methods |= HasMethod(type, nameof(Entity.OnCreate), ScriptMethods.OnCreate);
methods |= HasMethod(type, nameof(Entity.OnUpdate), ScriptMethods.OnUpdate);
methods |= HasMethod(type, nameof(Entity.OnDestroy), ScriptMethods.OnDestroy);
methods |= HasMethod(type, nameof(Entity.OnCollisionEnter2D), ScriptMethods.OnCollisionEnter2D);
bool runInEditMode = type.HasCustomAttribute<RunInEditModeAttribute>();
@@ -309,6 +311,20 @@ internal static unsafe partial class ScriptGlue
Log.Exception(e);
}
}
[UnmanagedCallersOnly(CallConvs = [typeof(CallConvCdecl)])]
public static void InvokeEntityOnCollisionEnter2D(UUID entityId, Collision2D collision)
{
try
{
(Entity entity, Type type) = EntityScriptInstances[entityId];
entity.OnCollisionEnter2D(collision);
}
catch (Exception e)
{
Log.Exception(e);
}
}
[UnmanagedCallersOnly]
public static void InvokeEntityOnDestroy(UUID entityId, byte callDestroy)