Added: ScriptingObject* TryFindObject(MClass* mclass), Allow you from c++ to use MAssembly GetBinaryModuleGame, and get a monoobject from a class, monoobject is needed later to Invoke a method from the class.

This commit is contained in:
Preben Eriksen
2022-10-11 10:45:28 +02:00
parent f237d424fa
commit 2efc97b64f
2 changed files with 25 additions and 0 deletions

View File

@@ -868,6 +868,23 @@ ScriptingObject* Scripting::TryFindObject(Guid id, MClass* type)
return result;
}
ScriptingObject* Scripting::TryFindObject(MClass* mclass)
{
if (mclass == nullptr)
return nullptr;
ScopeLock lock(_objectsLocker);
for (auto i = _objectsDictionary.Begin(); i.IsNotEnd(); ++i)
{
const auto obj = i->Value;
if(obj->GetClass() == mclass)
return obj;
}
return nullptr;
}
ScriptingObject* Scripting::FindObject(const MObject* managedInstance)
{
if (managedInstance == nullptr)

View File

@@ -144,6 +144,14 @@ public:
/// <returns>The found object or null if missing.</returns>
static ScriptingObject* FindObject(Guid id, MClass* type = nullptr);
/// <summary>
/// Tries to find the object by the given class.
/// </summary>
/// <returns>The found object or null if missing.</returns>
static ScriptingObject* TryFindObject(MClass* type = nullptr);
/// <summary>
/// Tries to find the object by the given identifier.
/// </summary>