当前位置:网站首页>Unity3d:ugui source code eventsystem input system FAQ
Unity3d:ugui source code eventsystem input system FAQ
2022-07-23 12:45:00 【Sixi Liyu】
1. button Process from press to response
1. First, EventSystem stay Update Call the current input module InputModules Of Process Method handles all mouse events ,
2. And the input module will call RaycastAll Get the target information ,
3. Through sub object not mounted IEventSystemHandler, Find the actual receiver of the event by finding the parent object and execute the click event
2. button Sub object text Also check RaycastTarget, Why response button, instead of text
Create a Button, So this one Button It also contains Text Components , If text.RaycastTarget On the hook
Called when the mouse clicks GetEventHandler function ,
Of this function root The parameters are Text, Find out text nothing IEventSystemHandler Components
But its parent object will be found Button, Found to have , And then call Button Click events for
Core issues :text The lack of IEventSystemHandler
public class Button : Selectable, IPointerClickHandler, ISubmitHandler
public interface IPointerClickHandler : IEventSystemHandler
Click on button, Respond first text, And then find button,handlerCount by 0, Description none IPointerClickHandler Components 
text add EventTrigger, Will respond to text Click events for , No upward response button
3. How to force text Click on , For example, click the hyperlink in the chat system
text Hanging script implementation IPointerClickHandler Interface OnPointerClick
4. through UI Click on the question
IsPointerOverGameObject It was exposed to radiation UI Yes RaycastTarget
public override bool IsPointerOverGameObject(int pointerId)
{
var lastPointer = GetLastPointerEventData(pointerId);
if (lastPointer != null)
return lastPointer.pointerEnter != null;
return false;
}
if (Input.GetMouseButtonDown(0))
{
if (Application.isMobilePlatform && Input.touchCount > 0)
{
for (int i = 0; i < Input.touchCount; i++)
{
if (EventSystem.current.IsPointerOverGameObject(Input.GetTouch(i).fingerId))
{
m_isClickUi = true;
break;
}
}
}
else if (EventSystem.current.IsPointerOverGameObject())
{
m_isClickUi = true;
}
}
5. EventSystem function
EventSystem Will be in Update Calling input module PointerInputModule Of Process Method to process the input message
PointerInputModule Would call EventSystem Medium RaycastAll Methods radiographic testing was performed
RaycastAll Will call again BastRaycaster Of Raycast Methods to perform specific radiographic testing operations , It is mainly to obtain the selected target information .
6. How do irregular buttons respond to clicks
Polygon Collider 2D
7. Design and build system : How to drag the screen without responding to building clicks , How to distinguish between clicking and dragging buildings
8. GraphicRaycaster.BlockingObjects
Uncheck when not in use 2d,3d, stay update Performance consumption . The default is none
if (blockingObjects == BlockingObjects.ThreeD || blockingObjects == BlockingObjects.All)
{
if (ReflectionMethodsCache.Singleton.raycast3D != null)
{
var hits = ReflectionMethodsCache.Singleton.raycast3DAll(ray, distanceToClipPlane, (int)m_BlockingMask);
if (hits.Length > 0)
hitDistance = hits[0].distance;
}
}
if (blockingObjects == BlockingObjects.TwoD || blockingObjects == BlockingObjects.All)
{
if (ReflectionMethodsCache.Singleton.raycast2D != null)
{
var hits = ReflectionMethodsCache.Singleton.getRayIntersectionAll(ray, distanceToClipPlane, (int)m_BlockingMask);
if (hits.Length > 0)
hitDistance = hits[0].distance;
}
}
9. What are the optimizations
1. Events that do not need to be clicked can be unchecked RaycastTarget
2. Package click button with parameters
using UnityEngine;
using System.Collections;
using UnityEngine.Events;
using UnityEngine.EventSystems;
public class ClickListener : MonoBehaviour, IPointerClickHandler, IPointerDownHandler,IPointerUpHandler
{
public delegate void VoidDelegate(GameObject go);
public VoidDelegate onClick;
public VoidDelegate onPress;
public VoidDelegate onNewGuideClick;
static public ClickListener Get(GameObject go)
{
ClickListener listener = go.GetComponent<ClickListener>();
if (listener == null) listener = go.AddComponent<ClickListener>();
return listener;
}
public void OnPointerClick(PointerEventData eventData)
{
if (onClick != null)
{
onClick(gameObject);
}
}
bool ispress;
public void OnPointerDown(PointerEventData eventData)
{
ispress = true;
}
public void OnPointerUp(PointerEventData eventData)
{
ispress = false;
}
void Update() {
if (onPress != null && ispress)
onPress(gameObject);
}
}
边栏推荐
- 浅析互联网协议(一)
- Hcip--- BGP related configuration (Federal chapter)
- OSPF和RIP的路由扩展配置
- HCIP---BGP相关配置(联邦篇)
- 《wireshark网络分析就是这么简单》知识点与技巧
- Analyze sentinel mode in redis
- [memory understand the difference and function between ram flash and EEPROM memory]
- flask项目celery使用redis sentinel中遇到的坑
- Implementation of heap and heap sorting
- Mutual implementation of queue and heap (pure C implementation)
猜你喜欢
![[bootloader architecture and brushing process based on UDS service]](/img/c7/de4f1e32f89173e18d74d2f624f3f9.png)
[bootloader architecture and brushing process based on UDS service]

Common sort exchange sort

主机字节序的判定

HCIP---GRE协议和MGRE环境,以及OSPF协议的相关知识点

Unity3D高清渲染管线无法在模型上播放视频

HCIP---BGP相关配置

Summary of video coding and decoding related data

Using one-way linked list to realize queue

socket基础知识以及各种使用场景

Hcip--- BGP related configuration (Federal chapter)
随机推荐
【数据库】基础理论
htpasswd作用
刷题笔记:二叉树的中序遍历(三种解法-递归,迭代,Morris)
APISIX的源码安装与使用
如何用普通的文本编辑器写Web页面
牛客面试必考真题【算法篇】高频Top200 题目汇总
Vs attribute configuration related knowledge
SQL基础操作总结
flask项目celery使用redis sentinel中遇到的坑
OSPF综合实验
Using one-way linked list to realize queue
C# 自定义双向链表
hot 100 动态规划
HCIP---GRE协议和MGRE环境,以及OSPF协议的相关知识点
ThreadLocal到底在干嘛?
Axure实现增删改查
OSPF的链路扩展配置
Hcip --- BGP --- border gateway protocol
Unity在URP管线下使用TriLib插件加载模型材质不正确的问题
URL查询参数编码问题(golang)