something something

This commit is contained in:
2026-01-09 11:57:24 +05:00
parent 175fe61e5c
commit 346779060e
5 changed files with 34 additions and 13 deletions

View File

@@ -41,6 +41,7 @@ public class GameObject
{
NativeFunctions.createGameObject(out ulong id, out uint index);
var o = new GameObject(id, index);
Console.WriteLine($"C# created object with id {id}, index {index}");
return o;
}
@@ -54,18 +55,24 @@ public class GameObject
throw new Exception($"Can't destroy GameObject({_id})");
}
~GameObject()
{
// destroys object native part when managed part is garbage-collected
Destroy();
}
/// <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)))
if (!t.IsSubclassOf(typeof(Component)))
throw new Exception($"type {t.FullName} is not a derived class of {typeof(Component).FullName}");
if(Components.ContainsKey(t))
if (Components.ContainsKey(t))
return false;
Component component = (Component?)Activator.CreateInstance(t, this)
Component component = (Component?)Activator.CreateInstance(t, this)
?? throw new Exception($"can't create instance of class {t.FullName}");
Components.Add(t, component);
return true;
@@ -78,7 +85,9 @@ public class GameObject
private void InvokeUpdate(double deltaTime)
{
foreach(var p in Components)
Console.WriteLine("C# InvokeUpdate");
Console.WriteLine($"id {_id}, index {_index}, destroyed {_isDestroyed}");
foreach (var p in Components)
{
p.Value.Update(deltaTime);
}