Last active
July 2, 2016 07:44
-
-
Save igara/9666cf4ebe440c09d1298f2700a0ff6f to your computer and use it in GitHub Desktop.
UnityのネイティブコードをSwiftで書こうとした時にはまったこと ref: http://qiita.com/igara/items/68b4d3efd53c118339b3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <[Unityのプロジェクト名]-Swift.h> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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_ (); // ネイティブコード上のメソッドを呼び出す | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
#import <[Unityのプロジェクト名]-Swift.h> | |
extern "C"{ | |
void hogeMethod_() { | |
[HogeClass hogeMethod]; // Swiftのメソッドを呼び出す | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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