位置: 编程技术 - 正文
推荐整理分享Unity调用Android原生的震动(简单)(unity调用android方法),希望有所帮助,仅作参考,欢迎阅读内容。
文章相关热门搜索词:unity发布android教程,unity发布android教程,unity调用aar,unity调用安卓原生接口,unity androidx,unity调用安卓原生接口,unity调用android方法,unity调用安卓原生接口,内容如对您有帮助,希望把文章链接给更多的朋友!
要在unity中调用Android系统的震动,需要一个Vibrator类 ,通过AndroidManifest.xml文件设置权限了
如下:
在这里先给贴出英文文档及大概的翻译 :
Class that operates the vibrator on the device.If your process exits, any vibration you started with will stop. Vibrator类用来操作设备上的震动,如果你的线程退出了,那么启动的震动也会停止
Pass in an array of ints that are the durations for which to turn on or off the vibrator in milliseconds. The first value indicates the number of milliseconds to wait before turning the vibrator on. The next value indicates the number of milliseconds for which to keep the vibrator on before turning it off. Subsequent values alternate between durations in milliseconds to turn the vibrator off or to turn the vibrator on.
传递一个整型数组作为关闭和开启震动的持续时间,以毫秒为单位。第一个表示等待震动开启的毫秒数,下一个表示保持震动的毫秒数,这个序列交替表示震动关闭和开启的毫秒数To cause the pattern to repeat, pass the index into the pattern array at which to start the repeat, or -1 to disable repeating.为了重复的按设定的节奏震动,传递index参数表示重复次数,用-1表示不重复。Parameterspattern an array of longs of times for which to turn the vibrator on or off.repeat the index into pattern at which to repeat, or -1 if you don't want to repeat.
上代码:
这里设置两个参数,以便于在unity中灵活定义震动;
同时还有:
之后把自己的Android工程Clean一下,然后打出自己的 jar包(或者用命令行: jar -cvf myclass.jar *(打包步骤略去)),把打好的jar包放在unity工程中(“Plugins/Android/libs”);
最好我们回到unity,新建一个C#脚本,
贴出代码 :
通过此方法来调用Android的原生震动。
此教程比较简单,有好的建议,欢迎 轻喷!
关于U3D贴图格式压缩 各种纹理式,大家参照下U3DMANUAL里面的具体描述介绍,这是官方的东西。但我觉得有一部内容是错的,例如占用内存大小。
Unity使用 UnityVS+VS 调试脚本(转) UnityVS版本:UnityVS_1.8.2VS版本:VS旗舰版Unity3D版本:4.3.4安装步骤:1.如果之前安装过其它版本的UnityVS,请先卸载2.运行UnityVS.msi3.找到你安装visualstu
Unity CG 写一个超酷的 ray-marching(shader纯代码写3D) UnityCG写一个超酷的ray-marching(shader纯代码写3D)1.其实自从看了
标签: unity调用android方法
本文链接地址:https://www.jiuchutong.com/biancheng/369246.html 转载请保留说明!上一篇:非常详细的测试unity与android之间的通讯操作(一直activity那块还是有问题,一直进不来android界面!)(详细测试就是全部测试)
友情链接: 武汉网站建设