本文实例为大家分享了Unity苹果手机Taptic震动的具体代码,供大家参考,具体内容如下
文件:ios震动.zip
将上方文件解压之后将MultiHaptic.mm的文件放到Assets/Plugins/iOS目录下,MultiHaptic.cs文件不用挂载到游戏物体上,在需要的时候调用里面的三个静态方法即可
附上MultiHaptic.cs的代码:
using UnityEngine; using System.Runtime.InteropServices; public class MultiHaptic { [DllImport("__Internal")] static extern void _hapticMedium(); [DllImport("__Internal")] static extern void _hapticLight(); [DllImport("__Internal")] static extern void _hapticHeavy(); public static void HapticLight() { if (Application.platform == RuntimePlatform.IPhonePlayer) if (PlayerPrefs.GetInt("Taptic", 1) == 1) { _hapticLight(); } } public static void HapticMedium() { if (Application.platform == RuntimePlatform.IPhonePlayer) if (PlayerPrefs.GetInt("Taptic", 1) == 1) { _hapticMedium(); } } public static void HapticHeavy() { if (Application.platform == RuntimePlatform.IPhonePlayer) if (PlayerPrefs.GetInt("Taptic", 1) == 1) { _hapticHeavy(); } } }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。
评论(0)