Added new Prefab C# type
This commit is contained in:
@@ -206,6 +206,23 @@ namespace Nuake {
|
||||
return entity.IsValid();
|
||||
}
|
||||
|
||||
int PrefabInstance(Coral::String path, Vector3 position, float qx, float qy, float qz, float qw)
|
||||
{
|
||||
if (!FileSystem::FileExists(path))
|
||||
{
|
||||
Logger::Log("Prefab path doesn't exist", ".net", CRITICAL);
|
||||
}
|
||||
|
||||
const auto& prefab = Prefab::New(path);
|
||||
|
||||
Entity root = prefab->Root;
|
||||
TransformComponent& transformComponent = root.GetComponent<TransformComponent>();
|
||||
transformComponent.SetLocalPosition(position);
|
||||
transformComponent.SetLocalRotation(Quat(qw, qx, qy, qz));
|
||||
|
||||
return root.GetHandle();
|
||||
}
|
||||
|
||||
void TransformSetPosition(int entityId, float x, float y, float z)
|
||||
{
|
||||
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
|
||||
@@ -369,6 +386,9 @@ namespace Nuake {
|
||||
RegisterMethod("Entity.EntitySetNameIcall", &EntitySetName);
|
||||
RegisterMethod("Entity.EntityIsValidIcall", &EntityIsValid);
|
||||
|
||||
// Prefab
|
||||
RegisterMethod("Prefab.PrefabInstanceIcall", &PrefabInstance);
|
||||
|
||||
// Scene
|
||||
RegisterMethod("Scene.GetEntityIcall", &GetEntity);
|
||||
RegisterMethod("Scene.GetEntityScriptFromNameIcall", &GetEntityScriptFromName);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -24,6 +24,7 @@ namespace Nuake {
|
||||
Double,
|
||||
String,
|
||||
Entity,
|
||||
Prefab,
|
||||
Vector2,
|
||||
Vector3,
|
||||
Vector4,
|
||||
@@ -52,6 +53,7 @@ namespace Nuake {
|
||||
const std::string m_ContextName = "NuakeEngineContext";
|
||||
|
||||
Coral::Type m_BaseEntityType;
|
||||
Coral::Type m_PrefabType;
|
||||
bool m_IsInitialized = false;
|
||||
|
||||
Coral::HostInstance* m_HostInstance;
|
||||
|
||||
Reference in New Issue
Block a user