iPhone/iPadã®ãã©ã°ã¤ã³ãä½æããæ¹æ³(æ¹è¨ç)
â»以前作成したエントリーã§ã¯ Plugins/iOS ãã©ã«ãã使ã£ã¦èªåçã«Xcodeããã¸ã§ã¯ãã«ãã¡ã¤ã«ã«å«ããæ¹æ³ã使ã£ã¦ç¡ãã£ãã®ã§ä½¿ãæ§ã«ä¿®æ£ã
â»ã½ã¼ã¹ã³ã¼ããGitHubããã®é
å¸ã«å¤æ´ã
UnityããXcodeã§è¨è¿°ããæ©è½ãå¼ã¹ãiPhone/iPadã®ãã©ã°ã¤ã³ãä½æããæ¹æ³ã解説ãä»åã®ãµã³ãã«ã¯こちらããDLåºæ¥ã¾ãã
ãã©ã°ã¤ã³ãä½ãã°ãã¤ãã£ãã³ã¼ãã§åºæ¥ãäºã¯ãªãã§ãåºæ¥ã¡ããã¾ããä½æãããã©ã°ã¤ã³ã¯iOS Proã©ã¤ã»ã³ã¹ã¯ãã¡ãããiOSã©ã¤ã»ã³ã¹ã§ã使ç¨å¯è½ã§ãã
æé ã¯ä»¥ä¸ã®æ§ã«ãªãã¾ãã
1. ãã«ããã¦Xcodeã®ããã¸ã§ã¯ããä½æã
2. Xcodeå´ã®ããã°ã©ã ãä½æããçºã«ãã¡ã¤ã«ãçæãããã°ã©ã ãè¨è¿°ããã
3. Unityå´ã§Xcodeå´ã®ããã°ã©ã ã¨Unityå´ã®ããã°ã©ã ãæ©æ¸¡ãããããã°ã©ã ãä½æã
é çªã«è©³ãã解説ãã¾ãã 1. ã¯åé¡ç¡ãã¨æãã®ã§ 2. ãã
Xcodeå´ã®ããã°ã©ã ãä½æããçºã«ãã¡ã¤ã«ãçæ
ä»åã¯iPhone/iPadã§è¨å®ããã¦ããè¨èªãåå¾ããããã°ã©ã ãä¾ã«è§£èª¬ãã¾ãã
â»è¨èªã¯ãã©ã°ã¤ã³ãä½ããªãã¦ã Application.systemLanguage ã§åå¾åºæ¥ãããªæ°ããã¾ããå®ã¯iPhone/iPadã§ã¯ Unknown ãè¿ããåå¾åºæ¥ã¾ããã
Xcodeä¸ã§ LanguagePlugin.h/LanguagePlugin.m ãä½æãã.mãã¡ã¤ã«ã«ä»¥ä¸ã®æ§ã«è¨è¿°ãã¾ãã
char* MakeStringCopy (const char* string) { if (string == NULL) return NULL; char* res = (char*)malloc(strlen(string) + 1); strcpy(res, string); return res; } char *CurrentLanguage_ () { NSArray *languages = [NSLocale preferredLanguages]; NSString *currentLanguage = [languages objectAtIndex:0]; return MakeStringCopy([currentLanguage UTF8String]); }
CurrentLanguage_ () ãã¡ã¤ã³ã®é¢æ°ã§ MakeStringCopy() ã§æååãå å·¥ãã¦ããã®ã¯ä»¥ä¸ã詳ããèªãã§è²°ãã¨åããã¾ãã
Unity - Plugins - Pro/Mobile-Only Feature
http://unity3d.com/support/documentation/Manual/Plugins.html
æååã«ã¤ãã¦ã¯ãã®æ§ãªã«ã¼ã«ãæãããã§ãã
String values returned from a native method should be UTF-8 encoded and allocated on the heap. Mono marshaling calls are free for them.
ã³ã¬ã«å¯¾å¦ããçºã®å¦çã¯èªåã§ä½æãã¦ãè¯ãã£ãã®ã§ããå ¬å¼ã§é å¸ãã¦ããこちらã®ãµã³ãã«ã«è¨è¿°ãæã£ãã®ã§ãã®ã¾ã¾æµç¨ãã¦ãã¾ããããã MakeStringCopy () ã¨ãªãã¾ãã
ãã®Xcodeå´ã®ããã°ã©ã ã®ãã¡ã¤ã«ã¯ç½®ãå ´æã«ãã£ã¦ã¯Unityã§ãã«ããã¦Xcodeããã¸ã§ã¯ããåçæãããæã«(å ´åã«ãã£ã¦ã¯)ä¸æ¸ãããã¦ãã¾ãã®ã§ä»¥ä¸ã®ããããã®ä½ç½®ã«ç½®ãã®ãæ¨å¥¨ããã¦ãã¾ãã
ã»Unityå´ã®ããã¸ã§ã¯ãã® Assets ãã©ã«ã
ã»Xcodeå´ã®ããã¸ã§ã¯ãã® Classes ãã©ã«ã
ãªããUnityå´ã®ããã¸ã§ã¯ãã® Assets ãã©ã«ãã®ä¸ã« Plugins/iOS ã¨ãããã©ã«ããä½æãããã®ãã©ã«ãã«ãã¡ã¤ã«ãç½®ãã¦ããã¨iOSåãã«ãã«ãããæã«ãèªåçã«çæãããXcodeã®ãã¡ã¤ã«ã«å«ã¾ãã¾ãããªãããµããã©ã«ãã«ã¯å¯¾å¿ãã¦ãªãã¿ãããªã®ã§ Plugins/iOS/image/hoge.png ãªã©ã¨ããä½ç½®ã«ãã¡ã¤ã«ãç½®ãã¨ãã®ãã¡ã¤ã«ã¯å¯¾è±¡ã«å«ã¾ããªãã®ã§æ³¨æãã¦ä¸ããã
Unityå´ã§Xcodeå´ã®ããã°ã©ã ã¨Unityå´ã®ããã°ã©ã ãæ©æ¸¡ãããããã°ã©ã ãä½æ
Unityã«æ»ã£ã¦ããã°ã©ã ã®æ©æ¸¡ããããããã°ã©ã ãä½æãã¾ãã
Plugins ãã©ã«ã( Plugins/iOS ã§ã¯æãã¾ãã)ã«C#ã®ãã¡ã¤ã«ã Binding ã¨ããååã§ä½æãã¾ãã
ããã°ã©ã ã¯ä»¥ä¸ã
using UnityEngine; using System.Runtime.InteropServices; public class Binding { [DllImport("__Internal")] private static extern string CurrentLanguage_ (); public static string CurrentLanguage () { if (Application.platform != RuntimePlatform.OSXEditor) { return CurrentLanguage_ (); } else { return ""; } } }
ãã® CurrentLanguage_ () ãXcodeå´ã§ä½æããé¢æ°ã«ãªãã¾ãã
Unityã®IDEä¸ã§å®è¡ããæã«ã¯ãã®é¢æ°ãå¼ã¶ãã¨ã¯åºæ¥ãªãã®ã§ Application.platform ã§ãã§ãã¯ãããIDEä¸ã§å®è¡ä¸ã®å ´å㯠"" ãè¿ãã¦ãã¾ãã
å®éã«ãã® CurrentLanguage() ãå¼ã¶å ´åã¯ãã®æ§ã«ãã¾ãã
Debug.Log( Binding.CurrentLanguage() );
ä»åã¯ç»é¢ã®å·¦ä¸ã«åå¾ããè¨èªã表示ãããæ§ã«ããããªããã°ã©ã ãä½æãã¾ããã
private var lang: String; function Start () { lang = Binding.CurrentLanguage(); } function OnGUI () { GUI.Label(Rect(20, 20, 100, 100), lang); }
ãããå®è¡ããã¨ä»¥ä¸ã®æ§ã«ç»é¢ã®å·¦ä¸ã«å°ãã(â»)ç¾å¨ã®è¨èªè¨å®ã表示ããã¾ããæ¥æ¬èªã«è¨å®ããã¦ããå ´å㯠ja ã¨è¡¨ç¤ºããã¾ãã
â»Unityã§iOSåããã«ãã§åçã«å¤§ããæåã使ãã®ã¯ã¡ãã£ã¨æéãªã®ã§ãããªã£ã¦ã¾ãã
iPhone/iPadã®è¨èªè¨å®ã«ã¤ãã¦ã¯è©³ããã¯ä»¥åæ¸ããこちらãåç §ä¸ããã
è£è¶³æ å ±
ãããXcodeå´ã®ããã°ã©ã ãC++ã.mmãã¡ã¤ã«ã§ä½æããå ´åã¯Cããå¼ã¹ãC++ã®ããã°ã©ã ãä½æããæã¨åæ§ã«ä»¥ä¸ã®æ§ã« extern "C" (ãªã³ã±ã¼ã¸æå®)ãå¿ è¦ã§ãã
extern "C" { float FooPluginFunction (); }
ãã©ã°ã¤ã³ã®ããã°ã©ã ä½æä¸ã«ãªãã ãä¸æãåããªãå ´åã«ã¯èªåã¯ä»¥ä¸ã®æ§ãªã¢ã©ã¼ãã表示ãã¦ãããã°ãã¾ããã
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"ãã¹ã" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"OK", nil]; [alert show]; [alert release];
é¢é£æ å ±
Unityåãã®ARãã©ã°ã¤ã³ã®å¶ä½ææ³ã«ã¤ãã¦è§£èª¬ããã¹ã©ã¤ãè³æã
Unityã§ã®ARã¢ããªã±ã¼ã·ã§ã³éçº
http://qoncept.jp/ar/seminar/unity_20110716.pdf
ãã¡ãã¯ä»¥ä¸ã®ã¤ãã³ãã§ä½¿ããããã®ã§ãã
IGDAæ¥æ¬ã²ã¼ã éçºã»ããã¼ãUnityã®å°å ¥ã¨å®è·µãã«åå ãã¦æ¥ã¾ãã - å¼·ç«ã§é²ã
http://d.hatena.ne.jp/nakamura001/20110716/1310821202
æ§é ä½ãå¼æ°ã«ããå ´åã
Specific steps to set up a plugin for iphone in XCode - Unity Answers
http://answers.unity3d.com/questions/10110/specific-steps-to-set-up-a-plugin-for-iphone-in-xc.html
Byteé åãå¼æ°ã«ããå ´åã
Returning a byte array from ObjC to C# script on ios - Unity Answers
http://answers.unity3d.com/questions/132083/returning-a-byte-array-from-objc-to-c-script-on-io.html
Unity - Plugins (Pro/Mobile-Only Feature)
http://unity3d.com/support/documentation/Manual/Plugins.htmlé¢é£ãªã³ã¯
ãUnity Proã®ã¿å¯¾å¿ã Mac ç°å¢ã®ãã©ã°ã¤ã³ãä½æ - å¼·ç«ã§é²ã
http://d.hatena.ne.jp/nakamura001/20120901/1346529070