I’m trying to keep my game logic API-agnostic. In doing so, I don’t want to use Unity3D’s Vector3 struct, or XNA’s, etc. What’s the best way to do this? It seems like it would be awfully cast-heavy if I rolled my own Vector3 struct and just wrote implicit converters to the various API implementations.
Is there a best practice for this kind of thing? It’s not like I can ask Microsoft, Unity, etc. to have a picnic and adhere to a common interface.
It looks like XNA and Unity implementations of
Vector3are really similar, the main difference being the case of property names. Too bad there’s no way to implement extension properties.What you could do is create a set of extension methods, together with some conditional compilation (
#if UNITY_3_3or#if XNA) and exclusively use those extension methods to retrieve values in your API agnostic code. This would still allow you to pass the Vector3 object unmodified to platform specific code requiring Vector3’s without tons of casting.