zoukankan      html  css  js  c++  java
  • (三)UGUI ExecuteEvent

    1.前言

    ExecuteEvent是一个非常有用的类,方法都是静态的。在Unity事件系统中负责执行各个事件。

    2.关键方法

    1)Execute
    方法:
    public static bool Execute(GameObject target, BaseEventData eventData, EventFunction functor) where T : IEventSystemHandler
    获取target上所有组件,如果组件是functor类型时(比如时PointerDown)则执行此方法。
    2)ExecuteHierarchy
    方法:
    public static GameObject ExecuteHierarchy(GameObject root, BaseEventData eventData, EventFunction callbackFunction) where T : IEventSystemHandler
    此方法向上查找然后执行相关方法,首先获取游戏物体root的所有父类,然后依次向上查找所有父类,执行Execute方法。比如当执行PointerDown事件时,如果pointerdown时对应的游戏物体没有PointerDown对应的事件,则查找父类执行PointerDown事件,直到事件执行或者查找结束。
    3)GetEventHandler
    根据提供的游戏物体,依次向上查找,获取可以执行相应事件的的游戏物物体

            public static GameObject GetEventHandler<T>(GameObject root) where T : IEventSystemHandler
            {
                if (root == null)
                    return null;
    
                Transform t = root.transform;
                while (t != null)
                {
                    if (CanHandleEvent<T>(t.gameObject))
                        return t.gameObject;
                    t = t.parent;
                }
                return null;
            }
    

    4)GetEventChain
    往上依次获取所有的父类

            private static void GetEventChain(GameObject root, IList<Transform> eventChain)
            {
                eventChain.Clear();
                if (root == null)
                    return;
    
                var t = root.transform;
                while (t != null)
                {
                    eventChain.Add(t);
                    t = t.parent;
                }
            
    

    3.结语

    此类主要时方法执行。

  • 相关阅读:
    Web_0012:FTP文件编辑器关联
    JS_0033:判断苹果安卓 微信浏览器,并在苹果微信浏览器下做特别处理
    JS_0032:匿名函数 function前加 ! 或 function用括号包裹起来 含义
    JS_0031:JS 常用方法
    spark为什么用scala语言开发
    spark开发常见问题
    java实现多继承
    数仓架构
    object类中的方法
    Spring的IOC原理
  • 原文地址:https://www.cnblogs.com/llstart-new0201/p/12636219.html
Copyright © 2011-2022 走看看