Esempio n. 1
0
    public static object RequireValue <T, U, V>(string eventType, T arg1, U arg2, V arg3)
    {
        Delegate delegate2;

        OnBroadcasting(eventType);
        if (luaCallback != null)
        {
            object ret = luaCallback(eventType, new object[] { arg1, arg2, arg3 });
            if (ret != null)
            {
                return(ret);
            }
        }

        if (eventTable.TryGetValue(eventType, out delegate2))
        {
            CallbackReturn <T, U, V> callback = delegate2 as CallbackReturn <T, U, V>;
            if (callback == null)
            {
                throw CreateBroadcastSignatureException(eventType);
            }
            return(callback(arg1, arg2, arg3));
        }

        return(null);
    }
Esempio n. 2
0
    public static object RequireValue <T>(string eventType, T arg1)
    {
        Delegate delegate2;

        OnBroadcasting(eventType);
        if (luaCallback != null)
        {
            object ret = luaCallback(eventType, new object[] { arg1 });
            if (ret != null)
            {
                return(ret);
            }
        }

        if (eventTable.TryGetValue(eventType, out delegate2))
        {
            //Debug.Log("broadcast:"+ delegate2.GetType().ToString());

            CallbackReturn <T> callback = delegate2 as CallbackReturn <T>;
            if (callback == null)
            {
                throw CreateBroadcastSignatureException(eventType);
            }
            return(callback(arg1));
        }

        return(null);
    }
Esempio n. 3
0
        /// <summary>
        /// 开始切换场景
        /// </summary>
        static IEnumerator StartSwicth()
        {
            m_IsSwitch = true;

            SceneSwitchInfo info = null;
            CallbackReturn <IEnumerator, object> itorCb = null;
            IEnumerator itor = null;

            while (m_SwitchQueue.Count > 0)
            {
                info = m_SwitchQueue.Dequeue();

                itorCb = info.m_ItorCb;
                if (itorCb != null)
                {
                    itor = itorCb(info.m_Data);
                    while (itor.MoveNext())
                    {
                        yield return(null);
                    }
                }
            }

            m_IsSwitch = false;
        }
Esempio n. 4
0
 public static void RemoveReturnListener <T, U, V>(string eventType, CallbackReturn <T, U, V> handler)
 {
     OnListenerRemoving(eventType, handler);
     if (eventTable.ContainsKey(eventType))
     {
         eventTable[eventType] = (CallbackReturn <T, U, V>)Delegate.Remove((CallbackReturn <T, U, V>)eventTable[eventType], handler);
     }
     OnListenerRemoved(eventType);
 }
Esempio n. 5
0
        /// <summary>
        /// 尝试切换场景
        /// </summary>
        /// <param name="itorCb">切换Coroutine</param>
        /// <param name="data">切换时需要的数据</param>
        public static void TrySwitch(CallbackReturn <IEnumerator, object> itorCb, object data)
        {
            if (m_SwitchQueue == null)
            {
                m_SwitchQueue = new Queue <SceneSwitchInfo>();
            }

            SceneSwitchInfo info = new SceneSwitchInfo();

            info.m_ItorCb = itorCb;
            info.m_Data   = data;
            m_SwitchQueue.Enqueue(info);

            if (!m_IsSwitch)
            {
                MainCoroutine.mainCoroutine.StartCoroutine(StartSwicth());
            }
        }
Esempio n. 6
0
    //Three parameters
    static public R BroadcastReturn <T, U, V, E, R>(string eventType, T arg1, U arg2, V arg3, E arg4)
    {
#if LOG_ALL_MESSAGES || LOG_BROADCAST_MESSAGE
        Debug.Log("MESSENGER\t" + System.DateTime.Now.ToString("hh:mm:ss.fff") + "\t\t\tInvoking \t\"" + eventType + "\"");
#endif
        OnBroadcasting(eventType);

        Delegate d;
        if (eventTable.TryGetValue(eventType, out d))
        {
            CallbackReturn <T, U, V, E, R> callback = d as CallbackReturn <T, U, V, E, R>;
            R r;
            if (callback != null)
            {
                r = callback(arg1, arg2, arg3, arg4);
                return(r);
            }
            else
            {
                throw CreateBroadcastSignatureException(eventType);
            }
        }
        return(default(R));
    }
Esempio n. 7
0
 //四个参数+返回值
 static public void AddReturnListener <T, U, V, E, R>(string eventType, CallbackReturn <T, U, V, E, R> handler)
 {
     OnListenerAdding(eventType, handler);
     eventTable[eventType] = (CallbackReturn <T, U, V, E, R>)eventTable[eventType] + handler;
 }
Esempio n. 8
0
 public static void AddReturnListener <T, U, V>(string eventType, CallbackReturn <T, U, V> handler)
 {
     OnListenerAdding(eventType, handler);
     eventTable[eventType] = (CallbackReturn <T, U, V>)Delegate.Combine((CallbackReturn <T, U, V>)Delegate.Remove((CallbackReturn <T, U, V>)eventTable[eventType], handler), handler);
 }
Esempio n. 9
0
        /// <summary>
        /// 用于从文件中读取“键”在“值”中无引用的字典
        /// </summary>
        /// <typeparam name="TKey">键</typeparam>
        /// <typeparam name="TValue">值</typeparam>
        /// <param name="outputDic">输出字典,可以为空</param>
        /// <param name="xqFile">二进制文件</param>
        /// <param name="keyLoader">键读取方法</param>
        /// <param name="valueLoader">值读取方法</param>
        /// <param name="needClear">true 需要清除原有Dictionary的内容</param>
        /// <returns>true 读取成功</returns>
        public static bool LoadToDic <TKey, TValue>(ref Dictionary <TKey, TValue> outputDic, XQFileStream xqFile, CallbackReturn <TKey, XQFileStream> keyLoader, CallbackReturn <TValue, XQFileStream> valueLoader, bool needClear)
        {
            bool res = false;

            do
            {
                if (outputDic == null)
                {
                    outputDic = new Dictionary <TKey, TValue>();
                }
                else if (needClear)
                {
                    outputDic.Clear();
                }

                if (xqFile == null || !xqFile.IsOpen())
                {
                    break;
                }

                if (keyLoader == null || valueLoader == null)
                {
                    break;
                }

                TKey   key   = default(TKey);
                TValue value = default(TValue);
                ushort count = xqFile.ReadUShort();
                for (ushort i = 0; i < count; i++)
                {
                    key   = keyLoader(xqFile);
                    value = valueLoader(xqFile);
                    if (outputDic.ContainsKey(key))
                    {
                        continue;
                    }

                    outputDic.Add(key, value);
                }

                res = true;
            } while (false);

            return(res);
        }