经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » 软件/图像 » unity » 查看文章
Unity实现苹果手机Taptic震动
来源:jb51  时间:2019/11/1 8:32:48  对本文有异议

本文实例为大家分享了Unity苹果手机Taptic震动的具体代码,供大家参考,具体内容如下

文件:ios震动.zip

将上方文件解压之后将MultiHaptic.mm的文件放到Assets/Plugins/iOS目录下,MultiHaptic.cs文件不用挂载到游戏物体上,在需要的时候调用里面的三个静态方法即可

附上MultiHaptic.cs的代码:

  1. using UnityEngine;
  2. using System.Runtime.InteropServices;
  3. public class MultiHaptic
  4. {
  5. [DllImport("__Internal")]
  6. static extern void _hapticMedium();
  7. [DllImport("__Internal")]
  8. static extern void _hapticLight();
  9. [DllImport("__Internal")]
  10. static extern void _hapticHeavy();
  11. public static void HapticLight()
  12. {
  13. if (Application.platform == RuntimePlatform.IPhonePlayer)
  14. if (PlayerPrefs.GetInt("Taptic", 1) == 1)
  15. {
  16. _hapticLight();
  17. }
  18. }
  19. public static void HapticMedium()
  20. {
  21. if (Application.platform == RuntimePlatform.IPhonePlayer)
  22. if (PlayerPrefs.GetInt("Taptic", 1) == 1)
  23. {
  24. _hapticMedium();
  25. }
  26. }
  27. public static void HapticHeavy()
  28. {
  29. if (Application.platform == RuntimePlatform.IPhonePlayer)
  30. if (PlayerPrefs.GetInt("Taptic", 1) == 1)
  31. {
  32. _hapticHeavy();
  33. }
  34. }
  35. }

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号