profelis / unity_plugin

Native plugin for Unity3D (sample)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Native plugin for Unity3D (sample)

Native plugin for "all" unity targets with shared c++ code.

Main features

  • Supports macOS (+editor), Windows (+UWP) (+editor), iOS, Android, WebGL
  • Simple and clear build process
  • Shared c++ code
  • Shared Objective-C code for ios and mac targets
  • Shared Swift code for ios and mac targets
  • Debug/Release configuration
  • Raw source code sample for iOS/WebGL target (useful for debug)
  • Marshaling samples (strings, arrays, structs), manual marshaling

Compiling

I compile all targets on macOS and use Windows only for windows targets.

macOS

  • Setup environment variable ANDROID_NDK_HOME target to Android NDK
  • Open plugin folder
  • run buildall.sh, special params [-w add swift sample code] [-x generate xcode projects] [-r Release configuration] [-s copy sources for iOS target (useful for debug)] [-l webgl build]

Swift

  • Define SWIFT in Unity Player Settings window - Scripting Define Symbols setting
  • Swift target copy additional files in project, feel free to edit or remove them. Dummy.swift can be removed if you have another *.swift files. SwiftPostProcessor.cs configures Xcode project.

MacOS(+editor) dylibs are huge because contains all swift dylibs (see ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES)

WebGL static library (WIP)

Can't get working *.bc library right now (WIP)

opt: error loading file '<projectpath>/Assets/Plugins/unity_plugin/webgl/libunity_plugin.bc'ERROR:root:Failed to run llvm optimizations: 
   UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)
  • Install Emscripten
  • Activate Emscripten source ./emsdk_env.sh

WebGL sources

buildall.sh -l -s works perfect, some include directives fail sometimes, simple place all *.cpp and *.h files in root Plugins folder

Windows

  • Install CMake 3.6+, MSVS, UWP SDK (optional)
  • Open plugin folder
  • run buildall.bat, special params [-r Release configuration]

make or MSVS or Xcode

See plugin/buildall.[sh|bat] for more information.

More info

iOS & MacOS

Android

WebGL

Marshaling

Todo

  • [android] test x86 library
  • [webgl] static library

About

Native plugin for Unity3D (sample)

License:MIT License


Languages

Language:CMake 42.6%Language:C# 20.5%Language:Shell 7.7%Language:C 7.3%Language:Objective-C++ 7.0%Language:C++ 5.3%Language:Swift 4.2%Language:Batchfile 3.3%Language:Objective-C 2.1%