unity設定iOS手機震動

2021-10-03 09:17:57 字數 1493 閱讀 8873

玩很多遊戲的時候,線性馬達的觸感很棒,unity封裝的 handheld.vibrate() 持續時間是0.5s, 用到按鍵震動反饋因為時間太長,上手感很差。ios 提供了另外乙個介面 audioservicesplaysystemsound(1519);

需要用uinty呼叫ios介面:

在unity ios工程裡建立oc混編檔案,shortvibrator.mm檔案裡**如下

#import "shortvibrator.h"

#import

@implementation shortvibrator

extern

"c"void

setvibratorios()

@end

在unity**裡呼叫

using system.runtime.interopservices;

//需要用到的命名空間

#if unity_ios

[dllimport

("__internal")]

static

extern

void

setvibratorios()

;//用static extern 宣告是外部函式

#endif

**比較簡單,可能會遇到了幾個編譯上的問題:

undefined symbols for architecture arm64:

"_setvibratorios", referenced from:

_iosutils_setvibratorios_m56d46f72c0d9623662142b280a78b7222b3be0be in assembly-csharp.o

(maybe you meant: _iosutils_setvibratorios_m56d46f72c0d9623662142b280a78b7222b3be0be)

ld: symbol(s) not found for architecture arm64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

之前是在ios專案裡加的mm檔案,然後unity-framework 找不到,一直build-failed

需要加到unity-framework裡

後面又發現編譯成功之後無法安裝:

原因是簽名問題,解決方法是:

Unity實現蘋果手機Taptic震動

檔案 ios震動.zip 將上方檔案解壓之後將multihaptic.mm的檔案放到assets plugins ios目錄下,multihaptic.cs檔案不用掛載到遊戲物體上,在需要的時候呼叫裡面的三個靜態方法即可 附上multihaptic.cs的 using unityengine usi...

Android 手機震動

1.新增震動許可權 uses permission android name android.permission.vibrate 2.獲取震動服務 vibrator mvibrator vibrator getsystemservice vibrator service 3.啟動震動 void v...

IOS簡單的實現手機震動的提示

我們都知道手機有震動功能,其實呢,這個功能實現起來特別的簡單,我們只需要用到幾個函式就可以了 void motionbegan uieventsubtype motion withevent uievent event void motionended uieventsubtype motion w...