Coder Social home page Coder Social logo

unity-n-native's Introduction

n-native

This is a helper package for working with native code.

Usage

Roughly, define a delegate type matching the C code:

[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
internal delegate int plugin_return_int();

Compile and copy the DLL into the Plugins/ folder and configure it, then use DynamicLibrary to load and execute code from it:

var lib = new DynamicLibrary("libplugin");
var return_int = lib.Symbol<plugin_return_int>();
var val = return_int();

See the tests in the Editor/ folder for each class for full usage examples.

Caveats

Currently only a posix loader is implemented; windows support is still a TODO.

In order to pick an implementation (that will actually compile...) you must define an implementation in:

Player Settings > Other Settings > Scripting Define Symbols

Notice that you can specify multiple targets like this:

FOO;BAR;FOO_BAR

Currently supported implementation targets are:

  • N_NATIVE_IMPL_POSIX

TODO: Refactor and import the LoadLibrary implementation on windows.

Install

From your unity project folder:

npm init
npm install shadowmint/unity-n-native --save
echo Assets/packages >> .gitignore
echo Assets/packages.meta >> .gitignore

The package and all its dependencies will be installed in your Assets/packages folder.

Development

Setup and run tests:

npm install
npm install ..
cd test
npm install
gulp

Remember that changes made to the test folder are not saved to the package unless they are copied back into the source folder.

To reinstall the files from the src folder, run npm install .. again.

Building the plugin

See tests/plugin; compile the shared library and copy it into the Plugins folder. Note that on OSX the shared library must be renamed foo.bundle not foo.dylib.

Tests

All tests are wrapped in #if ... blocks to prevent test spam.

You can enable tests in: Player settings > Other Settings > Scripting Define Symbols

The test key for this package is: N_NATIVE_TESTS

unity-n-native's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.