45 lines
1.5 KiB
C#
45 lines
1.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Reflection;
|
|
|
|
namespace Encompass
|
|
{
|
|
class UberRenderer : Renderer
|
|
{
|
|
private readonly IEnumerable<Type> _componentTypes;
|
|
private Entity _entity;
|
|
|
|
public UberRenderer(IEnumerable<Type> componentTypes)
|
|
{
|
|
_componentTypes = componentTypes;
|
|
}
|
|
|
|
public void SetEntity(Entity entity)
|
|
{
|
|
_entity = entity;
|
|
}
|
|
|
|
// can't reflect invoke on Span returns...
|
|
public void Render()
|
|
{
|
|
foreach (var type in _componentTypes)
|
|
{
|
|
// CallGenericMethod(type, "ReadEntities", null);
|
|
CallGenericMethod(type, "ReadEntity", null);
|
|
// CallGenericMethod(type, "ReadComponents", null);
|
|
CallGenericMethod(type, "ReadComponent", null);
|
|
CallGenericMethod(type, "GetComponent", new object[] { _entity });
|
|
CallGenericMethod(type, "HasComponent", new object[] { _entity });
|
|
CallGenericMethod(type, "SomeComponent", null);
|
|
}
|
|
}
|
|
|
|
private void CallGenericMethod(Type type, string methodName, object[] parameters)
|
|
{
|
|
var readComponentMethod = typeof(Renderer).GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance);
|
|
var genericReadComponentMethod = readComponentMethod.MakeGenericMethod(type);
|
|
genericReadComponentMethod.Invoke(this, parameters);
|
|
}
|
|
}
|
|
}
|