示例#1
0
        public override void Start()
        {
            _containerTree.DisplayName = $"Protobuf: {Path.GetFileName(TypedSettings.FilePath)}";
            _input = File.OpenRead(TypedSettings.FilePath !);
            Converter?.SetInitTRS(Vector3.zero, Quaternion.identity);
            _parsersChain.SetConverter(Converter);

            _frames         = new FramesCollection <Frame>(ReadCommands, TryGetSize());
            _threadWorker   = new ThreadQueueWorker();
            _timer          = new Timer(DelayBetweenFrames);
            _timer.Elapsed += (_, __) =>
            {
                _threadWorker.Enqueue(() =>
                {
                    if (NextFrame())
                    {
                        return;
                    }
                    _timer?.Stop();
                    MainThreadInvoker.Enqueue(() => Finished?.Invoke());
                });
            };
        }
 public void OnChannelResourceDataCached(IChatChannel channel, Dictionary <string, IChatResourceData> resources)
 {
     MainThreadInvoker.Invoke(() =>
     {
         int count = 0;
         if (_chatConfig.PreCacheAnimatedEmotes)
         {
             foreach (var emote in resources)
             {
                 if (emote.Value.IsAnimated)
                 {
                     StartCoroutine(ChatImageProvider.instance.PrecacheAnimatedImage(emote.Value.Uri, emote.Key, 110));
                     count++;
                 }
             }
             Logger.log.Info($"Pre-cached {count} animated emotes.");
         }
         else
         {
             Logger.log.Warn("Pre-caching of animated emotes disabled by the user. If you're experiencing lag, re-enable emote precaching.");
         }
     });
 }
        private IEnumerator CheckCollisionCoroutine()
        {
            while (true)
            {
                var mousePosition = Mouse.current.position.ReadValue();
                var ray           = _camera.ScreenPointToRay(mousePosition);
                Task.Run(() =>
                {
                    var collision = CollisionCloud.FindCollided(ray);

                    if (collision.HasValue)
                    {
                        MainThreadInvoker.Enqueue(
                            () => ProcessRaycast(collision.Value.container, collision.Value.item, mousePosition));
                    }
                    else
                    {
                        MainThreadInvoker.Enqueue(HideViewer);
                    }
                });
                yield return(new WaitForSeconds(CollisionCheckTimeout));
            }
            // ReSharper disable once IteratorNeverReturns
        }
示例#4
0
        public async void OnTextMessageReceived(IChatMessage msg)
        {
            string parsedMessage = await ChatMessageBuilder.BuildMessage(msg, _chatFont);

            MainThreadInvoker.Invoke(() =>
            {
                if (_lastMessage != null && !msg.IsSystemMessage && _lastMessage.Text.ChatMessage.Id == msg.Id)
                {
                    // If the last message received had the same id and isn't a system message, then this was a sub-message of the original and may need to be highlighted along with the original message
                    _lastMessage.SubText.text        = parsedMessage;
                    _lastMessage.SubText.ChatMessage = msg;
                    _lastMessage.SubTextEnabled      = true;
                    UpdateMessage(_lastMessage);
                }
                else
                {
                    var newMsg = TextPool.Alloc();
                    newMsg.Text.ChatMessage = msg;
                    newMsg.Text.text        = parsedMessage;
                    AddMessage(newMsg);
                    _lastMessage = newMsg;
                }
            });
        }
 public void OnDisable()
 {
     if (_svcs != null)
     {
         _svcs.OnJoinChannel               -= QueueOrSendOnJoinChannel;
         _svcs.OnTextMessageReceived       -= QueueOrSendOnTextMessageReceived;
         _svcs.OnChatCleared               -= QueueOrSendOnClearChat;
         _svcs.OnMessageCleared            -= QueueOrSendOnClearMessage;
         _svcs.OnChannelResourceDataCached -= QueueOrSendOnChannelResourceDataCached;
         BSEvents.menuSceneLoadedFresh     -= BSEvents_menuSceneLoadedFresh;
     }
     if (_sc != null)
     {
         //_sc.OnLogReceived -= _sc_OnLogReceived;
         _sc.StopAllServices();
     }
     if (_chatDisplay != null)
     {
         Destroy(_chatDisplay.gameObject);
         _chatDisplay = null;
     }
     MainThreadInvoker.ClearQueue();
     ChatImageProvider.ClearCache();
 }
示例#6
0
        public void Compute(MonoBehaviour settings, IClusterizationAlgorithm algorithm)
        {
            var pair = _clusterableContainers[ContainersSelector.value];
            var list = (pair.container as IClusterable) !.GetAllPoints().ToList();

            Task.Run(() =>
            {
                try
                {
                    var data      = algorithm.Compute(list);
                    var clustered = CreateClustersContainers(pair.name, data, pair.container as IVisible);
                    MainThreadInvoker.Enqueue(() =>
                    {
                        DataSourcesManager.AddDataSource(clustered);
                        settings.enabled = true;
                    });
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                    MainThreadInvoker.Enqueue(() => { settings.enabled = true; });
                }
            });
        }
        public override void Rebuild(CanvasUpdate update)
        {
            if (update == CanvasUpdate.LatePreRender)
            {
                MainThreadInvoker.Invoke(() =>
                {
                    ClearImages();
                });
                for (int i = 0; i < textInfo.characterCount; i++)
                {
                    TMP_CharacterInfo c = textInfo.characterInfo[i];
                    if (!c.isVisible || string.IsNullOrEmpty(text) || c.index >= text.Length)
                    {
                        // Skip invisible/empty/out of range chars
                        continue;
                    }

                    uint character = text[c.index];
                    if (c.index + 1 < text.Length && char.IsSurrogatePair(text[c.index], text[c.index + 1]))
                    {
                        // If it's a surrogate pair, convert the character
                        character = (uint)char.ConvertToUtf32(text[c.index], text[c.index + 1]);
                    }

                    if (FontInfo == null || !FontInfo.TryGetImageInfo(character, out var imageInfo) || imageInfo is null)
                    {
                        // Skip characters that have no imageInfo registered
                        continue;
                    }

                    MainThreadInvoker.Invoke(() =>
                    {
                        var img = _imagePool.Alloc();
                        try
                        {
                            if (imageInfo.AnimControllerData != null)
                            {
                                img.animStateUpdater.controllerData = imageInfo.AnimControllerData;
                                img.sprite = imageInfo.AnimControllerData.sprites[imageInfo.AnimControllerData.uvIndex];
                            }
                            else
                            {
                                img.sprite = imageInfo.Sprite;
                            }
                            img.material = BeatSaberUtils.UINoGlowMaterial;
                            img.rectTransform.localScale = new Vector3(fontScale * 1.08f, fontScale * 1.08f, fontScale * 1.08f);
                            img.rectTransform.sizeDelta  = new Vector2(imageInfo.Width, imageInfo.Height);
                            img.rectTransform.SetParent(rectTransform, false);
                            img.rectTransform.localPosition = c.topLeft - new Vector3(0, imageInfo.Height * fontScale * 0.558f / 2);
                            img.rectTransform.localRotation = Quaternion.identity;
                            img.gameObject.SetActive(true);
                            _currentImages.Add(img);
                        }
                        catch (Exception ex)
                        {
                            Logger.log.Error($"Exception while trying to overlay sprite. {ex.ToString()}");
                            _imagePool.Free(img);
                        }
                    });
                }
            }
            base.Rebuild(update);
            if (update == CanvasUpdate.LatePreRender)
            {
                MainThreadInvoker.Invoke(OnLatePreRenderRebuildComplete);
            }
        }
示例#8
0
 public void Clear()
 {
     MainThreadInvoker.Enqueue(() => _info?.Clear());
 }
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Rebuild the text
        /// </summary>
        /// <param name="p_UpdateType">Update type</param>
        public override void Rebuild(CanvasUpdate p_UpdateType)
        {
            if (p_UpdateType == CanvasUpdate.LatePreRender)
            {
                MainThreadInvoker.Invoke(() => ClearImages());

                for (int l_I = 0; l_I < textInfo.characterCount; l_I++)
                {
                    /// Skip invisible/empty/out of range chars
                    TMP_CharacterInfo l_CharacterInfo = textInfo.characterInfo[l_I];
                    if (!l_CharacterInfo.isVisible || string.IsNullOrEmpty(text) || l_CharacterInfo.index >= text.Length)
                    {
                        continue;
                    }

                    /// If it's a surrogate pair, convert the character
                    uint l_Character = text[l_CharacterInfo.index];
                    if (l_CharacterInfo.index + 1 < text.Length && char.IsSurrogatePair(text[l_CharacterInfo.index], text[l_CharacterInfo.index + 1]))
                    {
                        l_Character = (uint)char.ConvertToUtf32(text[l_CharacterInfo.index], text[l_CharacterInfo.index + 1]);
                    }

                    /// Skip characters that have no imageInfo registered
                    if (FontInfo == null || !FontInfo.TryGetImageInfo(l_Character, out var l_ImageInfo) || l_ImageInfo is null)
                    {
                        continue;
                    }

                    MainThreadInvoker.Invoke(() =>
                    {
                        var l_Image = m_ImagePool.Alloc();
                        try
                        {
                            if (l_ImageInfo.AnimControllerData != null)
                            {
                                l_Image.AnimStateUpdater.controllerData = l_ImageInfo.AnimControllerData;
                                l_Image.sprite = l_ImageInfo.AnimControllerData.sprites[l_ImageInfo.AnimControllerData.uvIndex];
                            }
                            else
                            {
                                l_Image.sprite = l_ImageInfo.Sprite;
                            }

                            l_Image.material = BeatSaberPlus.Utils.UnityMaterial.UINoGlowMaterial;
                            l_Image.rectTransform.localScale = new Vector3(fontScale * 1.08f, fontScale * 1.08f, fontScale * 1.08f);
                            l_Image.rectTransform.sizeDelta  = new Vector2(l_ImageInfo.Width, l_ImageInfo.Height);
                            l_Image.rectTransform.SetParent(rectTransform, false);
                            l_Image.rectTransform.localPosition = l_CharacterInfo.topLeft - new Vector3(0, l_ImageInfo.Height * fontScale * 0.558f / 2);
                            l_Image.rectTransform.localRotation = Quaternion.identity;
                            l_Image.gameObject.SetActive(true);
                            m_CurrentImages.Add(l_Image);
                        }
                        catch (Exception p_Exception)
                        {
                            Logger.Instance?.Error("Exception while trying to overlay sprite");
                            Logger.Instance?.Error(p_Exception);

                            m_ImagePool.Free(l_Image);
                        }
                    });
                }
            }

            base.Rebuild(p_UpdateType);

            if (p_UpdateType == CanvasUpdate.LatePreRender)
            {
                MainThreadInvoker.Invoke(OnLatePreRenderRebuildComplete);
            }
        }