zoukankan      html  css  js  c++  java
  • UGUI使用上的常见问题

    1. UGUI上的输入事件触发是通过Raycast Target选项控制的。所以如果某个Text或Image等组件,如果不需要处理输入事件,应该将Raycast Target选项去掉。

    2. 在有透明按钮的需求时,往往是通过透明Image实现的(不设置Sprite, 透明度0),如下图:

    此方法的问题在于,虽然Button不可见,但unity却会去绘制它。在FrameDebug中可见:

    unity会使用默认的白色图去绘制它,至于显示成全透明的原因是因为顶点中的color项为透明的。

    其实,在Overdraw窗口中也能明显看出:

      那透明按钮可以怎么处理呢?可以使用自定义组件替代Image。

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.UI;
     
    // 方法来自UWA改编
    public class NoDrawingRaycast : Graphic { public override void SetMaterialDirty() { } public override void SetVerticesDirty() { }    protected override void OnPopulateMesh(VertexHelper vh) {
         // 清除绘制的原三角形信息 vh.Clear(); } }

    使用NoDrawingRaycast替换Button中的Image后,FrameDebug中可见Unity并没有绘制它,且点击功能正常。

  • 相关阅读:
    Mac OS X 下安装Raspbian系统
    Tiny4412 uboot Makefile 分析
    Tiny4412增强版底板串口电路与设置
    为Debian搞定Mercury MW150US无线网卡驱动
    树莓派的启动过程
    xml格式转换为Bean
    j2ee之hibernate工具类
    验证码代码
    j2ee之AJAX的二级联动
    j2ee之原生AJAX
  • 原文地址:https://www.cnblogs.com/hghhe/p/14671635.html
Copyright © 2011-2022 走看看