예제 #1
0
        private void SetupScreens()
        {
            if (_chatScreen == null)
            {
                var screenSize = new Vector2(ChatWidth, ChatHeight);
                _chatScreen = FloatingScreen.CreateFloatingScreen(screenSize, true, ChatPosition, Quaternion.identity, 0f, true);
                var rectMask2D = _chatScreen.GetComponent <RectMask2D>();
                if (rectMask2D)
                {
                    Destroy(rectMask2D);
                }

                _chatContainer = new GameObject("chatContainer");
                _chatContainer.transform.SetParent(_chatScreen.transform, false);
                _chatContainer.AddComponent <RectMask2D>().rectTransform.sizeDelta = screenSize;

                var canvas = _chatScreen.GetComponent <Canvas>();
                canvas.sortingOrder = 3;

                _chatScreen.SetRootViewController(this, AnimationType.None);
                _rootGameObject = new GameObject();
                DontDestroyOnLoad(_rootGameObject);

                _chatMoverMaterial       = Instantiate(BeatSaberUtils.UINoGlowMaterial);
                _chatMoverMaterial.color = Color.clear;

                var renderer = _chatScreen.handle.gameObject.GetComponent <Renderer>();
                renderer.material             = _chatMoverMaterial;
                renderer.material.mainTexture = _chatMoverMaterial.mainTexture;

                _chatScreen.transform.SetParent(_rootGameObject.transform);
                _chatScreen.ScreenRotation = Quaternion.Euler(ChatRotation);

                _bg                      = _chatScreen.GetComponentInChildren <ImageView>();
                _bg.material             = Instantiate(_bg.material);
                _bg.material.mainTexture = BeatSaberUtils.UINoGlowMaterial.mainTexture;
                _bg.color                = BackgroundColor;

                AddToVRPointer();
                UpdateChatUI();
            }
        }
        public void Initialize()
        {
            var is360Level = _beatmapData.spawnRotationEventsCount > 0;
            var pos        = is360Level ? _config.Chart360LevelPosition : _config.ChartStandardLevelPosition;
            var rot        = is360Level
                                ? Quaternion.Euler(_config.Chart360LevelRotation)
                                : Quaternion.Euler(_config.ChartStandardLevelRotation);

            _floatingScreen = FloatingScreen.CreateFloatingScreen(_config.ChartSize, false, pos, rot, curvatureRadius: 0f, hasBackground: _config.HasBackground);
            _floatingScreen.SetRootViewController(this, AnimationType.None);
            _floatingScreen.name = nameof(SongChartVisualizer);

            if (_config.HasBackground)
            {
                var imageView = _floatingScreen.GetComponentInChildren <ImageView>();
                imageView.material = _assetLoader.UINoGlowMaterial;
                imageView.color    = _config.CombinedBackgroundColor;

                transform.SetParent(imageView.transform);
            }

            if (_audioTimeSyncController.songLength < 0)
            {
                _shouldNotRunTick = true;
                return;
            }

            // _siraLog.Debug($"There are {_beatmapData.beatmapObjectsData.Count(x => x.beatmapObjectType == BeatmapObjectType.Note)} notes");
            // _siraLog.Debug($"There are {_beatmapData.beatmapLinesData.Count} lines");

            _npsSections = GetNpsSections(_beatmapData);
#if DEBUG
            for (var i = 0; i < _npsSections.Count; i++)
            {
                var npsInfos = _npsSections[i];
                _siraLog.Debug($"Nps at section {i + 1}: {npsInfos.Nps} (from [{npsInfos.FromTime}] to [{npsInfos.ToTime}])");
            }
#endif

            _siraLog.Debug("Loading assetbundle..");
            var assembly = Assembly.GetExecutingAssembly();
            using (var stream = assembly.GetManifestResourceStream("SongChartVisualizer.UI.linegraph"))
            {
                _assetBundle = AssetBundle.LoadFromStream(stream);
            }

            if (!_assetBundle)
            {
                _siraLog.Warn("Failed to load AssetBundle! The chart will not work properly..");
            }
            else
            {
                var prefab = _assetBundle.LoadAsset <GameObject>("LineGraph");
                var sprite = _assetBundle.LoadAsset <Sprite>("Circle");
                var go     = Instantiate(prefab, transform);

                go.transform.Translate(0.04f, 0, 0);
                _windowGraph = go.AddComponent <WindowGraph>();
                _windowGraph.circleSprite          = sprite;
                _windowGraph.transform.localScale /= 10;
                var npsValues = _npsSections.Select(info => info.Nps).ToList();
                _windowGraph.ShowGraph(npsValues, false, linkColor: _config.LineColor);

                _currentSectionIdx = 0;
                _currentSection    = _npsSections[_currentSectionIdx];

                CreateSelfCursor(_config.PointerColor);

                if (_config.PeakWarning)
                {
                    var highestValue = _npsSections.Max(info => info.Nps);
                    _hardestSectionIdx = _npsSections.FindIndex(info => Math.Abs(info.Nps - highestValue) < 0.001f);
                    PrepareWarningText();

                    FadeInTextIfNeeded();
                }
            }
        }