UGUI防止穿透和判断点击的是否是UI
2016-02-18 18:08
561 查看
年后刚上班,就有不幸的事情发生,项目界面要把NGUI推翻,用UGUI来做,真是蛋都碎了,但是没办法,在做的过程中遇UI穿透和点击的是否是UI,查资料,问朋友,弄出来,跟大家分享:
1.UGUI自带的防穿透代码:
本文出自 “Unity_3D技术探讨” 博客,请务必保留此出处http://myselfdream.blog.51cto.com/9944020/1743099
1.UGUI自带的防穿透代码:
if (EventSystem.current.IsPointerOverGameObject()) { return;//为真,则点击在UI上 }2.查资料,自己写了一个判断
using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using System.Collections.Generic; using UnityEngine.UI; public class CheckUGUI : MonoBehaviour { public static bool CheckGuiRaycastObjects(EventSystem eventSystem, GraphicRaycaster graphicRayCaster) { PointerEventData eventData = new PointerEventData(eventSystem); #if UNITY_EDITOR eventData.pressPosition = Input.mousePosition; eventData.position = Input.mousePosition; #endif #if UNITY_ANDROID || UNITY_IPHONE if (Input.touchCount > 0) { eventData.pressPosition = Input.GetTouch(0).position; eventData.position = Input.GetTouch(0).position; } #endif List<RaycastResult> list = new List<RaycastResult>(); graphicRayCaster.Raycast(eventData, list); return list.Count > 0; } }第二种,我把它写成了一个类,用到的调用就行
public EventSystem eventSystem; public GraphicRaycaster graphicRaycaster; if (CheckUGUI.CheckGuiRaycastObjects(eventSystem, graphicRaycaster)) return;//为真,就点击的是UI。希望大家能用的上。
本文出自 “Unity_3D技术探讨” 博客,请务必保留此出处http://myselfdream.blog.51cto.com/9944020/1743099
相关文章推荐
- 使用CAShapeLayer与UIBezierPath画出想要的图形
- 63. Unique Paths II
- U3d内存优化(一)之UILabel使用String的问题
- UIImageView常用操作
- 探秘Java中String、StringBuilder以及StringBuffer
- iOS 【UIKit-一个控件用肉眼看不见,有哪些可能】
- iOS 【UIKit-UIButton中的三个EdgeInsets属性(切图)】
- INSTALL_FAILED_OLDER_SDK (continue talk about it)
- 62. Unique Paths
- Terrasolid Suite v015-v016 for Microstation CONNECT, V8i, V8 & for Windows platforms 1CD
- 《iOS Human Interface Guidelines》——Undo and Redo
- AudioQueue 音频队列实现录音和播音
- android4.4的文件管理器documentsui源码解析
- 关于build-tools位置不一致问题
- 调用顺序正确,仍然出现Android异常:requestFeature() must be called before adding content
- UGUI之Canvas
- Android Download机制详解(一)DocumentUI部分
- UITabbarController更改点击的图片与文字颜色以及更改tabbar的视图颜色
- CodeForces 283A Cows and Sequence 树状数组
- MiniUI之(一)简介