fix IDrawableComponent throwing if non auto property used for Layer
parent
59014c7a9e
commit
4fea2cf4e1
|
@ -26,7 +26,8 @@ namespace Encompass
|
|||
|
||||
foreach (var type in _componentTypes)
|
||||
{
|
||||
var instanceParam = new object[] { Entity, Activator.CreateInstance(type) };
|
||||
var instance = Activator.CreateInstance(type);
|
||||
var instanceParam = new object[] { Entity, instance };
|
||||
var setComponentMethod = typeof(Engine).GetMethod("SetComponent", BindingFlags.NonPublic | BindingFlags.Instance);
|
||||
var genericSetComponentMethod = setComponentMethod.MakeGenericMethod(type);
|
||||
genericSetComponentMethod.Invoke(this, instanceParam);
|
||||
|
|
|
@ -418,6 +418,11 @@ namespace Encompass
|
|||
|
||||
if (componentType.GetInterface("IDrawableComponent") != null)
|
||||
{
|
||||
// register draw layer using property value
|
||||
var instance = Activator.CreateInstance(componentType);
|
||||
var layerPropertyInfo = componentType.GetProperty("Layer");
|
||||
dummyDrawLayerManager.RegisterDrawLayer((int)layerPropertyInfo.GetValue(instance));
|
||||
|
||||
var drawLayerManagerRegisterMethod = typeof(DrawLayerManager).GetMethod("RegisterOrderedDrawable");
|
||||
var drawLayerManagerRegisterGenericMethod = drawLayerManagerRegisterMethod.MakeGenericMethod(componentType);
|
||||
drawLayerManagerRegisterGenericMethod.Invoke(dummyDrawLayerManager, null);
|
||||
|
|
|
@ -563,15 +563,24 @@ namespace Tests
|
|||
{
|
||||
struct AComponent : IComponent, IDrawableComponent
|
||||
{
|
||||
public int Layer { get; set; }
|
||||
public int Layer { get; }
|
||||
}
|
||||
|
||||
struct BComponent : IComponent, IDrawableComponent
|
||||
{
|
||||
public int Layer { get => 3; }
|
||||
}
|
||||
|
||||
class ARenderer : OrderedRenderer<AComponent>
|
||||
{
|
||||
|
||||
public override void Render(Entity entity, in AComponent drawComponent) { }
|
||||
}
|
||||
|
||||
class BRenderer : OrderedRenderer<BComponent>
|
||||
{
|
||||
public override void Render(Entity entity, in BComponent drawComponent) { }
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawLayerRegisterAfterOrderedRendererRegisterThrows()
|
||||
{
|
||||
|
@ -590,6 +599,16 @@ namespace Tests
|
|||
Assert.DoesNotThrow(() => worldBuilder.RegisterDrawLayer(1));
|
||||
Assert.DoesNotThrow(() => worldBuilder.AddOrderedRenderer(new ARenderer()));
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DrawLayerWithProperty()
|
||||
{
|
||||
var worldBuilder = new WorldBuilder();
|
||||
|
||||
var rendererB = worldBuilder.AddOrderedRenderer(new BRenderer());
|
||||
|
||||
Assert.DoesNotThrow(() => worldBuilder.Build());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue