tried to fix bugs (partial success)
This commit is contained in:
@@ -26,23 +26,21 @@ public class GameObject
|
||||
public Transform Transform { get; }
|
||||
public GameObject? Parent;
|
||||
|
||||
public readonly Dictionary<Type, Component> Components = new();
|
||||
public Dictionary<Type, Component> Components = new();
|
||||
|
||||
private GameObject()
|
||||
{
|
||||
}
|
||||
|
||||
private void Init(ulong id, uint nativePoolIndex)
|
||||
private GameObject(ulong id, uint nativePoolIndex)
|
||||
{
|
||||
_id = id;
|
||||
_index = nativePoolIndex;
|
||||
// constructor doesn't work without writing to console
|
||||
// TODO: FIX THIS BULLSHIT
|
||||
Console.WriteLine($"GameObject(id: {id}, nativePoolIndex: {nativePoolIndex})");
|
||||
}
|
||||
|
||||
static public GameObject Create()
|
||||
{
|
||||
NativeMethods.createGameObject(out ulong id, out uint index);
|
||||
var o = new GameObject();
|
||||
o.Init(id, index);
|
||||
var o = new GameObject(id, index);
|
||||
return o;
|
||||
}
|
||||
|
||||
@@ -56,6 +54,9 @@ public class GameObject
|
||||
throw new Exception($"Can't destroy GameObject({_id})");
|
||||
}
|
||||
|
||||
/// <param name="t">type derived from Component</param>
|
||||
/// <returns>true if new component instance was created, false if component of the same tipe is already added to GameObject</returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
public bool TryCreateComponent(Type t)
|
||||
{
|
||||
if(!t.IsSubclassOf(typeof(Component)))
|
||||
@@ -67,12 +68,13 @@ public class GameObject
|
||||
Components.Add(t, (Component)Activator.CreateInstance(t, this));
|
||||
return true;
|
||||
}
|
||||
private bool TryCreateComponent(string fullName)
|
||||
private bool TryCreateComponent_internal(string fullName)
|
||||
{
|
||||
return TryCreateComponent(Type.GetType(fullName));
|
||||
Type t = Type.GetType(fullName) ?? throw new Exception($"type not found '{fullName}'");
|
||||
return TryCreateComponent(t);
|
||||
}
|
||||
|
||||
private void UpdateComponents(double deltaTime)
|
||||
private void InvokeUpdate(double deltaTime)
|
||||
{
|
||||
foreach(var p in Components)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user