0
\$\begingroup\$

I need to create a c++ native plugin for my game. If I want to support macOS and Windows, do I need to write my plugin twice - one in XCode with a bundle project and another in VS for windows or is there a way to support both with one codebase?

\$\endgroup\$
1
\$\begingroup\$

Native typically means that made for that target environment. I.e. native for iOS means it will only work on iOS. and native for Android or Windows means it will only run in its respective environment of Android or Windows.

There is no short cut here. The only exception being if you can get Unity directly to do what you need, or technically, if you can find an off the shelf solution that prevents you from having to program anything unique.

\$\endgroup\$
1
\$\begingroup\$

No you dont need separate code base for this. Most of the functionality will probably be the same anyways. Only small parts will have to be different between platforms. In this case you can use C++ macro exclusion blocks to switch these parts between the two.

This way you have a single code base then at compile time you define the proper pre-processor variables to determine which code will be compiled.

// generic code that is not platform specific    

#ifdef MAC_BLOCK
// Mac specific code here
#endif

#ifdef WINDOWS_BLOCK
//windows specific code here
#endif

// non platform specific code again

The blocks of code that the define is not set will simply be ignored by the compiler.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.