Unity与IOS混合编程(一)

2022-03-28  本文已影响0人  Razy西南
unity&ios.jpeg

最近由于项目需求,终于啃下了Unity里面比较难啃的一部分:混编。
之前文件也有断断续续的介绍过,这里我做一个总结,把最常用的,最容易踩的坑都列出来了,希望对读者有所帮助。

先来最简单的互相调用:

Unity调IOS

using System.Runtime.InteropServices;
using UnityEngine;

public class IOSMethod : MonoBehaviour
{
#if UNITY_IPHONE || UNITY_IOS
   [DllImport("__Internal")]
    public static extern void OpenAppSettings();
    [DllImport("__Internal")]
    public static extern void JudgeNotifyPermission();
    [DllImport("__Internal")]
    public static extern void LoadIOS(string adid);
    [DllImport("__Internal")]
    public static extern void ShowIOS(string adid);
    
#endif
}

避坑:注意传入参数,建议都转为string,到ios端,对应的是char类型,注意转化。

IOS调Unity

UnitySendMessage("IOSCube","JudgeNotifyCallBack","-1");

在xcode中如何写oc++代码

下一篇继续。

上一篇 下一篇

猜你喜欢

热点阅读