Esempio n. 1
0
 internal static void CheckCallback <T>(Action <T> callback, CallbackType callbackType)
 {
     if (callback == null)
     {
         throw new ArgumentException(string.Format("Missing {0} Callback", callbackType.ToString()));
     }
 }
    public Callback getCallback(CallbackType callbackType)
    {
        Callback callback;

        if (callbackQueue.Count > 0)
        {
            callback = callbackQueue.Dequeue();
            callback.reset();
        }
        else
        {
            callback = createNewCallback();
        }
        callback.type = callbackType;
        switch (callbackType)
        {
        case CallbackType.DISPOSABLE:
            disposableCallbacks.Add(callback);
            break;

        case CallbackType.PERMANENT:
            permanentCallback.Add(callback);
            break;

        default:
            Debug2.LogError("Wrong callbackType" + callbackType.ToString());
            break;
        }

        return(callback);
    }
Esempio n. 3
0
 /// <summary>
 /// 测试前初始化
 /// </summary>
 /// <param name="callbackType"></param>
 /// <param name="type"></param>
 /// <param name="mul"></param>
 protected void start(CallbackType callbackType, TestType type, int callbackMul = 1)
 {
     this.callbackType = callbackType;
     this.type         = type;
     count             = (callbackType == CallbackType.Synchronous ? loopCount / 50 : loopCount);
     callbackCount     = count * callbackMul;
     errorCount        = 0;
     Console.WriteLine("start " + count.toString() + " " + callbackType.ToString() + " " + type.ToString() + (isFile ? " + File" : null));
     waitEvent.Reset();
     time.Restart();
 }
Esempio n. 4
0
    private void AddCallbackInternal(CallbackType type, Action action)
    {
        if (type == CallbackType.UPDATE)
        {
            if (!Instance.updateActions.Contains(action))
            {
                Instance.updateActions.Add(action);
                return;
            }
        }

        if (type == CallbackType.FIXED_UPDATE)
        {
            if (!Instance.fixedUpdateActions.Contains(action))
            {
                Instance.fixedUpdateActions.Add(action);
                return;
            }
        }

        if (type == CallbackType.LATE_UPDATE)
        {
            if (!Instance.lateUpdateActions.Contains(action))
            {
                Instance.lateUpdateActions.Add(action);
                return;
            }
        }

        //FIXME current system is 2 x slower possibly because of garbage being created
        //in ProcessCallbacks()
        return;

        NamedAction namedAction = new NamedAction();

        // Give that shit a name so we can refer to it in profiler.
#if UNITY_EDITOR
        namedAction.Name = action.Target != null?
                           action.Target.GetType().ToString() + "." + action.Method.ToString() :
                               action.Method.ToString();
#endif
        namedAction.Action = action;

        CallbackCollection callbackCollection = collections[type];

        // Check if it's already been added, should never be the case so avoiding the overhead in build.
#if UNITY_EDITOR
        if (callbackCollection.ActionDictionary.ContainsKey(action))
        {
            Debug.LogErrorFormat("Failed to add callback '{0}' to CallbackEvent '{1}' because it is already added.", namedAction.Name, type.ToString());
            return;
        }
#endif

        callbackCollection.ActionList.Add(namedAction);
        callbackCollection.ActionDictionary.Add(action, namedAction);
    }
Esempio n. 5
0
    private void AddCallbackInternal(CallbackType type, Action action)
    {
        NamedAction namedAction = new NamedAction();

        // Give that shit a name so we can refer to it in profiler.
#if UNITY_EDITOR
        namedAction.Name = action.Target != null?
                           action.Target.GetType().ToString() + "." + action.Method.ToString() :
                               action.Method.ToString();
#endif
        namedAction.Action = action;

        CallbackCollection callbackCollection = collections[type];

        // Check if it's already been added, should never be the case so avoiding the overhead in build.
#if UNITY_EDITOR
        if (callbackCollection.ActionDictionary.ContainsKey(action))
        {
            Debug.LogErrorFormat("Failed to add callback '{0}' to CallbackEvent '{1}' because it is already added.", namedAction.Name, type.ToString());
            return;
        }
#endif

        callbackCollection.ActionList.Add(namedAction);
        callbackCollection.ActionDictionary.Add(action, namedAction);
    }
Esempio n. 6
0
        internal static void SendCallbacks <T>(IJsonPluggableLibrary jsonPluggableLibrary, RequestState <T> asynchRequestState,
                                               List <object> itemMessage, CallbackType callbackType, bool checkType)
        {
            if (asynchRequestState.ChannelEntities != null)
            {
                SendCallbacks <T> (jsonPluggableLibrary, asynchRequestState.ChannelEntities, itemMessage, callbackType, checkType);
            }
            else
            {
                #if (ENABLE_PUBNUB_LOGGING)
                LoggingMethod.WriteToLog(string.Format("DateTime {0}, SendCallbacks1: Callback type={1}", DateTime.Now.ToString(), callbackType.ToString()), LoggingMethod.LevelInfo);
                #endif

                if (callbackType.Equals(CallbackType.Success))
                {
                    GoToCallback <T> (itemMessage, asynchRequestState.SuccessCallback, jsonPluggableLibrary);
                }
            }
        }
Esempio n. 7
0
    private static void AddCallbackInternal(Dictionary <CallbackType, CallbackCollection> collection, CallbackType type, Func <bool> callback)
    {
        if (!collection.ContainsKey(type))
        {
            collection.Add(type, new CallbackCollection());
        }

        NamedFunc namedFunc = new NamedFunc();

        // We do PHASED_DEBUG instead of UNITY_EDITOR in case we connect profiler in debug build
#if PHASED_DEBUG
        namedFunc.Name = callback.Target != null?
                         callback.Target.GetType().ToString() + "." + callback.Method.ToString() :
                             callback.Method.ToString();
#endif
        namedFunc.Func = callback;

        CallbackCollection callbackCollection = collection[type];

        if (callbackCollection.FunctionsDictionary.ContainsKey(callback))
        {
            Debug.LogErrorFormat("Failed to add callback '{0}' to CallbackEvent '{1}' because it is already added.", namedFunc.Name, type.ToString());
            return;
        }

        callbackCollection.FunctionsList.Add(namedFunc);
        callbackCollection.FunctionsDictionary.Add(callback, namedFunc);
    }