Beispiel #1
0
 /// <summary>
 /// 作为监听者监听事件
 /// </summary>
 public BaseCommand ListenEvent <A1, A2, A3>(string eventName, Func <A1, A2, A3, T> func)
 {
     return(EventDispatcher.AddEventListener <A1, A2, A3>(eventName, (arg1, arg2, arg3) => this.propValue = func(arg1, arg2, arg3)));
 }
Beispiel #2
0
 /// <summary>
 /// 作为监听者监听事件
 /// </summary>
 /// <param name="eventName"></param>
 /// <param name="func"></param>
 /// <returns></returns>
 public BaseCommand ListenEvent(string eventName, Func <T> func)
 {
     return(EventDispatcher.AddEventListener(eventName, () => this.propValue = func()));
 }
Beispiel #3
0
 /// <summary>
 /// 改变数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="dataId"></param>
 /// <param name="value"></param>
 public static void ChangeData <T>(string dataId, T value)
 {
     EventDispatcher.TriggerEvent <T>(dataId, value);
 }
        private static void HandleMethod <T>(T mono, MethodInfo method)
        {
            object[] attrs = method.GetCustomAttributes(typeof(GenEventable), true);
            if (attrs.Length == 0)
            {
                return;
            }
            GenEventable genEventAttr = attrs[0] as GenEventable;


            ParameterInfo[] paras      = method.GetParameters();
            var             eventNames = genEventAttr.eventName;

            if (eventNames == null || eventNames.Length == 0)
            {
                eventNames = new string[] { method.Name };
            }

            for (int i = 0; i < eventNames.Length; i++)
            {
                switch (paras.Length)
                {
                case 0:
                {
                    EventDispatcher.AddEventListener(eventNames[i],
                                                     () => { method.Invoke(mono, new object[0]); }, mono);
                }
                break;

                case 1:
                {
                    EventDispatcher.AddEventListener <object>(eventNames[i],
                                                              (arg1) => { method.Invoke(mono, new object[] { arg1 }); }, mono);
                }
                break;

                case 2:
                {
                    EventDispatcher.AddEventListener <object, object>(eventNames[i],
                                                                      (arg1, arg2) => { method.Invoke(mono, new object[] { arg1, arg2 }); }, mono);
                }
                break;

                case 3:
                {
                    EventDispatcher.AddEventListener <object, object, object>(eventNames[i],
                                                                              (arg1, arg2, arg3) => { method.Invoke(mono, new object[] { arg1, arg2, arg3 }); }, mono);
                }
                break;

                case 4:
                {
                    EventDispatcher.AddEventListener <object, object, object, object>(eventNames[i],
                                                                                      (arg1, arg2, arg3, arg4) => { method.Invoke(mono, new object[] { arg1, arg2, arg3, arg4 }); }, mono);
                }
                break;

                default:
                {
                    Debug.unityLogger.LogError("Event Gen Error", "The method " + method.Name + " has too much para");
                }
                break;
                }
            }
        }
 /// <summary>
 /// 设定数值
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="eventName"></param>
 /// <param name="value"></param>
 public static void SetData <T>(string eventName, T value)
 {
     EventDispatcher.TriggerEvent <T>(eventName, value);
 }
 /// <summary>
 /// 绑定数据
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="mono"></param>
 /// <param name="eventName"></param>
 /// <param name="setter"></param>
 public static void BindData <T>(MonoBehaviour mono, string eventName, Action <T> setter)
 {
     EventDispatcher.AddEventListener <T>(eventName, setter, mono);
 }