// ENTITY BASE CLASS
public class Entity {
}
// COMPONENTS (INTERFACES)
public interface ITangibleEntity { }
public interface IModelledEntity : ITangibleEntity { }
public interface IAudibleEntity : ITangibleEntity { }
// COMPONENTS (EXTENSION METHOD IMPLEMENTATIONS)
public static class ComponentExtensions {
// ITangibleEntity
public static Vector3 GetPosition(this ITangibleEntity @this) {
// TODO implement this
}
public static void SetPosition(this ITangibleEntity @this, Vector3 newPosition) {
// TODO implement this
}
public static Vector3 GetVelocity(this ITangibleEntity @this) {
// TODO implement this
}
public static void SetVelocity(this ITangibleEntity @this, Vector3 newVelocity) {
// TODO implement this
}
// IModelledEntity
public static ModelReference GetModel(this IModelledEntity @this) {
// TODO implement this
}
public static void SetModel(this IModelledEntity @this, ModelReference newModel) {
// TODO implement this
}
public static float GetScaling(this IModelledEntity @this) {
// TODO implement this
}
public static void SetScaling(this IModelledEntity @this, float newScaling) {
// TODO implement this
}
public static bool CameraCanSeeThis(this IModelledEntity @this, Camera camera) {
return !PhysicsSystem.RayTest(camera.Position, GetPosition(@this)).IsObscured;
}
// IAudibleEntity
public static SoundReference GetSound(this IModelledEntity @this) {
// TODO implement this
}
public static void SetSound(this IModelledEntity @this, SoundReference newSound) {
// TODO implement this
}
public static float GetSoundRadius(this IModelledEntity @this) {
// TODO implement this
}
public static void SetSoundRadius(this IModelledEntity @this, float newSoundRadius) {
// TODO implement this
}
public static bool CameraCanHearThis(this IModelledEntity @this, Camera camera) {
return GetSoundRadius(@this) > Vector3.Distance(camera.Position, GetPosition(@this));
}
}
Code snippet taken from "Simulating Multiple Inheritance In C#".