Esempio n. 1
0
 private void Start()
 {
     MinimapInstance = miniMap;
     SetCurrentState(EditorState.INIT);
     // Set static objects from unity editor //
     BarPrefab       = barPrefab;
     NotePrefab      = notePrefab;
     controlsDiagram = GameObject.FindGameObjectWithTag("ControlsWindow").
                       GetComponent <ControlsDiagram>();
     controlsDiagram.UpdateMe(EditorState.INIT);
     BeatMap.currentDebugText = debugText;
     BeatMap.staticMats       = materials;
     isVrPlayer           = isVrPlayerOverride;
     spawnPositions       = new Vector3[4, 3];
     spawnPositions[0, 0] = spawnBlocks[1].position;
     spawnPositions[0, 1] = spawnBlocks[5].position;
     spawnPositions[0, 2] = spawnBlocks[9].position;
     spawnPositions[1, 0] = spawnBlocks[0].position;
     spawnPositions[1, 1] = spawnBlocks[4].position;
     spawnPositions[1, 2] = spawnBlocks[8].position;
     spawnPositions[2, 0] = spawnBlocks[2].position;
     spawnPositions[2, 1] = spawnBlocks[6].position;
     spawnPositions[2, 2] = spawnBlocks[10].position;
     spawnPositions[3, 0] = spawnBlocks[3].position;
     spawnPositions[3, 1] = spawnBlocks[7].position;
     spawnPositions[3, 2] = spawnBlocks[11].position;
     BeatMap.Log("Spawn position0 - " + spawnPositions[0, 0]);
     mainCamera    = Camera.main;
     NoteContainer = new GameObject("NoteContainer");
     Log("Main camera - " + mainCamera.name);
     audioSource = GetComponent <AudioSource>();
     leftSaber.Initialize(isVrPlayer);
     rightSaber.Initialize(isVrPlayer);
 }
Esempio n. 2
0
 public void StartNewMap()
 {
     if (!flatMenu.IsReadyForNew())
     {
         BeatMap.Log("Start new called, but not ready");
         return;
     }
     currentNoteMode = flatMenu.selectedMode;
     StartNewMap(0, flatMenu.selectedBPM, flatMenu.selectedAudioPath,
                 flatMenu.selectedSongArtist, flatMenu.selectedMapArtist, flatMenu.selectedNewSongName,
                 flatMenu.selectedDifficulty, flatMenu.selecedNewSongFileName);
 }
Esempio n. 3
0
 public void InvertNotes()
 {
     if (BeatMap.state == EditorState.Playback)
     {
         return;
     }
     BeatMap.Log("Inverting map from " + BeatMap.Inverted +
                 " Waiting note size " + waitingNotes.Count);
     BeatMap.Inverted = !BeatMap.Inverted;
     InvertArray(waitingNotes);
     InvertArray(activeNotes);
     InvertArray(completedNotes);
 }
Esempio n. 4
0
 public void Attach(GameObject gameObject)
 {
     BeatMap.Log("Attach called on saber selector, current attachmetn - " + attachedObject);
     if (attachedObject != null)
     {
         BeatMap.Log("Saber Selector called to attach when already attached");
         return;
     }
     attachedObject     = gameObject;
     transform.position = gameObject.transform.position;
     transform.SetParent(gameObject.transform, true);
     meshRenderer.enabled = true;
 }
Esempio n. 5
0
        public void Grab(IGrabber grabber)
        {
            Rigidbody thisRigidBody = GetComponent <Rigidbody>();

            BeatMap.Log("grab called on " + gameObject.name + " already grabbed? - " + IsGrabbed());
            if (IsGrabbed())
            {
                return;
            }
            resizing = true;
            joint    = gameObject.AddComponent <FixedJoint>();
            BeatMap.Log("Adding joint to " + gameObject.name);
            joint.connectedBody   = grabber.GetRigidBody();
            joint.anchor          = Vector3.zero;
            joint.connectedAnchor = grabber.GetJointAnchorPoint();
        }
        public static BeatSaberJSONClass ConvertUnityDataToBSData(BeatMapData data)
        {
            BeatSaberJSONClass bsaberJSON = new BeatSaberJSONClass();

            bsaberJSON.info = new InfoJSON();
            bsaberJSON.info.beatsPerMinute = (int)data.beatsPerMinute;
            bsaberJSON.info.authorName     = data.mapArtist;
            bsaberJSON.info.songSubName    = data.songArtist;
            bsaberJSON.info.songName       = data.songName;
            // TODO merge with existing info if any //
            bsaberJSON.info.difficultyLevels    = new DifficultyLevel[1];
            bsaberJSON.info.difficultyLevels[0] = DifficultyLevel.Generate(data.difficulty,
                                                                           data.songFileName, (int)data.songOffset);
            List <BSNote> notes = new List <BSNote>();

            for (int count = 0; count < data.notes.Length; count++)
            {
                if (!data.notes[count].inverted)
                {
                    BSNote bSNote = new BSNote();
                    if (data.notes[count].color == Note.NoteColor.LEFT)
                    {
                        bSNote._type = 0;
                    }
                    else
                    {
                        bSNote._type = 1;
                    }
                    bSNote._cutDirection = BSNote.GetBSaberCutDirection(data.notes[count].slashDirection);
                    bSNote._lineIndex    = (int)data.notes[count].gridPosition.x;
                    bSNote._lineLayer    = (int)data.notes[count].gridPosition.y;
                    bSNote._time         = data.notes[count].timeToSpawn;
                    notes.Add(bSNote);
                }
            }
            BeatMap.Log("Notes exported with count " + notes.Count);
            LevelJSON level = new LevelJSON();

            level._beatsPerMinute = (int)data.beatsPerMinute;
            level._version        = "1.0";
            level._beatsPerBar    = 16;
            level._noteJumpSpeed  = 10;
            level._shufflePeriod  = .5f;
            level._notes          = notes.ToArray();
            bsaberJSON.level      = level;
            return(bsaberJSON);
        }
Esempio n. 7
0
        private bool UnGrab()
        {
            IGrabbable grabbable = selector.GetAttachedObject().GetComponent <IGrabbable>();

            if (grabbable == null)
            {
                grabbable = selector.GetAttachedObject().GetComponentInParent <IGrabbable>();
            }
            if (grabbable != null)
            {
                grabbable.UnGrab();
            }
            else
            {
                BeatMap.Log("Ungrab called on an object that doesn't have a grabbable " + selector.GetAttachedObject().name);
            }
            grabbing = false;
            return(true);
        }
Esempio n. 8
0
        public void SaveCurrentMapToDisk()
        {
            BeatMapData dataToSave = new BeatMapData();

            if (beatMapData == null)
            {
                BeatMap.Log("Current map data not available to save");
                return;
            }
            if (state != EditorState.Editing && state != EditorState.Recording &&
                state != EditorState.PlaybackPaused)
            {
                BeatMap.Log("Call to save when not in proper state - " + state);
                return;
            }
            else
            {
                Debug.LogWarning("data song file name - " + beatMapData.songFileName);
                dataToSave = BeatMapData.CopyBMDNotNotes(dataToSave, beatMapData);
                float              throwAwayFirstBeats = (dataToSave.beatsPerMinute / 16.5f);
                NoteDetails[]      notes    = GetAllNotes(true);
                List <NoteDetails> filtered = new List <NoteDetails>();
                for (int count = 0; count < notes.Length; count++)
                {
                    if (notes[count].timeToSpawn < throwAwayFirstBeats)
                    {
                    }
                    else
                    {
                        Debug.LogWarning("Accepting note " + notes[count].timeToSpawn + "-" +
                                         notes[count].inverted);
                        filtered.Add(notes[count]);
                    }
                }
                Debug.LogWarning("Notes - " + notes.Length + " filtered - " + filtered.Count);
                dataToSave.notes = filtered.ToArray();
            }
            Log("Call to save with # of notes " + dataToSave.notes.Length);
            Utilities.SaveToDisk(dataToSave);
        }
Esempio n. 9
0
        private bool Grab(GameObject gameObject)
        {
            BeatMap.Log("Saber called grab on " + gameObject.name);
            IGrabbable grabbable = gameObject.GetComponent <IGrabbable>();

            if (grabbable == null)
            {
                grabbable = gameObject.GetComponentInParent <IGrabbable>();
            }
            if (grabbable == null)
            {
                Debug.LogWarning("Object not grabbable - " + gameObject.name);
                return(false);
            }
            if (grabbable.IsGrabbed())
            {
                Debug.LogWarning("Object already grabbed - " + gameObject.name);
                return(false);
            }
            grabbable.Grab(this);
            grabbing = true;
            addVibration(.5f, .5f, true);
            return(true);
        }
Esempio n. 10
0
        public static void SkipToBeat(float beat)
        {
            if (!(state == EditorState.PlaybackPaused || state == EditorState.Editing))
            {
                Debug.LogWarning("SkipToBeat called when not in proper state -" + state);
                return;
            }
            BeatMap.Log("Skipping to beat " + beat);

            // Disable all active notes and bars on screen //
            foreach (Note note in activeNotes)
            {
                note.gameObject.SetActive(false);
            }

            // Reinitialize lists //
            waitingNotes   = new List <NoteDetails>();
            activeNotes    = new List <Note>();
            completedNotes = new List <NoteDetails>();

            // Get the beat manager up to date //
            float noteSpeedInBeats = beatManager.GetNoteSpeedInBeats();

            beatManager.SkipToBeat(beat, noteSpeedInBeats);
            float lastBeatToPlace = beatManager.GetClosestBeatToPlayer();
            // List of notes that will be spawned as active //
            List <NoteDetails> notesToSpawn = new List <NoteDetails>();

            // Check each note in our map data for notes that fall within the skipped time //
            for (int count = 0; count < beatMapData.notes.Length; count++)
            {
                if (beatMapData.notes[count].timeToSpawn <= beat &&
                    beatMapData.notes[count].timeToSpawn >= lastBeatToPlace)
                {
                    notesToSpawn.Add(beatMapData.notes[count]);
                }
                else
                {
                    if (beatMapData.notes[count].timeToSpawn < beat)
                    {
                        completedNotes.Add(beatMapData.notes[count]);
                    }
                    else
                    {
                        waitingNotes.Add(beatMapData.notes[count]);
                    }
                }
            }
            // Place Notes //
            for (int count = 0; count < notesToSpawn.Count; count++)
            {
                Note note = notesToSpawn[count].note;
                if (note == null)
                {
                    note             = Instantiate(NotePrefab).GetComponent <Note>();
                    note.noteDetails = notesToSpawn[count];
                }
                float   spaceBetween      = noteSpeedInBeats;
                Vector3 position          = GetSpawnPosition(note.noteDetails.gridPosition);
                float   adjustedSpawnTime = beat - note.noteDetails.timeToSpawn;
                position.z -= (adjustedSpawnTime * spaceBetween);
                position.z  = RoundToRelativeBeat(position.z, currentNoteMode);
                note.Initialize(notesToSpawn[count], staticMats, position);

                activeNotes.Add(note);
            }
            SetRunning(false);
            MinimapInstance.SetZBasedOnBeat(beat);
            initialized = true;
        }
Esempio n. 11
0
        private void Update()
        {
            if (!initialized)
            {
                // Initialization //

                if (audioIsLoading)
                {
                    AudioIsInitialized();
                }
            }
            // INITIALIZED //
            else
            {
                // Start Update //
                currentFrame++;
                if (running)
                {
                    beatManager.Update();
                    // Song may be completed //
                    if ((state == EditorState.Playback || state == EditorState.Recording) &&
                        !audioSource.isPlaying)
                    {
                        PauseSong();
                    }
                    if (mainCamera.transform.position.z >= showGuardAtZ &&
                        !guard.activeSelf)
                    {
                        guard.SetActive(true);
                        BeatMap.Log("Guard activated");
                        PauseSong();
                    }
                }
                // Check if player is back in a good position and resume song //
                else if (guard.activeSelf && mainCamera.transform.position.z < showGuardAtZ)
                {
                    guard.SetActive(false);
                    BeatMap.Log("Guard deactivated");
                    ResumeSong();
                }
                // If we're not running, we are done //
                else
                {
                    return;
                }

                // Check if the next beat has started //
                if (beatManager.NextBeatStarted(true, mostRecentBeat))
                {
                    mostRecentBeat = beatManager.GetCurrentRelativeBeat();
                    // Check if any active notes are complete //
                    foreach (Note note in activeNotes)
                    {
                        if ((note.transform.position.z < destroyNoteAtZ && !beatManager.rewinding) ||
                            (note.transform.position.z > spawnPositions[0, 0].z) && beatManager.rewinding)
                        {
                            note.gameObject.SetActive(false);
                            if (!beatManager.rewinding)
                            {
                                completedNotes.Add(note.noteDetails);
                            }
                            else
                            {
                                waitingNotes.Add(note.noteDetails);
                            }
                        }
                    }

                    // Wait list is determined by rewinding //
                    List <NoteDetails> waitList;
                    if (!beatManager.rewinding)
                    {
                        waitList = waitingNotes;
                    }
                    else
                    {
                        waitList = completedNotes;
                    }

                    // Temp list for removing notes from waiting list //
                    List <NoteDetails> notesDoneWaiting = new List <NoteDetails>();
                    for (int count = 0; count < waitList.Count; count++)
                    {
                        NoteDetails noteDetails = waitList[count];
                        float       playerRelativeTimeToSpawn = beatManager.currentBeat + beatsToReachPlayer;
                        if ((playerRelativeTimeToSpawn >= noteDetails.timeToSpawn && !beatManager.rewinding) ||
                            (beatManager.currentBeat <= noteDetails.timeToSpawn && beatManager.rewinding))
                        {
                            Note note = noteDetails.note;
                            if (note == null)
                            {
                                note = Instantiate(notePrefab).GetComponent <Note>();
                            }
                            note.Initialize(noteDetails, materials, GetSpawnPosition(noteDetails.gridPosition, beatManager.rewinding));
                            note.transform.SetParent(NoteContainer.transform);
                            notesDoneWaiting.Add(noteDetails);
                            activeNotes.Add(note);
                            note.Refresh();
                        }
                    }

                    foreach (NoteDetails note in notesDoneWaiting)
                    {
                        if (!beatManager.rewinding)
                        {
                            waitingNotes.Remove(note);
                        }
                        else
                        {
                            completedNotes.Remove(note);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        private void ProcessControls(bool vrControls)
        {
            bool triggerCooldown = false;

            BeatMap.EditorState currentState = BeatMap.GetCurrentState();
            if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger) ||
                Input.GetKeyDown(KeyCode.Space) && !vrControls)
            {
                triggerDown = true;
                if (!BeatMap.Inverted)
                {
                    map.InvertNotes();
                }
            }
            else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger) ||
                     Input.GetKeyUp(KeyCode.Space) && !vrControls)
            {
                triggerDown = false;
                if (BeatMap.Inverted)
                {
                    map.InvertNotes();
                }
            }
            else if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu) ||
                     Input.GetKeyDown(KeyCode.A) && !vrControls)
            {
                menuButtonDown = true;
                bool bothControllersPressing = otherSaber.menuButtonDown;

                if (bothControllersPressing)
                {
                    if (currentState == BeatMap.EditorState.Editing ||
                        currentState == BeatMap.EditorState.PlaybackPaused)
                    {
                        map.ResumeSong();
                        triggerCooldown = true;
                        return;
                    }
                    else if (currentState == BeatMap.EditorState.Playback ||
                             currentState == BeatMap.EditorState.Recording)
                    {
                        map.PauseSong();
                        triggerCooldown = true;
                        return;
                    }
                }
                else
                {
                    if (currentState == BeatMap.EditorState.Editing)
                    {
                        if (selector.GetAttachedObject() != null)
                        {
                            Note note = selector.GetAttachedObject().GetComponent <Note>();
                            if (note != null)
                            {
                                if (!note.noteDetails.inverted)
                                {
                                    note.MakeNeutral();
                                    if (isLeft)
                                    {
                                        note.Invert(true);
                                    }
                                    DetachSelector();
                                    triggerCooldown = true;
                                }
                            }
                        }
                    }
                }
            }
            else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_ApplicationMenu) ||
                     Input.GetKeyUp(KeyCode.A) && !vrControls)
            {
                menuButtonDown = false;
            }
            if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_SteamVR_Touchpad) ||
                Input.GetKeyDown(KeyCode.Y) && !vrControls)
            {
            }
            if (vrControls && steamVRController.GetTouchDown(EVRButtonId.k_EButton_SteamVR_Touchpad) ||
                Input.GetKeyDown(KeyCode.T) && !vrControls)
            {
                if (currentState == BeatMap.EditorState.Recording)
                {
                    BeatMap.currentNoteMode = BeatMap.NoteMode.HalfNote;
                }
            }
            else if (vrControls && steamVRController.GetTouchUp(EVRButtonId.k_EButton_SteamVR_Touchpad) ||
                     Input.GetKeyUp(KeyCode.T) && !vrControls)
            {
                if (currentState == BeatMap.EditorState.Recording)
                {
                    BeatMap.currentNoteMode = BeatMap.NoteMode.WholeNote;
                }
            }
            if (vrControls && steamVRController.GetPressDown(EVRButtonId.k_EButton_Grip) ||
                Input.GetKeyDown(KeyCode.G) && !vrControls)
            {
                if (gripHeldFor == 0) // Fresh push
                {
                    if (selector.HasTarget())
                    {
                        BeatMap.Log("Calling Grab on object " + selector.GetAttachedObject().name);
                        Grab(selector.GetAttachedObject());
                        if (selector.GetAttachedObject().GetComponent <MiniMap>() != null)
                        {
                            map.PauseSong();
                        }
                        triggerCooldown = true;
                    }
                }
                gripHeldFor += Time.deltaTime;
            }
            else if (vrControls && steamVRController.GetPressUp(EVRButtonId.k_EButton_Grip) ||
                     Input.GetKeyUp(KeyCode.G) && !vrControls)
            {
                BeatMap.Log("Grip let go, grabbing? " + grabbing);
                gripHeldFor = 0;
                if (grabbing)
                {
                    UnGrab();
                    triggerCooldown = true;
                }
            }
            // KEYBOARD ONLY //
            if (!vrControls)
            {
                if (Input.GetKeyDown(KeyCode.W))
                {
                    transform.position += transform.forward;
                }
                else if (Input.GetKeyDown(KeyCode.A))
                {
                    transform.position += -transform.right;
                }
                else if (Input.GetKeyDown(KeyCode.S))
                {
                    transform.position += -transform.forward;
                }
                else if (Input.GetKeyDown(KeyCode.D))
                {
                    transform.position += transform.right;
                }
                else if (Input.GetKeyDown(KeyCode.Q))
                {
                    transform.position += transform.up;
                }
                else if (Input.GetKeyDown(KeyCode.E))
                {
                    transform.position += -transform.up;
                }
                else if (Input.GetKeyDown(KeyCode.RightArrow))
                {
                    BeatMap.SkipToBeat(BeatMap.GetCurrentBeat() + 10);
                }
                else if (Input.GetKeyDown(KeyCode.LeftArrow))
                {
                    BeatMap.SkipToBeat(BeatMap.GetCurrentBeat() - 10);
                }
                else if (Input.GetKeyDown(KeyCode.P) && !IsOnCoolDown() && isLeft)
                {
                    triggerCooldown = true;
                    if (BeatMap.GetCurrentState() == BeatMap.EditorState.Editing)
                    {
                        map.ResumeSong();
                    }
                    else if (BeatMap.GetCurrentState() == BeatMap.EditorState.PlaybackPaused)
                    {
                        map.ResumeSong();
                    }
                    else if (BeatMap.GetCurrentState() == BeatMap.EditorState.Playback)
                    {
                        map.PauseSong();
                    }
                    else if (BeatMap.GetCurrentState() == BeatMap.EditorState.Recording)
                    {
                        map.PauseSong();
                    }
                }
            }
            if (triggerCooldown)
            {
                currentCooldown += Time.deltaTime;
            }
        }
Esempio n. 13
0
 private void AddCollision(Hit collision)
 {
     BeatMap.Log("Hit - " + collision.point + " By - " + collision.saberColor.ToString());
     collisions.Add(collision);
 }