jacksondunstan/UnityNativeScripting

How to use pure c not c++

mic89 opened this issue · 1 comments

mic89 commented

Hello, How to use pure c not c++

Hi @zmicx, the code generator only generates C++ bindings right now. If you want to use C instead of C++, you can write a thin compatibility layer in your C++ game code using extern "C". For example,

Game.h

#ifdef __cplusplus
extern "C"
{
#endif

void GameObjectNew();

#ifdef __cplusplus
}
#endif

Game.cpp

#include "Game.h"
#include "Bindings.h"

extern "C"
{
    void GameObjectNew(const char* name)
    {
        System::String managedName(name);
        UnityEngine::GameObject go(managedName);
    }
}

Game.c

#include "Game.h"

GameObjectNew("test");