Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/1de75fafc8fa2f25c0e4 to your computer and use it in GitHub Desktop.
Save tsubaki/1de75fafc8fa2f25c0e4 to your computer and use it in GitHub Desktop.
//
// 呼び出されるObjective-Cのクラス
//
@interface ItemTest : NSObject
{
int count;
}
-(int) ResultCount;
@end
@implementation ItemTest
-(int) ResultCount
{
count += 1;
return count;
}
@end
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