Drag'n'drop for components

+ Added CreateInstance to ScriptClass
+ Added CreateComponentInstance to ScriptInstance
This commit is contained in:
Simon Lübeß
2023-07-25 16:37:41 +02:00
parent 37197cbdf1
commit 81a61d5a90
7 changed files with 110 additions and 30 deletions
@@ -70,4 +70,19 @@ class ScriptInstance : RefCounter
{
_scriptClass.SetFieldValue<T>(_instance, field.[Friend]_monoField, value);
}
/// Creates a new instance of the given component class and initializes it for the current entity.
public MonoObject* CreateComponentInstance(ScriptClass componentClassType)
{
MonoObject* componentInstance = componentClassType.CreateInstance();
// TODO: We could cache the property, but this might be fine
MonoProperty* entityProperty = Mono.mono_class_get_property_from_name(componentClassType.[Friend]_monoClass, "Entity");
MonoObject* exception = null;
Mono.mono_property_set_value(entityProperty, componentInstance, (void**)&_instance, &exception);
return componentInstance;
}
}