Added new Prefab C# type

This commit is contained in:
Antoine Pilote
2024-08-15 22:24:26 -04:00
parent 04926476d7
commit 58a179be4f
8 changed files with 181 additions and 14 deletions

View File

@@ -180,6 +180,7 @@ namespace Nuake
const std::string absoluteAssemblyPath = FileSystem::Root + assemblyPath;
m_GameAssembly = m_LoadContext.LoadAssembly(absoluteAssemblyPath);
m_PrefabType = m_GameAssembly.GetType("Nuake.Net.Prefab");
auto& exposedFieldAttributeType = m_GameAssembly.GetType("Nuake.Net.ExposedAttribute");
for (auto& type : m_GameAssembly.GetTypes())
@@ -235,6 +236,10 @@ namespace Nuake
{
varType = ExposedVarTypes::Entity;
}
else if (typeName == "Nuake.Net.Prefab")
{
varType = ExposedVarTypes::Prefab;
}
if (varType != ExposedVarTypes::Unsupported)
{
@@ -341,6 +346,11 @@ namespace Nuake
int32_t handle;
};
break;
}
case ExposedVarTypes::Prefab:
{
break;
}
}
@@ -385,6 +395,23 @@ namespace Nuake
}
}
}
else if (exposedVarUserValue.Type == NetScriptExposedVarType::Prefab)
{
if (exposedVarUserValue.Value.has_value())
{
std::string path = std::any_cast<std::string>(exposedVarUserValue.Value);
if (FileSystem::FileExists(path))
{
// In the case where the entity doesnt have an instance, we create one
auto newPrefab = m_PrefabType.CreateInstance(Coral::String::New(path));
classInstance.SetFieldValue<Coral::ManagedObject>(exposedVarUserValue.Name, newPrefab);
}
else
{
Logger::Log("Invalid prefab exposed variable set", ".net", CRITICAL);
}
}
}
else
{
classInstance.SetFieldValue(exposedVarUserValue.Name, exposedVarUserValue.Value);