mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added ShowMouse and get global position to .net api, deferred onInit after all entities have been initialized
This commit is contained in:
@@ -52,13 +52,22 @@ namespace Nuake
|
||||
if (netScriptComponent.ScriptPath.empty())
|
||||
continue;
|
||||
|
||||
// Creates an instance of the entity script in C#
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
scriptingEngineNet.RegisterEntityScript(entity);
|
||||
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
// Creates an instance of the entity script in C#
|
||||
scriptingEngineNet.RegisterEntityScript(entity);
|
||||
}
|
||||
|
||||
for (auto& e : netEntities)
|
||||
{
|
||||
auto entity = Entity{ e, m_Scene };
|
||||
|
||||
if (entity.IsValid() && scriptingEngineNet.HasEntityScriptInstance(entity))
|
||||
{
|
||||
// We can now call on init on it.
|
||||
auto scriptInstance = scriptingEngineNet.GetEntityScript(entity);
|
||||
scriptInstance.InvokeMethod("OnInit");
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -6,6 +6,18 @@
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
void ShowMouse(bool visible)
|
||||
{
|
||||
if (visible)
|
||||
{
|
||||
Input::ShowMouse();
|
||||
}
|
||||
else
|
||||
{
|
||||
Input::HideMouse();
|
||||
}
|
||||
}
|
||||
|
||||
bool IsKeyDown(int keyCode)
|
||||
{
|
||||
return Input::IsKeyDown(keyCode);
|
||||
@@ -25,6 +37,7 @@ namespace Nuake {
|
||||
|
||||
void InputNetAPI::RegisterMethods()
|
||||
{
|
||||
RegisterMethod("Input.ShowMouseIcall", &ShowMouse);
|
||||
RegisterMethod("Input.IsKeyDownIcall", &IsKeyDown);
|
||||
RegisterMethod("Input.IsKeyPressedIcall", &IsKeyPressed);
|
||||
|
||||
|
||||
@@ -115,6 +115,19 @@ namespace Nuake {
|
||||
}
|
||||
}
|
||||
|
||||
Coral::NativeArray<float> TransformGetGlobalPosition(int entityId)
|
||||
{
|
||||
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
|
||||
|
||||
if (entity.IsValid() && entity.HasComponent<TransformComponent>())
|
||||
{
|
||||
auto& component = entity.GetComponent<TransformComponent>();
|
||||
const auto& globalPosition = component.GetGlobalPosition();
|
||||
Coral::NativeArray<float> result = { globalPosition.x, globalPosition.y, globalPosition.z };
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void TransformRotate(int entityId, float x, float y, float z)
|
||||
{
|
||||
Entity entity = { (entt::entity)(entityId), Engine::GetCurrentScene().get() };
|
||||
@@ -203,6 +216,7 @@ namespace Nuake {
|
||||
|
||||
// Components
|
||||
RegisterMethod("TransformComponent.SetPositionIcall", &TransformSetPosition);
|
||||
RegisterMethod("TransformComponent.GetGlobalPositionIcall", &TransformGetGlobalPosition);
|
||||
RegisterMethod("TransformComponent.RotateIcall", &TransformRotate);
|
||||
|
||||
RegisterMethod("CameraComponent.GetDirectionIcall", &CameraGetDirection);
|
||||
|
||||
@@ -223,7 +223,7 @@ namespace Nuake
|
||||
if (!HasEntityScriptInstance(entity))
|
||||
{
|
||||
Logger::Log("Failed to get entity .Net script instance, doesn't exist", ".net", CRITICAL);
|
||||
throw std::exception("Failed to get entity .Net script instance, doesn't exist");
|
||||
return Coral::ManagedObject();
|
||||
}
|
||||
|
||||
return m_EntityToManagedObjects[entity.GetID()];
|
||||
|
||||
@@ -39,6 +39,7 @@ namespace Nuake.Net
|
||||
|
||||
public class TransformComponent : IComponent
|
||||
{
|
||||
internal static unsafe delegate*<int, NativeArray<float>> GetGlobalPositionIcall;
|
||||
internal static unsafe delegate*<int, float, float, float, void> SetPositionIcall;
|
||||
internal static unsafe delegate*<int, float, float, float, void> RotateIcall;
|
||||
|
||||
@@ -76,7 +77,18 @@ namespace Nuake.Net
|
||||
unsafe { SetPositionIcall(EntityID, value.X, value.Y, value.Z); }
|
||||
}
|
||||
}
|
||||
public Vector3 GlobalPosition { get; set; }
|
||||
public Vector3 GlobalPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
NativeArray<float> result = GetGlobalPositionIcall(EntityID);
|
||||
return new Vector3(result[0], result[1], result[2]);
|
||||
}
|
||||
}
|
||||
set { }
|
||||
}
|
||||
}
|
||||
|
||||
public class LightComponent : IComponent
|
||||
|
||||
@@ -134,10 +134,16 @@ namespace Nuake.Net
|
||||
|
||||
public class Input
|
||||
{
|
||||
internal static unsafe delegate*<bool, void> ShowMouseIcall;
|
||||
internal static unsafe delegate*<int, bool> IsKeyDownIcall;
|
||||
internal static unsafe delegate*<int, bool> IsKeyPressedIcall;
|
||||
internal static unsafe delegate*<NativeArray<float>> GetMousePositionIcall;
|
||||
|
||||
public static void ShowMouse(bool visible)
|
||||
{
|
||||
unsafe { ShowMouseIcall(visible); }
|
||||
}
|
||||
|
||||
public static bool IsKeyDown(Key keys)
|
||||
{
|
||||
unsafe { return IsKeyDownIcall((int)keys); }
|
||||
|
||||
Reference in New Issue
Block a user