DotNet script changes transform

This commit is contained in:
Simon Lübeß
2022-04-27 23:58:50 +02:00
parent 2bac6a8d05
commit 63b9270710
11 changed files with 444 additions and 22 deletions
@@ -1,5 +1,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using DotNetScriptingHelper.Components;
namespace DotNetScriptingHelper;
@@ -9,10 +11,10 @@ public abstract class ScriptableEntity
public virtual void OnCreate() { }
protected virtual void OnDestroy() { }
protected virtual void OnUpdate() { }
protected virtual void OnUpdate(GameTime gameTime) { }
[UnmanagedCallersOnly]
public static IntPtr CreateInstance(IntPtr typeNamePtr, int typeNameLength, EcsEntity entity)
public static IntPtr CreateInstance(IntPtr typeNamePtr, int typeNameLength, EcsEntity entity, IntPtr scene)
{
try
{
@@ -31,7 +33,7 @@ public abstract class ScriptableEntity
if (instance is not ScriptableEntity scriptableEntity)
return IntPtr.Zero;
scriptableEntity.Entity = new Entity(entity);
scriptableEntity.Entity = new Entity(entity, scene);
scriptableEntity.OnCreate();
GCHandle handle = GCHandle.Alloc(instance);
@@ -58,13 +60,39 @@ public abstract class ScriptableEntity
}
[UnmanagedCallersOnly]
public static void UpdateEntity(IntPtr entityPtr)
public static void UpdateEntity(IntPtr entityPtr, ulong frameCount, TimeSpan totalTime, TimeSpan frameTime)
{
GCHandle entityHandle = GCHandle.FromIntPtr(entityPtr);
if (entityHandle.Target is ScriptableEntity entity)
{
entity.OnUpdate();
GameTime gameTime = new GameTime(frameCount, totalTime, frameTime);
entity.OnUpdate(gameTime);
}
}
[DllImport("GlitchyEditor.exe", EntryPoint = "GE_DoStuff")]
static extern int DoStuff();
[DllImport("GlitchyEditor.exe", EntryPoint = "GE_DotNetScript_GetComponent")]
private static extern IntPtr GetComponent(EcsEntity entity, IntPtr scenePtr);
protected TransformComponent GetTransform()// where T : struct
{
IntPtr component = GetComponent(Entity.Handle, Entity.Scene);
return new TransformComponent(component);
//unsafe
//{
// TransformComponent* transform = (TransformComponent*)component;
// return ref *transform;
//}
//GameComponentAttribute? attribute = typeof(T).GetCustomAttribute<GameComponentAttribute>();
//Debug.Assert(attribute != null, $"Requested type {typeof(T)} is not a component.");
}
}