Last active
          May 12, 2016 07:13 
        
      - 
      
- 
        Save tenntenn/1df6a21e859ce99fdd047e0b7e758e19 to your computer and use it in GitHub Desktop. 
    UnityのネイティブプラグインをGoで書く #golang #unity ref: http://qiita.com/tenntenn/items/4d3316490a571e5d79ed
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | $ CGO_ENABLED=1 \ | |
| CC=arm-linux-androideabi-gcc \ | |
| GOOS=android \ | |
| GOARCH=arm \ | |
| GOARM=7 \ | |
| go build -buildmode=c-shared -o libhoge.so hoge.go | 
  
    
      This file contains hidden or 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
    
  
  
    
  | $ cd $GOROOT/src | |
| $ GOROOT_BOOTSTRAP=/path/to/go1.4/ \ | |
| GOARM=7 \ | |
| CGO_ENABLED=1 \ | |
| GOARCH=arm \ | |
| CC_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh \ | |
| CXX_FOR_TARGET=`pwd`/../misc/ios/clangwrap.sh ./make.bash | 
  
    
      This file contains hidden or 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
    
  
  
    
  | CGO_ENABLED=1 \ | |
| GOARCH=arm \ | |
| go build -buildmode=c-archive -tags=ios hoge.go | 
  
    
      This file contains hidden or 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 Sample : MonoBehaviour | |
| { | |
| #if UNITY_IPHONE | |
| [DllImport("__Internal")] | |
| #else | |
| [DllImport("hoge")] | |
| #endif | |
| private static extern int Hoge(); | |
| void Start() | |
| { | |
| var n = Hoge(); | |
| Debug.LogFormat("n = {0}", n); // n = 100 | |
| } | |
| } | 
  
    
      This file contains hidden or 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
    
  
  
    
  | package main | |
| import "C" | |
| //export Hoge | |
| func Hoge() int { | |
| return 100 | |
| } | |
| func main() { | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment