Last active
August 29, 2015 14:05
-
-
Save tsubaki/1de75fafc8fa2f25c0e4 to your computer and use it in GitHub Desktop.
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
// | |
// 呼び出されるObjective-Cのクラス | |
// | |
@interface ItemTest : NSObject | |
{ | |
int count; | |
} | |
-(int) ResultCount; | |
@end | |
@implementation ItemTest | |
-(int) ResultCount | |
{ | |
count += 1; | |
return count; | |
} | |
@end |
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.Collections; | |
using ObjC = ObjCMessage; | |
using System; | |
/// | |
/// 呼び出すC#のコード | |
/// | |
public class Test : MonoBehaviour { | |
IntPtr instance; | |
IntPtr classInfo; | |
void Start() | |
{ | |
// instance = [[ItemTest alloc]init]; と同じ | |
classInfo = ObjC.GetClass("ItemTest"); | |
instance = ObjC.MsgSend(ObjC.MsgSend(classInfo, ObjC.Selector ("alloc")), ObjC.Selector ("init")); | |
} | |
void OnGUI () | |
{ | |
if( GUI.Button(new Rect(0, 0, 300, 50), "add") ) | |
{ | |
// [instance ResultCount]; と同じ | |
var result = ObjC.MsgSend( instance, ObjC.Selector("ResultCount")); | |
Debug.Log(result); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment