Unity iOS 3DTouch 接入
2017-12-29 22:03
330 查看
Unity发展速度真的很快,想起去年策划让我接3DTouch我还需要自己写OC的代码,Unity-iOS要互相调来调去,今天发现Unity已经将3DTouch集成进来了,
1、废话不说上Git链接https://github.com/Prince-Ling/Unity3DTouch
2、废话不说上代码
1、废话不说上Git链接https://github.com/Prince-Ling/Unity3DTouch
2、废话不说上代码
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using UnityEngine.EventSystems; // (1)Input.touchPressureSupported:是否支持3Dtouch,bool类型 // (2)Touch.pressure:获取当前按压值,float类型 // (3)Touch.maximumPossiblePressure:获取最大按压值,float类型 public class ThreeDTouch : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerExitHandler, IPointerClickHandler{ public Button threeDTouchBtn; public Image scaleImage; public Text showText; public Text pressText; // Use this for initialization void Start () { if(Input.touchPressureSupported) { showText.text = "支持3DTouch"; } else { showText.text = "!!不支持3DTouch!!"; } } [SerializeField] UnityEvent m_OnLongpress = new UnityEvent(); private bool isHad3DTouch = false; private float lastInvokeTime; // Update is called once per frame void Update() { if(Input.touchPressureSupported == false) { return; } scaleImage.transform.localScale = new Vector3(Input.GetTouch (0).pressure,Input.GetTouch (0).pressure,Input.GetTouch (0).pressure); pressText.text = "力度:"+Input.GetTouch (0).pressure.ToString(); if (isHad3DTouch == false) { if(Input.GetTouch (0).pressure > Input.GetTouch(0).maximumPossiblePressure*0.7f) { isHad3DTouch = true; Handheld.Vibrate(); } } } public void OnPointerDown(PointerEventData eventData) { m_OnLongpress.Invoke(); isHad3DTouch = false; lastInvokeTime = Time.time; Debug.Log("鼠标按下"); } public void OnPointerUp(PointerEventData eventData) { isHad3DTouch = true; Debug.Log("鼠标抬起"); } public void OnPointerExit(PointerEventData eventData) { Debug.Log("鼠标退出"); } public void OnPointerClick(PointerEventData eventData) { Debug.Log("鼠标点击"); } }
相关文章推荐
- 3D touch 的 应用 --备用
- iOS 11.1发布 3D Touch多任务回归
- iOS 3D Touch浅谈
- iOS9 3DTouch、ShortcutItem、Peek And Pop技术一览
- iOS9 3D Touch 使用教程
- ios开发——iOS9 3D Touch 使用教程
- iOS 3D Touch功能
- iOS 3Dtouch 学习
- 3DTouch开发 (基础)
- 3D touch 初学
- iOS 9之3D Touch
- 关于3D Touch
- ISO之3DTouch
- 用IPhone6s的3D Touch来称重,比较2个物体的重量
- iOS 3D Touch 适配开发
- 3D Touch初探
- 3D-Touch Home Screen Quick Actions 使用
- Android 7.1.1 之实现 3D Touch
- Instagram的3D Touch经验谈
- 3D Touch入门