Beispiel #1
0
        public Client() : base()
        {
            _threadDispatcher = new GameObject($"StreamLabsClientUnityDispatcher-{Guid.NewGuid()}");
            _threadDispatcher.AddComponent <ThreadDispatcher>();
            UnityEngine.Object.DontDestroyOnLoad(_threadDispatcher);

            base.OnConnected    += ((object sender, bool e) => { ThreadDispatcher.Instance().Enqueue(() => OnConnected?.Invoke(sender, e)); });
            base.OnDisconnected += ((object sender, bool e) => { ThreadDispatcher.Instance().Enqueue(() => OnDisconnected?.Invoke(sender, e)); });
            base.OnError        += ((object sender, string e) => { ThreadDispatcher.Instance().Enqueue(() => OnError?.Invoke(sender, e)); });
            base.OnUndocumented += ((object sender, string e) => { ThreadDispatcher.Instance().Enqueue(() => OnUndocumented?.Invoke(sender, e)); });

            base.OnDonation     += ((object sender, StreamlabsEvent <DonationMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnDonation?.Invoke(sender, e)); });
            base.OnStreamlabels += ((object sender, StreamlabelsEvent e) => { ThreadDispatcher.Instance().Enqueue(() => OnStreamlabels?.Invoke(sender, e)); });

            base.OnTwitchFollow       += ((object sender, StreamlabsEvent <TwitchFollowMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchFollow?.Invoke(sender, e)); });
            base.OnTwitchSubscription += ((object sender, StreamlabsEvent <TwitchSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchSubscription?.Invoke(sender, e)); });
            base.OnTwitchHost         += ((object sender, StreamlabsEvent <TwitchHostMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchHost?.Invoke(sender, e)); });
            base.OnTwitchCheer        += ((object sender, StreamlabsEvent <TwitchCheerMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnTwitchCheer?.Invoke(sender, e)); });

            base.OnYouTubeSubscription += ((object sender, StreamlabsEvent <YouTubeSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSubscription?.Invoke(sender, e)); });
            base.OnYouTubeSponsor      += ((object sender, StreamlabsEvent <YouTubeSponsorMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSponsor?.Invoke(sender, e)); });
            base.OnYouTubeSuperchat    += ((object sender, StreamlabsEvent <YouTubeSuperchatMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnYouTubeSuperchat?.Invoke(sender, e)); });

            base.OnMixerFollow       += ((object sender, StreamlabsEvent <MixerFollowMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerFollow?.Invoke(sender, e)); });
            base.OnMixerSubscription += ((object sender, StreamlabsEvent <MixerSubscriptionMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerSubscription?.Invoke(sender, e)); });
            base.OnMixerHost         += ((object sender, StreamlabsEvent <MixerHostMessage> e) => { ThreadDispatcher.Instance().Enqueue(() => OnMixerHost?.Invoke(sender, e)); });
        }
Beispiel #2
0
 public void Invoke <T>(Func <Task <T> > func, Action <T> action)
 {
     Task.Run(func).ContinueWith((x) =>
     {
         var value = x.Result;
         ThreadDispatcher.Instance().Enqueue(() => action.Invoke(value));
     });
 }