Skip to content

Instantly share code, notes, and snippets.

@igara
Last active July 2, 2016 07:44
Show Gist options
  • Save igara/9666cf4ebe440c09d1298f2700a0ff6f to your computer and use it in GitHub Desktop.
Save igara/9666cf4ebe440c09d1298f2700a0ff6f to your computer and use it in GitHub Desktop.
UnityのネイティブコードをSwiftで書こうとした時にはまったこと ref: http://qiita.com/igara/items/68b4d3efd53c118339b3
#import <[Unityのプロジェクト名]-Swift.h>
dyld: Library not loaded: @rpath/libswiftCore.dylib
Referenced from: /private/var/mobile/Containers/Bundle/Application/XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX/App-Name.app/App-Name
Reason: image not found
using UnityEngine;
using System.Runtime.InteropServices;
public class HogeClass {
[DllImport("__Internal")] // Unityで提供されているネイティブプラグイン
private static extern void hogeMethod_ (); // ネイティブコード上のメソッド
public static void hogeMethod () {
if (Application.platform != RuntimePlatform.OSXEditor) {
hogeMethod_ (); // ネイティブコード上のメソッドを呼び出す
}
}
}
#import <UIKit/UIKit.h>
#import <[Unityのプロジェクト名]-Swift.h>
extern "C"{
void hogeMethod_() {
[HogeClass hogeMethod]; // Swiftのメソッドを呼び出す
}
}
import UIKit
public class HogeClass: NSObject {
public class func hogeMethod() {
print("hoge") // Xcodeのコンソール上にhogeと表示させる
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment