だから私はc#コードをユニティで伝え、ObjectiveCコードをXcodeで伝えようとしています。これが私のコードです:
text.h
extern "C" {
int textTotexture(int hello,int world);
}
text.mm
int textTotexture(int hello,int world){
NSString *myString =[[NSString alloc] init];
NSSize size = [myString sizeWithAttributes:0];
NSImage* newImage = [[NSImage alloc] initWithSize: size];
[newImage lockFocus];
/* if you have a second image you're going to overlay on top of the first, do the same except use NSCompositeSourceOver as the operation */
//NSRect myRect = NSMakeRect(0,0,size.width,size.height);
//[myString drawInRect:myRect withAttributes:0];
[newImage unlockFocus];
//NSData *imageData = [newImage TIFFRepresentation];
//NSBitmapImageRep *imageRep = [NSBitmapImageRep imageRepWithData:imageData];
//NSDictionary *imageProps = [NSDictionary dictionaryWithObject:[NSNumber numberWithFloat:1.0] forKey:NSImageCompressionFactor];
//imageData = [imageRep representationUsingType:NSPNGFileType properties:imageProps];
//int len = [imageData length];
//memcpy(data, [imageData bytes], len);
return hello+world;
}
関数の呼び出し:
[DllImport("CubePlugin")]
public static extern int textTotexture(int s, int w);
Debug.Log(textTotexture(1,2));
デバッグログが3を返すので、基本的な通信は問題ありませんが、関数型コードを追加するとすぐに、ユニティがクラッシュします。ネイティブコードの一部が最後まで実行されないのではないかと思います。
ロックフォーカスを追加してフォーカスを失ったときに問題が発生することがわかりました。これを回避し、目標を達成するにはどうすればよいですか?