ComponentCore.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. using System;
  2. using System.Reflection;
  3. using System.Collections.Generic;
  4. using System.Runtime.Loader;
  5. using System.Runtime.InteropServices;
  6. namespace AtomicEngine
  7. {
  8. public partial class CSComponent : ScriptComponent
  9. {
  10. public virtual void Update(float timeStep)
  11. {
  12. }
  13. }
  14. public static class ComponentCore
  15. {
  16. // holds a reference
  17. static Dictionary<IntPtr, CSComponent> liveComponents = new Dictionary<IntPtr, CSComponent>();
  18. public static void Update (float timeStep)
  19. {
  20. foreach (var c in liveComponents.Values)
  21. {
  22. c.Update(timeStep);
  23. }
  24. }
  25. public static IntPtr CSComponentCreate(string assemblyName, string classTypeName)
  26. {
  27. Assembly assembly = AssemblyLoadContext.Default.LoadFromAssemblyName(new AssemblyName(assemblyName));
  28. Type type = assembly.GetType("AtomicNETTest." + classTypeName);
  29. // TODO: check type is derived from CSComponent
  30. var component = (CSComponent) Activator.CreateInstance(type);
  31. liveComponents[component.nativeInstance] = component;
  32. return component.nativeInstance;
  33. }
  34. }
  35. }