//Repeat The Thing
        public void OnUpdate()
        {
            //Slowing The Repeat Thing
            if (Time.time > nextActionTime)
            {
                nextActionTime += period;

                //Loading In Things I Need
                PlayerController HEL = Resources.FindObjectsOfTypeAll <PlayerController>().FirstOrDefault();
                GamePauseManager GMM = Resources.FindObjectsOfTypeAll <GamePauseManager>().FirstOrDefault();
                GameplayManager  PMM = Resources.FindObjectsOfTypeAll <GameplayManager>().FirstOrDefault();

                //Finding Saber Location
                if (HEL == null)
                {
                    return;
                }
                Saber   SaberThatIsLeft          = HEL.leftSaber;
                Saber   SaberThatIsRight         = HEL.rightSaber;
                Vector3 LeftSaberHandleLocation  = SaberThatIsLeft.handlePos;
                Vector3 RightSaberHandleLocation = SaberThatIsRight.handlePos;

                //When the game is paused, saber position freezes. This if statement is to make sure that when the game is unpaused, it doesn't take the value which set off the tracking issue in the first place (if that makes any sense)
                if (GMM != null && GMM.pause == true)
                {
                    PreviousLeftSaberHandleLocation  = RightSaberHandleLocation;
                    PreviousLeftSaberHandleLocation2 = LeftSaberHandleLocation;
                }
                else
                {
                    //FPS CHECKER
                    float fps = 1.0f / Time.deltaTime;
                    if (fps < 40.0f)
                    {
                        if (PMM != null)
                        {
                            PMM.Pause();
                        }
                    }

                    //TRACKING DETECTOR
                    if (PreviousLeftSaberHandleLocation == LeftSaberHandleLocation || PreviousLeftSaberHandleLocation2 == RightSaberHandleLocation)
                    {
                        if (PMM != null)
                        {
                            PMM.Pause();
                        }
                    }

                    //Set Saber Locations To Previous Saber Location
                    PreviousLeftSaberHandleLocation  = LeftSaberHandleLocation;
                    PreviousLeftSaberHandleLocation2 = RightSaberHandleLocation;
                }
            }
        }
Beispiel #2
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else
     {
         Destroy(this);
     }
 }
        private void Awake()
        {
            Config.LoadConfig();

            gamePauseManager = Resources.FindObjectsOfTypeAll <GamePauseManager>().First();

            gameObject.transform.position    = Config.Position;
            gameObject.transform.eulerAngles = Config.Rotation;
            gameObject.transform.localScale  = Config.Scale;

            mainCanvas            = gameObject.AddComponent <Canvas>();
            mainCanvas.renderMode = RenderMode.WorldSpace;
            var canvasTransform = mainCanvas.transform as RectTransform;

            canvasTransform.sizeDelta = Config.Size;

            var fontAsset = Resources.FindObjectsOfTypeAll <TMP_FontAsset>().First((TMP_FontAsset x) => x.name == "Teko-Medium SDF No Glow");

            var titleGameObject = new GameObject("Countdown Title");

            titleGameObject.SetActive(false);
            titleText = titleGameObject.AddComponent <TextMeshProUGUI>();
            var textTransform = titleText.transform as RectTransform;

            titleText.font = fontAsset;
            textTransform.SetParent(mainCanvas.transform, false);
            titleText.text = "Play time remaining:";
            titleText.enableWordWrapping    = true;
            titleText.autoSizeTextContainer = true;
            titleText.alignment             = TextAlignmentOptions.Center;
            textTransform.anchorMin         = new Vector2(0.5f, 0.7f);
            textTransform.anchorMax         = new Vector2(0.5f, 0.7f);
            titleGameObject.SetActive(true);

            var timeGameObject = new GameObject("Countdown Text");

            timeGameObject.SetActive(false);
            timeText      = timeGameObject.AddComponent <TextMeshProUGUI>();
            textTransform = timeText.transform as RectTransform;
            timeText.font = fontAsset;
            textTransform.SetParent(mainCanvas.transform, false);
            timeText.text = $"{TimeSpan.FromSeconds(timeRemaining).ToString(@"hh\:mm\:ss")}";
            timeText.enableWordWrapping    = true;
            timeText.autoSizeTextContainer = true;
            timeText.alignment             = TextAlignmentOptions.Center;
            timeGameObject.SetActive(true);
        }
Beispiel #4
0
        private void OnActiveSceneChanged(Scene oldScene, Scene newScene)
        {
            GameStatus gameStatus = statusManager.gameStatus;

            gameStatus.scene = newScene.name;

            if (newScene.name == "MenuCore")
            {
                // Menu
                gameStatus.scene = "Menu";

                Gamemode.Init();

                // TODO: get the current song, mode and mods while in menu
                gameStatus.ResetMapInfo();

                gameStatus.ResetPerformance();

                // Release references for AfterCutScoreBuffers that don't resolve due to player leaving the map before finishing.
                noteCutMapping.Clear();

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "menu");
            }
            else if (newScene.name == "GameCore")
            {
                // In game
                gameStatus.scene = "Song";

                gamePauseManager = FindFirstOrDefault <GamePauseManager>();
                scoreController  = FindFirstOrDefault <ScoreController>();
                gameplayManager  = Resources.FindObjectsOfTypeAll <StandardLevelGameplayManager>().FirstOrDefault() as MonoBehaviour ?? Resources.FindObjectsOfTypeAll <MissionLevelGameplayManager>().FirstOrDefault();
                beatmapObjectCallbackController  = FindFirstOrDefault <BeatmapObjectCallbackController>();
                gameplayModifiersSO              = FindFirstOrDefault <GameplayModifiersModelSO>();
                audioTimeSyncController          = FindFirstOrDefault <AudioTimeSyncController>();
                playerHeadAndObstacleInteraction = FindFirstOrDefault <PlayerHeadAndObstacleInteraction>();
                gameEnergyCounter = FindFirstOrDefault <GameEnergyCounter>();

                gameplayCoreSceneSetupData = BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData;

                // Register event listeners
                // private GameEvent GamePauseManager#_gameDidPauseSignal
                AddSubscriber(gamePauseManager, "_gameDidPauseSignal", OnGamePause);
                // private GameEvent GamePauseManager#_gameDidResumeSignal
                AddSubscriber(gamePauseManager, "_gameDidResumeSignal", OnGameResume);
                // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created
                scoreController.noteWasCutEvent += OnNoteWasCut;
                // public ScoreController#noteWasMissedEvent<NoteData, int multiplier>
                scoreController.noteWasMissedEvent += OnNoteWasMissed;
                // public ScoreController#scoreDidChangeEvent<int, int> // score
                scoreController.scoreDidChangeEvent += OnScoreDidChange;
                // public ScoreController#comboDidChangeEvent<int> // combo
                scoreController.comboDidChangeEvent += OnComboDidChange;
                // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1]
                scoreController.multiplierDidChangeEvent += OnMultiplierDidChange;
                // private GameEvent GameplayManager#_levelFinishedSignal
                AddSubscriber(gameplayManager, "_levelFinishedSignal", OnLevelFinished);
                // private GameEvent GameplayManager#_levelFailedSignal
                AddSubscriber(gameplayManager, "_levelFailedSignal", OnLevelFailed);
                // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent
                beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger;

                IDifficultyBeatmap diff  = gameplayCoreSceneSetupData.difficultyBeatmap;
                IBeatmapLevel      level = diff.level;

                gameStatus.partyMode = Gamemode.IsPartyActive;
                gameStatus.mode      = Gamemode.GameMode;

                gameplayModifiers = gameplayCoreSceneSetupData.gameplayModifiers;
                PlayerSpecificSettings playerSettings   = gameplayCoreSceneSetupData.playerSpecificSettings;
                PracticeSettings       practiceSettings = gameplayCoreSceneSetupData.practiceSettings;

                float songSpeedMul = gameplayModifiers.songSpeedMul;
                if (practiceSettings != null)
                {
                    songSpeedMul = practiceSettings.songSpeedMul;
                }
                float modifierMultiplier = gameplayModifiersSO.GetTotalMultiplier(gameplayModifiers);

                gameStatus.songName        = level.songName;
                gameStatus.songSubName     = level.songSubName;
                gameStatus.songAuthorName  = level.songAuthorName;
                gameStatus.levelAuthorName = level.levelAuthorName;
                gameStatus.songBPM         = level.beatsPerMinute;
                gameStatus.noteJumpSpeed   = diff.noteJumpMovementSpeed;
                gameStatus.songHash        = level.levelID.Substring(0, Math.Min(32, level.levelID.Length));
                gameStatus.songTimeOffset  = (long)(level.songTimeOffset * 1000f / songSpeedMul);
                gameStatus.length          = (long)(level.beatmapLevelData.audioClip.length * 1000f / songSpeedMul);
                gameStatus.start           = GetCurrentTime() - (long)(audioTimeSyncController.songTime * 1000f / songSpeedMul);
                if (practiceSettings != null)
                {
                    gameStatus.start -= (long)(practiceSettings.startSongTime * 1000f / songSpeedMul);
                }
                gameStatus.paused          = 0;
                gameStatus.difficulty      = diff.difficulty.Name();
                gameStatus.notesCount      = diff.beatmapData.notesCount;
                gameStatus.bombsCount      = diff.beatmapData.bombsCount;
                gameStatus.obstaclesCount  = diff.beatmapData.obstaclesCount;
                gameStatus.environmentName = level.environmentSceneInfo.sceneName;

                gameStatus.maxScore = ScoreController.MaxModifiedScoreForMaxRawScore(ScoreController.MaxRawScoreForNumberOfNotes(diff.beatmapData.notesCount), gameplayModifiers, gameplayModifiersSO);
                gameStatus.maxRank  = RankModel.MaxRankForGameplayModifiers(gameplayModifiers, gameplayModifiersSO).ToString();

                try {
                    // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
                    var texture   = level.GetCoverImageTexture2DAsync(CancellationToken.None).Result;
                    var active    = RenderTexture.active;
                    var temporary = RenderTexture.GetTemporary(
                        texture.width,
                        texture.height,
                        0,
                        RenderTextureFormat.Default,
                        RenderTextureReadWrite.Linear
                        );

                    Graphics.Blit(texture, temporary);
                    RenderTexture.active = temporary;

                    var cover = new Texture2D(texture.width, texture.height);
                    cover.ReadPixels(new Rect(0, 0, temporary.width, temporary.height), 0, 0);
                    cover.Apply();

                    RenderTexture.active = active;
                    RenderTexture.ReleaseTemporary(temporary);

                    gameStatus.songCover = System.Convert.ToBase64String(
                        ImageConversion.EncodeToPNG(cover)
                        );
                } catch {
                    gameStatus.songCover = null;
                }

                gameStatus.ResetPerformance();

                gameStatus.modifierMultiplier  = modifierMultiplier;
                gameStatus.songSpeedMultiplier = songSpeedMul;
                gameStatus.batteryLives        = gameEnergyCounter.batteryLives;

                gameStatus.modObstacles          = gameplayModifiers.enabledObstacleType.ToString();
                gameStatus.modInstaFail          = gameplayModifiers.instaFail;
                gameStatus.modNoFail             = gameplayModifiers.noFail;
                gameStatus.modBatteryEnergy      = gameplayModifiers.batteryEnergy;
                gameStatus.modDisappearingArrows = gameplayModifiers.disappearingArrows;
                gameStatus.modNoBombs            = gameplayModifiers.noBombs;
                gameStatus.modSongSpeed          = gameplayModifiers.songSpeed.ToString();
                gameStatus.modNoArrows           = gameplayModifiers.noArrows;
                gameStatus.modGhostNotes         = gameplayModifiers.ghostNotes;
                gameStatus.modFailOnSaberClash   = gameplayModifiers.failOnSaberClash;
                gameStatus.modStrictAngles       = gameplayModifiers.strictAngles;
                gameStatus.modFastNotes          = gameplayModifiers.fastNotes;

                gameStatus.staticLights = playerSettings.staticLights;
                gameStatus.leftHanded   = playerSettings.leftHanded;
                gameStatus.swapColors   = playerSettings.swapColors;
                gameStatus.playerHeight = playerSettings.playerHeight;
                gameStatus.disableSFX   = playerSettings.disableSFX;
                gameStatus.noHUD        = playerSettings.noTextsAndHuds;
                gameStatus.advancedHUD  = playerSettings.advancedHud;

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart");
            }
        }
Beispiel #5
0
        private void AddEvents()
        {
            if (_leftSaber)
            {
                _leftEventManager = _leftSaber.GetComponent <EventManager>();
                if (_leftEventManager == null)
                {
                    _leftEventManager = _leftSaber.AddComponent <EventManager>();
                }
            }

            if (_rightSaber)
            {
                _rightEventManager = _rightSaber.GetComponent <EventManager>();
                if (_rightEventManager == null)
                {
                    _rightEventManager = _rightSaber.AddComponent <EventManager>();
                }
            }

            if (_leftEventManager)
            {
                if (_leftEventManager.OnLevelStart != null)
                {
                    _leftEventManager.OnLevelStart.Invoke();
                }
                else
                {
                    return;
                }
            }

            if (_rightEventManager)
            {
                if (_rightEventManager.OnLevelStart != null)
                {
                    _rightEventManager.OnLevelStart.Invoke();
                }
                else
                {
                    return;
                }
            }

            try
            {
                _beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll <BeatmapObjectSpawnController>().FirstOrDefault();
                if (_beatmapObjectSpawnController == null)
                {
                    Logger.Log("Spawn Controller is 'NULL'", LogLevel.Warning);
                    //_beatmapObjectSpawnController = _saberRoot.AddComponent<BeatmapObjectSpawnController>();
                }

                _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();
                if (_scoreController == null)
                {
                    Logger.Log("Score Controller is 'NULL'", LogLevel.Warning);
                    //_scoreController = _saberRoot.AddComponent<ScoreController>();
                }

                _saberCollisionManager = Resources.FindObjectsOfTypeAll <ObstacleSaberSparkleEffectManager>().FirstOrDefault();
                if (_saberCollisionManager == null)
                {
                    Logger.Log("Collision Manager is 'NULL'", LogLevel.Warning);
                    //_saberCollisionManager = _saberRoot.AddComponent<ObstacleSaberSparkleEffectManager>();
                }

                _gameEnergyCounter = Resources.FindObjectsOfTypeAll <GameEnergyCounter>().FirstOrDefault();
                if (_gameEnergyCounter == null)
                {
                    Logger.Log("Energy Counter is 'NULL'", LogLevel.Warning);
                    //_gameEnergyCounter = _saberRoot.AddComponent<GameEnergyCounter>();
                }

                _beatmapCallback = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().FirstOrDefault();
                if (_beatmapCallback == null)
                {
                    Logger.Log("Beatmap Callback is 'NULL'", LogLevel.Warning);
                    //_beatmapCallback = _saberRoot.AddComponent<BeatmapObjectCallbackController>();
                }

                _gamePauseManager = Resources.FindObjectsOfTypeAll <GamePauseManager>().FirstOrDefault();
                if (_gamePauseManager == null)
                {
                    Logger.Log("GamePauseManager is 'NULL'", LogLevel.Warning);
                    //_gamePauseManager = _saberRoot.AddComponent<GamePauseManager>();
                }

                _playerHeadAndObstacleInteraction = Resources.FindObjectsOfTypeAll <PlayerHeadAndObstacleInteraction>().FirstOrDefault();
                if (_playerHeadAndObstacleInteraction == null)
                {
                    Logger.Log("PlayerHeadAndObstacleInteraction is 'NULL'", LogLevel.Warning);
                    //_playerHeadAndObstacleInteraction = _saberRoot.AddComponent<PlayerHeadAndObstacleInteraction>();
                }

                if (_beatmapObjectSpawnController)
                {
                    _beatmapObjectSpawnController.noteWasCutEvent    += SliceCallBack;
                    _beatmapObjectSpawnController.noteWasMissedEvent += NoteMissCallBack;
                }

                if (_scoreController)
                {
                    _scoreController.multiplierDidChangeEvent += MultiplierCallBack;
                    _scoreController.comboDidChangeEvent      += ComboChangeEvent;
                }

                if (_saberCollisionManager)
                {
                    _saberCollisionManager.sparkleEffectDidStartEvent += SaberStartCollide;
                    _saberCollisionManager.sparkleEffectDidEndEvent   += SaberEndCollide;
                }

                if (_gameEnergyCounter)
                {
                    _gameEnergyCounter.gameEnergyDidReach0Event += FailLevelCallBack;
                }

                if (_beatmapCallback)
                {
                    _beatmapCallback.beatmapEventDidTriggerEvent += LightEventCallBack;
                }

                //ReflectionUtil.SetPrivateField(_gamePauseManager, "_gameDidResumeSignal", (Action)OnPauseMenuClosed); //For some reason _gameDidResumeSignal isn't public.
            }
            catch (Exception ex)
            {
                Logger.Log($"{ex.Message}\n{ex.StackTrace}", LogLevel.Error);
                throw;
            }

            try
            {
                var mgs         = GetGameSceneSetup();
                var beatmapData = mgs.GameplayCoreSceneSetupData.difficultyBeatmap.beatmapData;

                var beatmapLinesData = beatmapData.beatmapLinesData;
                var LastTime         = 0.0f;

                for (var i = 0; i < beatmapLinesData.Length; i++)
                {
                    var beatmapObjectsData = beatmapLinesData[i].beatmapObjectsData;
                    for (var j = beatmapObjectsData.Length - 1; j >= 0; j--)
                    {
                        if (beatmapObjectsData[j].beatmapObjectType == BeatmapObjectType.Note)
                        {
                            if (((NoteData)beatmapObjectsData[j]).noteType != NoteType.Bomb)
                            {
                                if (beatmapObjectsData[j].time > LastTime)
                                {
                                    LastNoteId = beatmapObjectsData[j].id;
                                    LastTime   = beatmapObjectsData[j].time;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Log($"{ex.Message}\n{ex.StackTrace}", LogLevel.Error);
                throw;
            }
        }
        private void AddEvents()
        {
            _leftEventManager = _leftSaber.GetComponent <EventManager>();
            if (_leftEventManager == null)
            {
                _leftEventManager = _leftSaber.AddComponent <EventManager>();
            }

            _rightEventManager = _rightSaber.GetComponent <EventManager>();
            if (_rightEventManager == null)
            {
                _rightEventManager = _rightSaber.AddComponent <EventManager>();
            }

            _leftEventManager.OnLevelStart.Invoke();
            _rightEventManager.OnLevelStart.Invoke();
            try
            {
                _beatmapObjectSpawnController = Resources.FindObjectsOfTypeAll <BeatmapObjectSpawnController>().FirstOrDefault();
                if (_beatmapObjectSpawnController == null)
                {
                    Console.WriteLine("SPAWN CONTROLLER NULL");
                    //_beatmapObjectSpawnController = _saberRoot.AddComponent<BeatmapObjectSpawnController>();
                }
                _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();
                if (_scoreController == null)
                {
                    Console.WriteLine("SCORE CONTROLLER NULL");
                    //_scoreController = _saberRoot.AddComponent<ScoreController>();
                }
                _saberCollisionManager =
                    Resources.FindObjectsOfTypeAll <ObstacleSaberSparkleEffectManager>().FirstOrDefault();
                if (_saberCollisionManager == null)
                {
                    Console.WriteLine("COLLISION MANAGER NULL");
                    //_saberCollisionManager = _saberRoot.AddComponent<ObstacleSaberSparkleEffectManager>();
                }
                _gameEnergyCounter = Resources.FindObjectsOfTypeAll <GameEnergyCounter>().FirstOrDefault();
                if (_gameEnergyCounter == null)
                {
                    Console.WriteLine("energery counter null");
                    //_gameEnergyCounter = _saberRoot.AddComponent<GameEnergyCounter>();
                }
                _beatmapCallback = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().FirstOrDefault();
                if (_beatmapCallback == null)
                {
                    Console.WriteLine("BEATMAP CALLBACK NULL");
                    //_beatmapCallback = _saberRoot.AddComponent<BeatmapObjectCallbackController>();
                }

                _gamePauseManager = Resources.FindObjectsOfTypeAll <GamePauseManager>().FirstOrDefault();
                if (_gamePauseManager == null)
                {
                    Console.WriteLine("GamePauseManager Null");
                    //_gamePauseManager = _saberRoot.AddComponent<GamePauseManager>();
                }

                _playerHeadAndObstacleInteraction = Resources.FindObjectsOfTypeAll <PlayerHeadAndObstacleInteraction>().FirstOrDefault();
                if (_playerHeadAndObstacleInteraction == null)
                {
                    Console.WriteLine("PlayerHeadAndObstacleInteraction Null");
                    //_playerHeadAndObstacleInteraction = _saberRoot.AddComponent<PlayerHeadAndObstacleInteraction>();
                }

                _beatmapObjectSpawnController.noteWasCutEvent    += SliceCallBack;
                _beatmapObjectSpawnController.noteWasMissedEvent += NoteMissCallBack;
                _scoreController.multiplierDidChangeEvent        += MultiplierCallBack;
                _scoreController.comboDidChangeEvent             += ComboChangeEvent;

                _saberCollisionManager.sparkleEffectDidStartEvent += SaberStartCollide;
                _saberCollisionManager.sparkleEffectDidEndEvent   += SaberEndCollide;

                _gameEnergyCounter.gameEnergyDidReach0Event += FailLevelCallBack;

                _beatmapCallback.beatmapEventDidTriggerEvent += LightEventCallBack;
                //  ReflectionUtil.SetPrivateField(_gamePauseManager, "_gameDidResumeSignal", (Action)OnPauseMenuClosed); //For some reason _gameDidResumeSignal isn't public.
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(e.Message);
                throw;
            }

            try
            {
                StandardLevelSceneSetup mgs         = GetGameSceneSetup();
                BeatmapData             beatmapData = mgs.standardLevelSceneSetupData.difficultyBeatmap.beatmapData;

                BeatmapLineData[] beatmapLinesData = beatmapData.beatmapLinesData;
                float             LastTime         = 0.0f;

                for (int i = 0; i < beatmapLinesData.Length; i++)
                {
                    BeatmapObjectData[] beatmapObjectsData = beatmapLinesData[i].beatmapObjectsData;
                    for (int j = beatmapObjectsData.Length - 1; j > 0; j--)
                    {
                        if (beatmapObjectsData[j].beatmapObjectType == BeatmapObjectType.Note)
                        {
                            if (((NoteData)beatmapObjectsData[j]).noteType != NoteType.Bomb)
                            {
                                if (beatmapObjectsData[j].time > LastTime)
                                {
                                    LastNoteId = beatmapObjectsData[j].id;
                                    LastTime   = beatmapObjectsData[j].time;
                                }
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(e.Message);
                throw;
            }
        }
        private void OnSceneLoaded(Scene newScene, LoadSceneMode mode)
        {
            var gameStatus = statusManager.gameStatus;

            gameStatus.scene = newScene.name;

            if (newScene.name == "Menu")
            {
                // Menu
                headInObstacle = false;

                // TODO: get the current song, mode and mods while in menu
                gameStatus.ResetMapInfo();

                gameStatus.ResetPerformance();

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "menu");
            }
            else if (newScene.name == "StandardLevel")
            {
                // In game
                mainSetupData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault();
                if (mainSetupData == null)
                {
                    Console.WriteLine("[HTTP Status] Couldn't find MainGameSceneSetupData");
                    return;
                }

                gamePauseManager = Resources.FindObjectsOfTypeAll <GamePauseManager>().FirstOrDefault();
                if (gamePauseManager == null)
                {
                    Console.WriteLine("[HTTP Status] Couldn't find GamePauseManager");
                    return;
                }

                scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();
                if (scoreController == null)
                {
                    Console.WriteLine("[HTTP Status] Couldn't find ScoreController");
                    return;
                }

                gameplayManager = Resources.FindObjectsOfTypeAll <GameplayManager>().FirstOrDefault();
                if (gameplayManager == null)
                {
                    Console.WriteLine("[HTTP Status] Couldn't find GameplayManager");
                    return;
                }

                beatmapObjectCallbackController = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().FirstOrDefault();
                if (beatmapObjectCallbackController == null)
                {
                    Console.WriteLine("[HTTP Status] Couldn't find BeatmapObjectCallbackController");
                    return;
                }

                GameSongController gameSongController = (GameSongController)gameSongControllerField.GetValue(gameplayManager);
                audioTimeSyncController          = (AudioTimeSyncController)audioTimeSyncControllerField.GetValue(gameSongController);
                playerHeadAndObstacleInteraction = (PlayerHeadAndObstacleInteraction)playerHeadAndObstacleInteractionField.GetValue(scoreController);

                // Register event listeners
                // private GameEvent GamePauseManager#_gameDidPauseSignal
                AddSubscriber(gamePauseManager, "_gameDidPauseSignal", OnGamePause);
                // private GameEvent GamePauseManager#_gameDidResumeSignal
                AddSubscriber(gamePauseManager, "_gameDidResumeSignal", OnGameResume);
                // public ScoreController#noteWasCutEvent<NoteData, NoteCutInfo, int multiplier> // called after AfterCutScoreBuffer is created
                scoreController.noteWasCutEvent += OnNoteWasCut;
                // public ScoreController#noteWasMissedEvent<NoteData, int multiplier>
                scoreController.noteWasMissedEvent += OnNoteWasMissed;
                // public ScoreController#scoreDidChangeEvent<int> // score
                scoreController.scoreDidChangeEvent += OnScoreDidChange;
                // public ScoreController#comboDidChangeEvent<int> // combo
                scoreController.comboDidChangeEvent += OnComboDidChange;
                // public ScoreController#multiplierDidChangeEvent<int, float> // multiplier, progress [0..1]
                scoreController.multiplierDidChangeEvent += OnMultiplierDidChange;
                // private GameEvent GameplayManager#_levelFinishedSignal
                AddSubscriber(gameplayManager, "_levelFinishedSignal", OnLevelFinished);
                // private GameEvent GameplayManager#_levelFailedSignal
                AddSubscriber(gameplayManager, "_levelFailedSignal", OnLevelFailed);
                // public event Action<BeatmapEventData> BeatmapObjectCallbackController#beatmapEventDidTriggerEvent
                beatmapObjectCallbackController.beatmapEventDidTriggerEvent += OnBeatmapEventDidTrigger;

                var diff  = mainSetupData.difficultyLevel;
                var level = diff.level;

                gameStatus.mode = mainSetupData.gameplayMode.ToString();

                gameStatus.songName       = level.songName;
                gameStatus.songSubName    = level.songSubName;
                gameStatus.songAuthorName = level.songAuthorName;
                gameStatus.songBPM        = level.beatsPerMinute;
                gameStatus.songTimeOffset = (long)(level.songTimeOffset * 1000f);
                gameStatus.length         = (long)(level.audioClip.length * 1000f);
                gameStatus.start          = GetCurrentTime();
                gameStatus.paused         = 0;
                gameStatus.difficulty     = diff.difficulty.Name();
                gameStatus.notesCount     = diff.beatmapData.notesCount;
                gameStatus.obstaclesCount = diff.beatmapData.obstaclesCount;
                gameStatus.maxScore       = ScoreController.MaxScoreForNumberOfNotes(diff.beatmapData.notesCount);

                try {
                    // From https://support.unity3d.com/hc/en-us/articles/206486626-How-can-I-get-pixels-from-unreadable-textures-
                    var texture   = level.coverImage.texture;
                    var active    = RenderTexture.active;
                    var temporary = RenderTexture.GetTemporary(
                        texture.width,
                        texture.height,
                        0,
                        RenderTextureFormat.Default,
                        RenderTextureReadWrite.Linear
                        );

                    Graphics.Blit(texture, temporary);
                    RenderTexture.active = temporary;

                    var cover = new Texture2D(texture.width, texture.height);
                    cover.ReadPixels(new Rect(0, 0, temporary.width, temporary.height), 0, 0);
                    cover.Apply();

                    RenderTexture.active = active;
                    RenderTexture.ReleaseTemporary(temporary);

                    gameStatus.songCover = System.Convert.ToBase64String(
                        ImageConversion.EncodeToPNG(cover)
                        );
                } catch {
                    gameStatus.songCover = null;
                }

                gameStatus.ResetPerformance();

                // TODO: obstaclesOption can be All, FullHeightOnly or None. Reflect that?
                gameStatus.modObstacles = mainSetupData.gameplayOptions.obstaclesOption.ToString();
                gameStatus.modNoEnergy  = mainSetupData.gameplayOptions.noEnergy;
                gameStatus.modMirror    = mainSetupData.gameplayOptions.mirror;

                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "songStart");
            }
            else
            {
                statusManager.EmitStatusUpdate(ChangedProperties.AllButNoteCut, "scene");
            }
        }
Beispiel #8
0
        private void Start()
        {
            _leftEventManager = _leftSaber.GetComponent <EventManager>();
            if (_leftEventManager == null)
            {
                _leftEventManager = _leftSaber.AddComponent <EventManager>();
            }

            _rightEventManager = _rightSaber.GetComponent <EventManager>();
            if (_rightEventManager == null)
            {
                _rightEventManager = _rightSaber.AddComponent <EventManager>();
            }

            _leftEventManager.OnLevelStart.Invoke();
            _rightEventManager.OnLevelStart.Invoke();
            try
            {
                _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault();
                if (_scoreController == null)
                {
                    Console.WriteLine("SCORE CONTROLLER NULL");
                }
                _saberCollisionManager =
                    Resources.FindObjectsOfTypeAll <ObstacleSaberSparkleEffectManager>().FirstOrDefault();
                if (_saberCollisionManager == null)
                {
                    Console.WriteLine("COLLISION MANAGER NULL");
                }
                _gameEnergyCounter = Resources.FindObjectsOfTypeAll <GameEnergyCounter>().FirstOrDefault();
                if (_gameEnergyCounter == null)
                {
                    Console.WriteLine("energery counter null");
                }
                _beatmapCallback = Resources.FindObjectsOfTypeAll <BeatmapObjectCallbackController>().FirstOrDefault();
                if (_beatmapCallback == null)
                {
                    Console.WriteLine("BEATMAP CALLBACK NULL");
                }

                _gamePauseManager = Resources.FindObjectsOfTypeAll <GamePauseManager>().FirstOrDefault();
                if (_gamePauseManager == null)
                {
                    Console.WriteLine("GamePauseManager Null");
                }

                _scoreController.noteWasCutEvent          += SliceCallBack;
                _scoreController.noteWasMissedEvent       += NoteMissCallBack;
                _scoreController.multiplierDidChangeEvent += MultiplierCallBack;
                _scoreController.comboDidChangeEvent      += ComboChangeEvent;

                _saberCollisionManager.sparkleEffectDidStartEvent += SaberStartCollide;
                _saberCollisionManager.sparkleEffectDidEndEvent   += SaberEndCollide;

                _gameEnergyCounter.gameEnergyDidReach0Event += FailLevelCallBack;

                _beatmapCallback.beatmapEventDidTriggerEvent += LightEventCallBack;
                ReflectionUtil.SetPrivateField(_gamePauseManager, "_gameDidResumeSignal", (Action)OnPauseMenuClosed); //For some reason _gameDidResumeSignal isn't public.
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Console.WriteLine(e.Message);
                throw;
            }
        }