-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComponents.cs
More file actions
90 lines (83 loc) · 3.13 KB
/
Components.cs
File metadata and controls
90 lines (83 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
namespace ShibaEngineCore
{
public static class Components
{
/// <summary>
/// Updates the external core component, should be called from the core component bindings when a property is set
/// </summary>
/// <param name="entity"></param>
/// <param name="name"></param>
/// <param name="value"></param>
[MethodImpl(MethodImplOptions.InternalCall)]
public extern static void UpdateExternCoreComponent(uint entity, string name, object value);
public static void UpdateExternCoreComponent<T>(uint entity, T value) where T : CoreComponent
{
UpdateExternCoreComponent(entity, typeof(T).Name, value);
}
/// <summary>
/// Updating a core component on the scripting side to the latest values on the external side, should be called from a core component binding when the get property is called
/// </summary>
/// <param name="entity"></param>
/// <param name="name"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public extern static void UpdateCoreComponent(uint entity, string name);
public static void UpdateCoreComponent<T>(uint entity) where T : CoreComponent
{
UpdateCoreComponent(entity, typeof(T).Name);
}
/// <summary>
/// Getting a reference to the core component from the external side
/// </summary>
/// <param name="entity"></param>
/// <param name="name"></param>
/// <returns></returns>
[MethodImpl(MethodImplOptions.InternalCall)]
public extern static object GetCoreComponent(uint entity, string name);
public static T GetCoreComponent<T>(uint entity) where T : CoreComponent
{
return GetCoreComponent(entity, typeof(T).Name) as T;
}
public static Instance GetInstance(uint entity)
{
return GetEntityInstance(entity) as Instance;
}
[MethodImpl(MethodImplOptions.InternalCall)]
private extern static object GetEntityInstance(uint entity);
}
public class Component
{
public uint entity;
public Transform transform;
public Instance instance;
private void Initialize()
{
transform = Components.GetCoreComponent<Transform>(entity);
System.Console.WriteLine("initialized as " + entity);
instance = Components.GetInstance(entity);
}
}
/// <summary>
/// This is the class that all of the bindings for core components should inherit from
/// </summary>
public class CoreComponent
{
public uint entity;
public void UpdateSelf()
{
Components.UpdateCoreComponent(entity, GetType().Name);
}
public void UpdateExtern()
{
Components.UpdateExternCoreComponent(entity, GetType().Name, this);
}
}
}