From 88558f29b08f22a0aa4e0dc277b096cad73826ed Mon Sep 17 00:00:00 2001 From: Linus Date: Fri, 25 Mar 2016 18:20:34 +0100 Subject: [PATCH] Added abstract WrapperComponent class --- .../Providers/TypeReflectionProvider.cs | 1 + Entitas/Entitas/WrapperComponent.cs | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 Entitas/Entitas/WrapperComponent.cs diff --git a/Entitas/Entitas/CodeGenerator/Providers/TypeReflectionProvider.cs b/Entitas/Entitas/CodeGenerator/Providers/TypeReflectionProvider.cs index a3170ceb4..bfdf07f26 100644 --- a/Entitas/Entitas/CodeGenerator/Providers/TypeReflectionProvider.cs +++ b/Entitas/Entitas/CodeGenerator/Providers/TypeReflectionProvider.cs @@ -20,6 +20,7 @@ public TypeReflectionProvider(Type[] types, string[] poolNames) { public static ComponentInfo[] GetComponentInfos(Type[] types) { return types .Where(type => !type.IsInterface) + .Where(type => !type.IsAbstract) .Where(type => type.GetInterfaces().Any(i => i.FullName == "Entitas.IComponent")) .Select(type => CreateComponentInfo(type)) .ToArray(); diff --git a/Entitas/Entitas/WrapperComponent.cs b/Entitas/Entitas/WrapperComponent.cs new file mode 100644 index 000000000..25319b07b --- /dev/null +++ b/Entitas/Entitas/WrapperComponent.cs @@ -0,0 +1,23 @@ +namespace Entitas { + + /// Inherit from this class if you want a component that is just a wrapper for some type. + /// All attributes that work for normal components also work for components that inherit from this class. + /// The body of the inheriting class should remain empty. + /// Example use: + /// + /// // definition + /// public class NameComponent : WrapperComponent<string> { } + /// + /// // usage (after generator has run) + /// public string PhoneNumber(Entity e, Dictionary<string, string> phoneBook) { + /// if(e.Name == "Bob") { return "012 333 4545"; } + /// + /// return phoneBook[e.Name]; + /// } + /// + public abstract class WrapperComponent : IComponent { + public T value; + + public static implicit operator T(WrapperComponent component) { return component.value; } + } +}