Last active
April 27, 2016 14:52
-
-
Save JamesMcMahon/d344afc1e7305bb5cbeec52786b74594 to your computer and use it in GitHub Desktop.
WrapperComponent for Entitas, https://github.com/sschmid/Entitas-CSharp/pull/88. Storing here just in case the branch gets deleted.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: | |
/// <example> | |
/// // 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]; | |
/// } | |
/// </example> | |
public abstract class WrapperComponent<T> : IComponent { | |
public T value; | |
public static implicit operator T(WrapperComponent<T> component) { return component.value; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment