Added ability to get other instances of .net scripts using GetEntity<T>
This commit is contained in:
@@ -21,6 +21,7 @@
|
||||
#include "src/Scene/Components/QuakeMap.h"
|
||||
|
||||
#include "src/Physics/PhysicsManager.h"
|
||||
#include "src/Scripting/ScriptingEngineNet.h"
|
||||
|
||||
#include <Coral/Array.hpp>
|
||||
|
||||
@@ -38,6 +39,24 @@ namespace Nuake {
|
||||
return scene->GetEntity(entityName).GetHandle();
|
||||
}
|
||||
|
||||
Coral::ManagedObject GetEntityScript(Coral::String entityName)
|
||||
{
|
||||
auto scene = Engine::GetCurrentScene();
|
||||
if (!scene->EntityExists(entityName))
|
||||
{
|
||||
return Coral::ManagedObject(); // Error code: entity not found.
|
||||
}
|
||||
|
||||
Entity entity = scene->GetEntity(entityName);
|
||||
|
||||
auto& scriptingEngine = ScriptingEngineNet::Get();
|
||||
if (scriptingEngine.HasEntityScriptInstance(entity))
|
||||
{
|
||||
auto instance = scriptingEngine.GetEntityScript(entity);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
static enum ComponentTypes
|
||||
{
|
||||
Unknown = -1,
|
||||
@@ -216,6 +235,7 @@ namespace Nuake {
|
||||
{
|
||||
RegisterMethod("Entity.EntityHasComponentIcall", &EntityHasComponent);
|
||||
RegisterMethod("Scene.GetEntityIcall", &GetEntity);
|
||||
RegisterMethod("Scene.GetEntityScriptIcall", &GetEntityScript);
|
||||
|
||||
// Components
|
||||
RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition);
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace Nuake
|
||||
void ScriptingEngineNet::LoadProjectAssembly(Ref<Project> project)
|
||||
{
|
||||
const std::string sanitizedProjectName = String::Sanitize(project->Name);
|
||||
const std::string assemblyPath = "/bin/Debug/net7.0/" + sanitizedProjectName + ".dll";
|
||||
const std::string assemblyPath = "/bin/Debug/net8.0/" + sanitizedProjectName + ".dll";
|
||||
|
||||
if (!FileSystem::FileExists(assemblyPath))
|
||||
{
|
||||
@@ -223,6 +223,8 @@ namespace Nuake
|
||||
{
|
||||
if (!HasEntityScriptInstance(entity))
|
||||
{
|
||||
std::string name = entity.GetComponent<NameComponent>().Name;
|
||||
Logger::Log(name);
|
||||
Logger::Log("Failed to get entity .Net script instance, doesn't exist", ".net", CRITICAL);
|
||||
return Coral::ManagedObject();
|
||||
}
|
||||
@@ -266,10 +268,10 @@ namespace Nuake
|
||||
const std::string cleanProjectName = String::Sanitize(projectName);
|
||||
const std::string premakeScript = R"(
|
||||
workspace ")" + cleanProjectName + R"("
|
||||
configurations { "Debug", "Release" }
|
||||
project ")" + cleanProjectName + R"("
|
||||
language "C#"
|
||||
dotnetframework "net7.0"
|
||||
|
||||
dotnetframework "net8.0"
|
||||
kind "SharedLib"
|
||||
clr "Unsafe"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user