Esempio n. 1
0
 protected override void SetReferences()
 {
     if (SingletonUtil.TryInit(ref Instance, this, gameObject))
     {
         base.SetReferences();
     }
 }
Esempio n. 2
0
 // Must be colled to setup the class's functionality
 void init()
 {
     // Singleton method returns a bool depending on whether this object is the instance of the class
     if (SingletonUtil.TryInit(ref _instance, this, gameObject, true))
     {
         if (useCustomPaths)
         {
             loader = new AudioLoader(customJSONPath, customAudioPath);
         }
         else
         {
             loader = AudioLoader.Default;
         }
         fileList = loader.Load();
         if (!fileList.AreEventsSubscribed)
         {
             fileList.SubscribeEvents();
         }
         fileList.PopulateGroups();
         initFileDictionary(fileList);
         addAudioEvents();
         subscribeEvents();
         if (isAudioListener)
         {
             addAudioListener();
         }
         preloadFiles(fileList.Files);
         if (playMusicOnInit)
         {
             playMainMusic();
         }
     }
 }
 // Must be colled to setup the class's functionality
 void Init()
 {
     // Singleton method returns a bool depending on whether this object is the instance of the class
     if (SingletonUtil.TryInit(ref Instance, this, gameObject, true))
     {
         loader   = new AudioLoader(path);
         fileList = loader.Load();
         if (!fileList.AreEventsSubscribed)
         {
             fileList.SubscribeEvents();
         }
         fileList.PopulateGroups();
         InitFileDictionary(fileList);
         AddAudioEvents();
         SubscribeEvents();
         if (isAudioListener)
         {
             AddAudioListener();
         }
         PreloadFiles(fileList.Files);
         // TODO: Enable after tracks have been delivered
         // initCyclingAudio();
         if (playMusicOnInit)
         {
             playMainMusic();
         }
     }
 }
Esempio n. 4
0
    protected override void SetReferences()
    {
        bool shouldInitialize = true;

        if (IsSingleton && !SingletonUtil.TryInit(ref Instance, this, gameObject))
        {
            shouldInitialize = false;
        }
        if (shouldInitialize)
        {
            createAgents();
            createGrid(agents);
        }
    }
Esempio n. 5
0
        /// <summary>
        /// 回调接收处理事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="eventArgs"></param>
        protected virtual void ReceivedHandler(object sender, BasicDeliverEventArgs eventArgs)
        {
            try
            {
                bool   canAck     = false;                                                //应答结果
                int    retryCount = 0;                                                    //第几次重试
                string messageId  = eventArgs.BasicProperties.MessageId;                  //消息Id
                IDictionary <string, object> headers = eventArgs.BasicProperties.Headers; //头部信息
                if (headers != null && headers.ContainsKey(RabbitmqContext.RetryCountKeyName))
                {
                    retryCount = (int)headers[RabbitmqContext.RetryCountKeyName];
                    _log.Warn($"队列:{_config.QueueName},MessageId:{messageId},第:{retryCount}次重试开始!!!");
                }

                try
                {
                    ConsumerContext context    = eventArgs.GetConsumerContext();
                    string          pluginPath = RabbitmqContext.Config.PluginPath;
                    var             instance   = SingletonUtil.GetInstance <IConsumer>(pluginPath, _config);
                    ResponseResult  result     = instance.Handler(context);
                    canAck = true;
                    //业务处理成功
                    SuccessHandler(sender, result, eventArgs);
                }
                catch (Exception ex)
                {
                    retryCount++;
                    _log.Error($"队列:{_config.QueueName},MessageId:{messageId},第:{retryCount}次消费发生异常:", ex);
                    canAck = RetryHandler(retryCount, _retryQueueName, eventArgs);
                }
                //处理应答
                AnswerHandler(canAck, eventArgs);
            }
            catch (Exception ex)
            {
                _log.Error($"队列:{_config.QueueName},MessageId:{eventArgs.BasicProperties.MessageId},消费时发生未经处理异常:", ex);
            }
        }
Esempio n. 6
0
 protected override void CleanupReferences()
 {
     base.CleanupReferences();
     SingletonUtil.TryCleanupSingleton(ref Instance, this);
 }
Esempio n. 7
0
 static Singleton()
 {
     instance = SingletonUtil.CreateSingleton <T>();
     instance.InitSingleton();
 }