Skip to content

Commit 5d62e02

Browse files
committed
GameFramework: C# Implementation of Transforms almost finished
1 parent 9a4a6bb commit 5d62e02

File tree

5 files changed

+44
-9
lines changed

5 files changed

+44
-9
lines changed

src/Managed/ExeonScript.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ public static void Init()
99
{
1010
Scene sampleScene = SceneManager.GetScene("SampleScene");
1111

12-
Console.Debug(sampleScene.ObjectExists("Sponza Atrium").ToString());
12+
Console.Debug("C# Scripting working");
13+
GameObject obj = sampleScene.GetObject("Sponza Atrium");
14+
Transform transform = obj.transform;
15+
Console.Debug(transform.location.x.ToString());
1316
}
1417
}
1518
}

src/Managed/Math/Transform.cs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,46 @@
11
using System;
2+
using System.Linq.Expressions;
23
using System.Runtime.CompilerServices;
4+
using System.Runtime.InteropServices;
35
using Exeon;
46

7+
[StructLayout(LayoutKind.Sequential)]
8+
struct CVector3
9+
{
10+
public float x;
11+
public float y;
12+
public float z;
13+
}
14+
15+
516
namespace Exeon
617
{
718
public class Transform
819
{
920

1021
[MethodImpl(MethodImplOptions.InternalCall)]
11-
private static extern Vector3 GetLocation_Impl(UIntPtr ptr);
22+
private static extern CVector3 GetLocation_Impl(UIntPtr ptr);
23+
24+
private Vector3 GetLocation(UIntPtr ptr)
25+
{
26+
Vector3 v = new Vector3();
27+
CVector3 cv = GetLocation_Impl(ptr);
28+
v.x = cv.x;
29+
v.y = cv.y;
30+
v.z = cv.z;
31+
32+
return v;
33+
}
1234

1335
private UIntPtr nativePtr;
1436
public Transform(UIntPtr ptr)
1537
{
1638
this.nativePtr = ptr;
1739
}
1840

19-
public Vector3 Location
41+
public Vector3 location
2042
{
21-
get => GetLocation_Impl(this.nativePtr);
43+
get => GetLocation(this.nativePtr);
2244
}
2345
}
2446
}

src/private/Runtime/GameObjectImpl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ extern "C" uintptr_t GameObject_GetTransform(uintptr_t ptr) {
77
return pTransform;
88
}
99

10-
extern "C" uintptr_t Transform_GetLocation(uintptr_t ptr) {
11-
Transform* trasnform = reinterpret_cast<Transform*>(ptr);
12-
uintptr_t pLocation = reinterpret_cast<uintptr_t>(&trasnform->location);
13-
return pLocation;
10+
extern "C" CVector3 Transform_GetLocation(uintptr_t ptr) {
11+
Transform* transform = reinterpret_cast<Transform*>(ptr);
12+
Vector3 loc = transform->location;
13+
CVector3 vec(loc.x, loc.y, loc.z);
14+
return vec;
1415
}

src/private/Runtime/MonoScript.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ void MonoScript::Init() {
4848
mono_add_internal_call("Exeon.Scene::GetObject_Impl", reinterpret_cast<const void*>(Scene_GetObject));
4949
mono_add_internal_call("Exeon.Scene::ObjectExists_Impl", reinterpret_cast<const void*>(Scene_ObjectExists));
5050
mono_add_internal_call("Exeon.GameObject::GetTransform_Impl", reinterpret_cast<const void*>(GameObject_GetTransform));
51+
mono_add_internal_call("Exeon.Transform::GetLocation_Impl", reinterpret_cast<const void*>(Transform_GetLocation));
5152

5253
mono_runtime_invoke(initMethod, nullptr, nullptr, nullptr);
5354
}

src/public/Runtime/GameObjectImpl.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,15 @@
33
#include "Core/GameObject/GameObject.h"
44
#include <mono/jit/jit.h>
55

6+
7+
68
extern "C" {
9+
struct CVector3 {
10+
float x;
11+
float y;
12+
float z;
13+
};
14+
715
uintptr_t GameObject_GetTransform(uintptr_t ptr);
8-
uintptr_t Transform_GetLocation(uintptr_t ptr);
16+
CVector3 Transform_GetLocation(uintptr_t ptr);
917
}

0 commit comments

Comments
 (0)