Пример #1
0
        /// <summary>
        /// jiao--获取事件的Caster
        /// </summary>
        /// <typeparam name="TEventCaster"></typeparam>
        /// <param name="eventData"></param>
        /// <returns></returns>
        public static TEventCaster GetEventCaster <TEventCaster>(this ColliderEventData eventData) where TEventCaster : MonoBehaviour, IColliderEventCaster
        {
            if (!(eventData.eventCaster is TEventCaster))
            {
                return(null);
            }

            return(eventData.eventCaster as TEventCaster);
        }
Пример #2
0
        /// <summary>
        /// jiao--上一个函数的第二种写法,Try表示返回一个bool表示是否成功,而真正要的其实是输入参数中的eventCaster
        /// </summary>
        /// <typeparam name="TEventCaster"></typeparam>
        /// <param name="eventData"></param>
        /// <param name="eventCaster"></param>
        /// <returns></returns>
        public static bool TryGetEventCaster <TEventCaster>(this ColliderEventData eventData, out TEventCaster eventCaster) where TEventCaster : MonoBehaviour, IColliderEventCaster
        {
            eventCaster = null;

            if (!(eventData.eventCaster is TEventCaster))
            {
                return(false);
            }

            eventCaster = eventData.eventCaster as TEventCaster;
            return(true);
        }