jacksondunstan / UnityNativeScripting

Unity Scripting in C++

Home Page:https://jacksondunstan.com/articles/3938

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to use pure c not c++

mic89 opened this issue · comments

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");