mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-06 05:01:53 +00:00
Start of edit mode scripts
- Initialize script instances in edit mode - Run OnCreate and OnUpdate for Entities with RunInEditMode-Attribute
This commit is contained in:
@@ -283,6 +283,8 @@ class ScriptClass : SharpClass
|
||||
typealias OnUpdateMethod = function MonoObject*(MonoObject* instance, float deltaTime, MonoException** exception);
|
||||
typealias OnDestroyMethod = function MonoObject*(MonoObject* instance, MonoException** exception);
|
||||
|
||||
private bool _runInEditMode;
|
||||
|
||||
private MonoMethod* _constructor;
|
||||
|
||||
private OnCreateMethod _onCreate;
|
||||
@@ -300,6 +302,8 @@ class ScriptClass : SharpClass
|
||||
public bool HasCollisionEnter2D => _onCollisionEnter2DMethod != null;
|
||||
public bool HasCollisionLeave2D => _onCollisionLeave2DMethod != null;
|
||||
|
||||
public bool RunInEditMode => _runInEditMode;
|
||||
|
||||
[AllowAppend]
|
||||
public this(StringView classNamespace, StringView className, MonoImage* image, ScriptFieldType scriptFieldType = .Class) :
|
||||
base(classNamespace, className, image, scriptFieldType)
|
||||
@@ -314,6 +318,19 @@ class ScriptClass : SharpClass
|
||||
|
||||
_onCollisionEnter2DMethod = GetMethod("OnCollisionEnter2D", 1);
|
||||
_onCollisionLeave2DMethod = GetMethod("OnCollisionLeave2D", 1);
|
||||
|
||||
DetermineRunInEditMode();
|
||||
}
|
||||
|
||||
/// Determines whether or not scripts of this class will be executed in edit mode.
|
||||
private void DetermineRunInEditMode()
|
||||
{
|
||||
// TODO: This is only relevant for the editor!
|
||||
MonoCustomAttrInfo* attributes = Mono.mono_custom_attrs_from_class(_monoClass);
|
||||
|
||||
if (attributes != null)
|
||||
_runInEditMode = Mono.mono_custom_attrs_has_attr(attributes, ScriptEngine.Attributes.s_RunInEditModeAttribute);
|
||||
|
||||
}
|
||||
|
||||
private MonoMethod* FindConstructor()
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Collections;
|
||||
using GlitchyEngine.Core;
|
||||
using GlitchyEngine.Math;
|
||||
using GlitchyEngine.World;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace GlitchyEngine.Scripting;
|
||||
|
||||
@@ -104,6 +105,7 @@ static class ScriptEngine
|
||||
internal static class Attributes
|
||||
{
|
||||
internal static MonoClass* s_ShowInEditorAttribute;
|
||||
internal static MonoClass* s_RunInEditModeAttribute;
|
||||
}
|
||||
|
||||
public static void Init()
|
||||
@@ -553,7 +555,12 @@ static class ScriptEngine
|
||||
/// Retrieves the classes for Attributes that are defined in the Core library
|
||||
static void GetCoreAttributes()
|
||||
{
|
||||
// We definitely need these attributes!
|
||||
// TODO: Some only for the editor!
|
||||
Attributes.s_ShowInEditorAttribute = Mono.mono_class_from_name(s_CoreAssemblyImage, "GlitchyEngine.Editor", "ShowInEditorAttribute");
|
||||
Debug.Assert(Attributes.s_ShowInEditorAttribute != null);
|
||||
Attributes.s_RunInEditModeAttribute = Mono.mono_class_from_name(s_CoreAssemblyImage, "GlitchyEngine.Editor", "RunInEditModeAttribute");
|
||||
Debug.Assert(Attributes.s_RunInEditModeAttribute != null);
|
||||
}
|
||||
|
||||
private static void GetEntitiesFromAssemblies()
|
||||
|
||||
Reference in New Issue
Block a user