My goal is to get a toy in C ++ library wrapped with SWIG and available for C # / Mono scripts in Unity. (In other words, you have the library functionality working in the Windows build of the game. I will borrow Android as follows :)
I am following the combination of Building a C # module (SWIG tutorial), Unity and DLL (Eric Eastwood) and Getting started with SWiG for Visual Studio projects (technical recipes). I created two DLLs in Visual Studio 2013 and added them to the Unity project. But access to the toy method at run time is not performed.
The steps that I followed (including general corrections for the error I get):
Create C ++ project / custom assembly
- Create a C ++ Win32 Console Application Project in Visual Studio
- (because MonoDevelop on Windows cannot compile C ++)
- Add sample code to the project
- Create example.i (interface file for SWIG)
- Create a custom build tool for the interface file
- Execution of Custom Build Tool (generates shell code for C ++ and C #)
- Add C ++ shell code to the project (it will be used later to create C ++ DLL)
Create C # Project
- Create a C # Class Library Project in Visual Studio
- Change Target Platform Version 3.5
- Add C # shell code files to the project root directory
- Add the following library and namespace files to the C # shell files:
using System;
using System.Runtime.InteropServices;
namespace CSharpExampleLib {
...
}
Build two DLL releases
- Set build options for / x86 for both projects.
- Set a target for C # build for a C ++ build target
- ( DLL, )
- , DLL ()
CorFlags, # DLL 32- () ( / ++ DLL)
DLL Unity
- Unity 4 (Pro) Mono script
- Unity
- DLL "/"
- Unity ( DLL)
- , " MonoDevelop..." ( MonoDevelop script, DLL)
- script:
using System.Runtime.InteropServices;
using System.IO;
DLL
, script # DLL (Intellisense , DLL ):
Debug.Log(CSharpExampleLib.example.fact(3));
, Unity, :
DllNotFoundException: example
CSharpExampleLib.examplePINVOKE+SWIGExceptionHelper..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper
CSharpExampleLib.examplePINVOKE..cctor ()
Rethrow as TypeInitializationException: An exception was thrown by the type initializer for CSharpExampleLib.examplePINVOKE
CSharpExampleLib.example.fact (Int32 n)
SimpleController.Start () (at Assets/scripts/SimpleController.cs:10)
( Release, 32-, Dependency Walker ..) . - SWIG- Unity-, ? , DLL?