API agnostic Vector3, Matrix, etc.?

I am trying to keep the API logic API agnostic. However, I do not want to use Unity3D Vector3 struct or XNA, etc. What is the best way to do this? It seems like it would be terribly hard if I deployed my own Vector3 structure and just wrote implicit converters for various API implementations.

Is there any best practice for this kind of thing? It doesn't look like I can ask for Microsoft, Unity, etc. Have a picnic and stick to a common interface.

+4
source share
2 answers

It looks like the XNA and Unity implementations of Vector3 really similar, the main difference is the property names. It is a pity that there is no way to implement the properties of the extension.

What you can do is create a set of extension methods along with some conditional compilation ( #if UNITY_3_3 or #if XNA ) and exclusively use these extension methods to retrieve values ​​in the agnostic API code. This will still allow you to pass the Vector3 object unmodified into the code of a specific platform, requiring Vector3 without a ton of casting.

+3
source

Based on my experience, I would choose one platform for writing your logic, and then, on another platform, create an appropriate implementation with conversions to the native types of the platform. It makes no sense to develop and record a third implementation, and then do conversions on both platforms!

All platforms are equal, I probably would prefer XNA, as you can grab the open source implementation from MonoGame or (ultimately) ExEn and use this.

However, in practice, I think that it is probably best for you to start working with the platform on which you intend to develop (XNA or Unity), and then create your level of compatibility when you really need it.

+2
source

Source: https://habr.com/ru/post/1343584/


All Articles