mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Added Entity event OnCollisionEnter2D
This commit is contained in:
@@ -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) { }
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user