软件编程
位置:首页>> 软件编程>> C#编程>> Unity实现苹果手机Taptic震动

Unity实现苹果手机Taptic震动

作者:LLLLL__  发布时间:2023-02-15 07:18:47 

标签:Unity,苹果手机,震动

本文实例为大家分享了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();
     }
 }
}

来源:https://blog.csdn.net/LLLLL__/article/details/102823979

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com