zoukankan      html  css  js  c++  java
  • 解决UI与3d物体的事件响应问题

    解决UI与3d物体的事件响应问题

    1.3D物体也可以使用EventSystems里的接口,需要相机上添加PhysicsRaycaster组件。

    2.UI响应事件向下传递:

    //向下传递UI响应事件
        private void PassdownEvent(PointerEventData eventData, ExecuteEvents.EventFunction<IPointerClickHandler> function)
        {
            List<RaycastResult> results = new List<RaycastResult>();
            EventSystem.current.RaycastAll(eventData, results); //获得本次点击的所有物体
            for (int i = 0; i < results.Count; i++)
            {
                //Debug.Log(results[i].gameObject.name);
                if (results[i].gameObject != gameObject) //移除自己
                {
                    ExecuteEvents.Execute(results[i].gameObject, eventData, function);
                }
            }
        }

    3.当鼠标点击在UI上时,不响应鼠标点击事件

    private GraphicRaycaster uiRaycaster;
    private
    void Update() { //当鼠标点在UI上时,不响应鼠标点击事件 if (Input.GetMouseButtonDown(0) && !IsPointClickUI()) { //......... } }//判断是否点击到ui了,返回true是点击到ui了,反之没有 public bool IsPointClickUI() { PointerEventData eventData = new PointerEventData(EventSystem.current); eventData.position = Input.mousePosition; eventData.pressPosition = Input.mousePosition; List<RaycastResult> resultAppendList = new List<RaycastResult>(); uiRaycaster.Raycast(eventData, resultAppendList); return resultAppendList.Count > 0; }
  • 相关阅读:
    Quick QEMU
    Linux 常用命令速查
    Linux 安装篇
    Vivaldi解决flash插件问题
    VNC 安装 (适用Redhat 9.0 和 CentOS 7.0+)
    Git使用笔记 (github为例)
    poj3045 Cow Acrobats(二分最大化最小值)
    poj3104 Drying(二分最大化最小值 好题)
    poj3468 A Simple Problem with Integers(线段树区间更新)
    poj1852 Ants(思维)
  • 原文地址:https://www.cnblogs.com/luoyanghao/p/15127273.html
Copyright © 2011-2022 走看看