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
@@ -66,8 +66,13 @@ namespace Sandbox
Log.Info($"Jump Force: {JumpForce}");
_rigidBody ??= GetComponent<RigidBody2D>() ?? AddComponent<RigidBody2D>();
//_rigidBody ??= GetComponent<RigidBody2D>() ?? AddComponent<RigidBody2D>();
if (_rigidBody == null)
{
Log.Error("_rigidBody was not set in editor.");
}
if (Camera == null)
{
Log.Warning("Camera wasn't set in editor. Searching...");
+16 -16
View File
@@ -72,7 +72,7 @@
Color = {
R = 1,
G = 0.941887021,
B = 0.401484519,
B = 0.401484489,
A = 1
},
Sprite = "",
@@ -162,7 +162,7 @@
OrthographicHeight = 10,
OrthographicNearPlane = 0,
OrthographicFarPlane = 10,
AspectRatio = 1.17151165,
AspectRatio = 2.05582929,
FixedAspectRatio = false
},
ScriptComponent = {
@@ -195,8 +195,8 @@
},
TransformComponent = {
Position = {
X = -0.121203199,
Y = 0.660161018,
X = -0.121203206,
Y = 0.660161078,
Z = 0
},
Rotation = {
@@ -234,7 +234,7 @@
ScriptComponent = {
ScriptClass = "Sandbox.MyTestEntity",
Fields = [
_rigidBody = (Component)0,
_rigidBody = (Component)15710354273720487680,
TheEntity = (Entity)0,
JumpForce = (Float)200,
MoveForce = (Float)148,
@@ -276,7 +276,7 @@
Color = {
R = 0.985467017,
G = 1,
B = 0.569977999
B = 0.569977939
}
}
},
@@ -323,8 +323,8 @@
SpriteRendererComponent = {
Color = {
R = 0.425658971,
G = 0.855207503,
B = 0.0558161139,
G = 0.855207443,
B = 0.0558161177,
A = 1
},
Sprite = "",
@@ -338,14 +338,14 @@
TransformComponent = {
Position = {
X = 6.74610233,
Y = -2.03225923,
Y = -2.03225946,
Z = 0
},
Rotation = {
X = 0,
Y = 0,
Z = -0.331792623,
W = 0.943352461
W = 0.94335258
},
Scale = {
X = 5.29557419,
@@ -399,8 +399,8 @@
},
TransformComponent = {
Position = {
X = 15.2321291,
Y = -1.98709261,
X = 15.2321281,
Y = -1.98709273,
Z = 0
},
Rotation = {
@@ -410,7 +410,7 @@
W = 0.990847468
},
Scale = {
X = 13.9764547,
X = 13.9764528,
Y = 1,
Z = 1
},
@@ -462,13 +462,13 @@
TransformComponent = {
Position = {
X = -6.27842855,
Y = 2.62550187,
Y = 2.62550163,
Z = 0
},
Rotation = {
X = 0,
Y = 0,
Z = 0.187087849,
Z = 0.187087879,
W = 0.982343197
},
Scale = {
@@ -497,7 +497,7 @@
},
Density = 1,
Friction = 0.5,
Restitution = 0.899999917,
Restitution = 0.899999857,
RestitutionThreshold = 0.5
}
}
@@ -817,11 +817,22 @@ namespace GlitchyEditor.EditWindows
// TODO: I don't like the fact, that we are using mono directly
ScriptField scriptField = scriptClass.Fields[fieldName];
MonoReflectionType* reflectionType = Mono.mono_type_get_object(ScriptEngine.[Friend]s_AppDomain, scriptField.GetMonoType());
// TODO: We shouldn't abuse the script glue like that...
// ScriptGlue should only be called by C#, not by Beef...
allowDrop = ScriptGlue.[Friend]Entity_HasComponent(draggedEntity.UUID, reflectionType);
// For some reason we have to retrieve the MonoType like this. Using scriptField.GetMonoType() directly returns the wrong type...
MonoReflectionType* reflectionType = Mono.mono_type_get_object(ScriptEngine.[Friend]s_AppDomain, scriptField.GetMonoType());
MonoType* actualMonoType = Mono.mono_reflection_type_get_type(reflectionType);
// TODO: We shouldn't abuse the script glue like that.
// ScriptGlue should only be called by C#, not by Beef.
if (ScriptGlue.[Friend]s_HasComponentMethods.TryGetValue(actualMonoType, let has_component))
{
allowDrop = has_component(draggedEntity);
}
else
{
Log.EngineLogger.Warning($"No HasComponent-Function found for field {scriptField.Name}");
allowDrop = false;
}
}
if (allowDrop)