mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-21 20:08:40 +03:00
work
This commit is contained in:
@@ -82,10 +82,41 @@ namespace Nuake
|
||||
if (!Engine::IsPlayMode())
|
||||
return;
|
||||
|
||||
InitializeNewScripts();
|
||||
|
||||
auto& scriptingEngineNet = ScriptingEngineNet::Get();
|
||||
auto netEntities = m_Scene->m_Registry.view<NetScriptComponent>();
|
||||
|
||||
// Instance all the new entities
|
||||
std::vector<Entity> entityJustInstanced;
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
auto& netScriptComponent = netEntities.get<NetScriptComponent>(e);
|
||||
if (!netScriptComponent.Initialized)
|
||||
{
|
||||
if (netScriptComponent.ScriptPath.empty())
|
||||
continue;
|
||||
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
|
||||
// Creates an instance of the entity script in C#
|
||||
scriptingEngineNet.RegisterEntityScript(entity);
|
||||
|
||||
netScriptComponent.Initialized = true;
|
||||
entityJustInstanced.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
// Call init on the newly created instance
|
||||
for (auto& e : entityJustInstanced)
|
||||
{
|
||||
auto& netScriptComponent = e.GetComponent<NetScriptComponent>();
|
||||
if (e.IsValid() && scriptingEngineNet.HasEntityScriptInstance(e))
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(e);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
|
||||
// Then call update on all the other scripts
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
@@ -180,18 +211,6 @@ namespace Nuake
|
||||
entityJustInstanced.push_back(entity);
|
||||
}
|
||||
}
|
||||
|
||||
// Call init on the newly created instance
|
||||
for (auto& e : entityJustInstanced)
|
||||
{
|
||||
auto& netScriptComponent = e.GetComponent<NetScriptComponent>();
|
||||
if (e.IsValid() && scriptingEngineNet.HasEntityScriptInstance(e))
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(e);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptingSystem::DispatchPhysicCallbacks()
|
||||
|
||||
@@ -301,6 +301,22 @@ namespace Nuake.Net
|
||||
return entity;
|
||||
}
|
||||
|
||||
public T? Instance<T>(Vector3 position = default, Quaternion quat = default) where T : Entity
|
||||
{
|
||||
int handle;
|
||||
unsafe { handle = PrefabInstanceIcall(Path, position, quat.X, quat.Y, quat.Z, quat.W); }
|
||||
|
||||
if (handle == -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
T? instance = Scene.GetEntity<T>(handle);
|
||||
instance.OnInit();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
public static implicit operator bool(Prefab prefab)
|
||||
{
|
||||
if (object.ReferenceEquals(prefab, null))
|
||||
|
||||
@@ -54,7 +54,7 @@ namespace Nuake.Net
|
||||
return entity;
|
||||
}
|
||||
|
||||
public static Entity? InstancePrefab(string path, Entity? parent = null)
|
||||
public static T? InstancePrefab<T>(string path, Entity? parent = null) where T : class
|
||||
{
|
||||
int handle;
|
||||
unsafe { handle = InstancePrefabIcall(path); }
|
||||
@@ -73,9 +73,17 @@ namespace Nuake.Net
|
||||
// return entity as T;
|
||||
//}
|
||||
|
||||
Entity entity = new Entity(handle);
|
||||
|
||||
NativeInstance<Entity> nativeInstance;
|
||||
unsafe { nativeInstance = GetEntityScriptFromHandleIcall(handle); }
|
||||
|
||||
return entity;
|
||||
Entity? entity = nativeInstance.Get();
|
||||
if (entity != null && entity is T)
|
||||
{
|
||||
return entity as T;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user