Ejemplo n.º 1
0
    protected override void Awake()
    {
        base.Awake();

        // BGM
        var bgmSources = new AudioSource[BGM_LINE_MAX];

        for (int i = 0; i < bgmSources.Length; i++)
        {
            bgmSources[i] = bgmParent.AddComponent <AudioSource>();
        }
        bgmAudio = new AudioLoop(bgmSources);

        // SE
        var seSources = new AudioSource[SE_LINE_MAX];

        for (int i = 0; i < seSources.Length; i++)
        {
            seSources[i] = seParent.AddComponent <AudioSource>();
        }
        seAudio = new AudioOneShot(seSources);

        // Voice
        var voiceSources = new AudioSource[VOICE_LINE_MAX];

        for (int i = 0; i < voiceSources.Length; i++)
        {
            voiceSources[i] = voiceParent.AddComponent <AudioSource>();
        }
        voiceAudio = new AudioOneShot(voiceSources);
    }
Ejemplo n.º 2
0
    public void AddLoopToQueue(string loopId)
    {
        AudioLoop loop = GetLoopFromId(loopId);

        if (loop != null)
        {
            _playQueue.Enqueue(loop);
            Debug.Log("Added [" + loopId + "] to queue.");
        }
    }
Ejemplo n.º 3
0
 public void TerminateLoop(AudioLoop l)
 {
     try
     {
         l.Cleanup();
     }
     catch (System.Exception e)
     {
         print(e.ToString());
     }
 }
Ejemplo n.º 4
0
 public void PlayLoop(AudioClip clip)
 {
     if (!audioSourceList.ContainsKey(clip))
     {
         AudioLoop loop = new AudioLoop();
         loop.source = this.gameObject.AddComponent<AudioSource>();
         loop.lastPlayTime = Time.fixedTime;
         loop.source.clip = clip;
         loop.source.Play();
         audioSourceList.Add(clip, loop);
     }
 }
Ejemplo n.º 5
0
 void Awake()
 {
     if (instance != null && instance != this)
     {
         Destroy(this.gameObject);
         return;
     }
     else
     {
         instance = this;
     }
     DontDestroyOnLoad(this.gameObject);
 }
Ejemplo n.º 6
0
        void Awake()
        {
            m_Instance = this;

            // Get that giant spam of clones out of the hierarchy
            Transform audioParent = new GameObject("AudioManager Things").transform;

            audioParent.parent = transform;

            m_AudioOneShots = new GvrAudioSource[m_NumAudioOneShots];
            for (int i = 0; i < m_AudioOneShots.Length; ++i)
            {
                GameObject     audioObj    = Instantiate(m_AudioOneShotPrefab, audioParent, true);
                GvrAudioSource audioSource = audioObj.GetComponent <GvrAudioSource>();
                audioSource.disableOnStop = true;

                m_AudioOneShots[i] = audioSource;
            }
            m_NextAvailableAudioOneShot = 0;

            m_AudioLoops = new AudioLoop[m_NumAudioLoops];
            for (int i = 0; i < m_AudioLoops.Length; ++i)
            {
                GameObject     audioObj    = Instantiate(m_AudioLoopPrefab, audioParent, true);
                GvrAudioSource audioSource = audioObj.GetComponent <GvrAudioSource>();
                audioSource.disableOnStop = true;
                audioSource.loop          = true;

                m_AudioLoops[i] = new AudioLoop
                {
                    m_GvrAudioSource = audioSource,
                    m_LoopName       = null
                };
            }
            m_RecentlyUsedAudioLoop = 0;

            GameObject musicObj = Instantiate(m_MusicPrefab, audioParent, true);

            m_Music = musicObj.GetComponent <AudioSource>();

            m_ItemHoverSoundIndex    = 0;
            m_PanelActivateTimestamp = Time.realtimeSinceStartup;
            m_InitWorldGrabTimestamp = Time.realtimeSinceStartup;
            m_HintAnimateTimestamp   = Time.realtimeSinceStartup;

            m_AudioSfxEnabled = false;

            m_ActiveGameMusicIndex = -1;
        }
Ejemplo n.º 7
0
    public AudioLoop CreateLoop(string s, float capVolume, bool startLoud)
    {
        AudioSource source = gameObject.AddComponent <AudioSource>();

        source.clip = FindClip(s);
        source.loop = true;
        source.name = s;
        if (!startLoud)
        {
            source.volume = 0;
        }
        source.Play();
        AudioLoop loop = gameObject.AddComponent <AudioLoop>().Initialize(source, capVolume, startLoud);

        Loops.Add(loop);
        return(Loops[Loops.Count - 1]);
    }
Ejemplo n.º 8
0
    public void PlayNextLoop()
    {
        if (_playQueue.Any())
        {
            AudioLoop loop = _playQueue.Dequeue();

            for (int i = 0; i < _playerTracks.Count; i++)
            {
                if (loop.Tracks.Count > i)
                {
                    _playerTracks[i].Initialize(loop.Tracks[i]);
                }
            }

            AudioManager.Instance.PlaySound(loop.AudioAssetId, true);
            PlayingTrack = true;
        }
    }
Ejemplo n.º 9
0
    // loads the game
    public void LoadGame()
    {
        // game shouldn't be loaded.
        if (!loadGame)
        {
            Debug.Log("Game loading is disabled. Set 'loadGame' to true, and call LoadGame() again.");
            return;
        }

        // destroys any debug objects in the scene.
        {
            // destroys the debug object and its children.
            GameObject debug = GameObject.Find("Debug");

            // destroys the parent and the children.
            if (debug != null)
            {
                Destroy(debug.gameObject);
            }
        }

        // searches for gameplay manager
        manager = FindObjectOfType <GameplayManager>();

        // if the manager does not exist, then it creates a new one.
        if (manager == null)
        {
            // searches for an object with the manager.
            GameObject temp = GameObject.Find("Manager");

            // if an object with the name "manager" was not found, then it searches for an object called "Gameplay Manager"
            if (temp == null)
            {
                temp = GameObject.Find("Gameplay Manager");
            }

            // object doesn't exist, so a new gameplay manager is made.
            if (temp == null)
            {
                // generate manager
                temp    = Instantiate((GameObject)(Resources.Load("Prefabs/Gameplay Manager")));
                manager = temp.GetComponent <GameplayManager>();
            }
            else
            {
                manager = temp.GetComponent <GameplayManager>();

                // if the manager is null, add the component
                if (manager == null)
                {
                    manager = gameObject.AddComponent <GameplayManager>();
                }
            }
        }
        else
        {
            // creates a new manager
            // Destroy(manager); // destroys the current manager
            // GameObject temp = Instantiate((GameObject)(Resources.Load("Prefabs/Gameplay Manager")));
            // manager = temp.GetComponent<GameplayManager>();
        }

        // sets this as the builder that made the manager.
        if (manager != null)
        {
            // TODO: perhaps order of deletion is screwing this up?
            manager.gameBuilder = this;
            manager.DestroyAllPlayers(); // destroys all existing players.
        }


        // create game assets

        // LOAD MAP
        if (loadMapOnEntry) // load map on entry.
        {
            GameObject  loadedObjects = new GameObject("Loaded Objects");
            LevelLoader levelLoader   = loadedObjects.AddComponent <LevelLoader>();

            // LevelLoader levelLoader = new LevelLoader();
            // levelLoader.parent = new GameObject("Loaded Objects");

            levelLoader.parent = loadedObjects;


            levelLoader.loadAsChildren = true;

            // TODO: move stage files into folder
            switch (map)
            {
            default:
            case stages.none:     // no map, so load the debug scene instead.
                loadGame = false;
                // NOTE: do NOT try to jump to another scene when processing a switch to an exiting scene.
                // UnityEngine.SceneManagement.SceneManager.LoadScene("DebugScene"); // TODO: update when you rename scene.
                levelLoader.file = "unnamed.dat";
                break;

            case stages.halloween:     // halloween stage
                levelLoader.file = "halloween_stage.dat";
                break;

            case stages.christmas:     // christmas stage
                levelLoader.file = "christmas_stage.dat";
                break;

            case stages.valentines:     // valentine's day stage
                levelLoader.file = "valentines_day_stage.dat";
                break;
            }

            // load contents
            if (levelLoader.file != "")
            {
                levelLoader.LoadFromFile();
            }

            stage = levelLoader.GetComponent <Stage>();

            // gets component from children if stage comp wasn't found.
            if (stage == null)
            {
                stage = levelLoader.GetComponentInChildren <Stage>();
            }
        }
        else if (!loadMapOnEntry)               // map should not be loaded on entry.
        {
            stage = FindObjectOfType <Stage>(); // finds the stage object in the scene.

            // if not set, it searches for the stage object.
            if (stage == null)
            {
                Debug.LogError("No Stage Component Found.");

                // GameObject temp = GameObject.Find("Stage");
                //
                // // if there is no parent object named "stage", then nothing happens
                // if(temp != null)
                // {
                //     // gets the component from the stage
                //     stage = temp.GetComponent<Stage>();
                //
                //     // if there is no stage component, add one.
                //     if (stage == null)
                //         stage = temp.AddComponent<Stage>();
                // }
            }
        }

        // LOAD CHARACTER ASSETS

        // create the game assets
        int count = Mathf.Clamp(playerList.Count, 0, 4);

        manager.DestroyAllPlayers(); // destroys all players

        // creates the player and puts it in the manager
        if (count == 0) // no playes set, so test player is added.
        {
            PlayerObject p = manager.CreatePlayer(0, 0, true, true, true, 0);
        }
        else if (count == 1) // only one player, so use main camera
        {
            // manager.CreatePlayer(playerList[0].number, playerList[0].character, false, true);
            manager.CreatePlayer(playerList[0].number, playerList[0].character, true, true, true, 0);
        }
        else
        {
            // multiple players. Only the first one uses the main camera.
            // for (int i = 0; i < count; i++)
            // {
            //     manager.CreatePlayer(i + 1, playerList[i], false, false);
            // }

            // player 1
            // manager.CreatePlayer(1, playerList[0], false, true, 0);
            //
            // // other players (starts at 1 since player 1 has been created)
            // for (int i = 1; i < count; i++)
            // {
            //     manager.CreatePlayer(i + 1, playerList[i], false, false, i);
            // }

            // pass in builder player
            foreach (BuilderPlayer bp in playerList)
            {
                PlayerObject p = manager.CreatePlayer(bp.number, bp.character, bp.controllable, bp.destorySaved, bp.useMainCam, bp.targetDisplay);
                p.name = "P" + bp.number + " - " + p.name; // change name to show player number.
            }
        }

        manager.playerCount = count;

        // creating players - now happens in the for loop above.
        // for (int i = 0; i < count; i++)
        // {
        //     // player object
        //     GameObject newPlayer = null;
        //     PlayerObject playerComp = null;
        //
        //     // goes through all the players
        //     switch (playerList[i])
        //     {
        //         default:
        //         case playables.none: // no character set
        //             newPlayer = Instantiate((GameObject)Resources.Load("Prefabs/Characters/Player"));
        //             playerComp = newPlayer.GetComponent<PlayerObject>();
        //             break;
        //
        //         case playables.dog: // dog
        //             newPlayer = Instantiate((GameObject)Resources.Load("Prefabs/Characters/Dog Player"));
        //             playerComp = newPlayer.GetComponent<DogPlayer>();
        //             break;
        //
        //         case playables.cat: // cat
        //             newPlayer = Instantiate((GameObject)Resources.Load("Prefabs/Characters/Cat Player"));
        //             playerComp = newPlayer.GetComponent<CatPlayer>();
        //             break;
        //
        //         case playables.bunny: // bunny
        //             newPlayer = Instantiate((GameObject)Resources.Load("Prefabs/Characters/Bunny Player"));
        //             playerComp = newPlayer.GetComponent<PlayerObject>();
        //             break;
        //
        //         case playables.turtle: // turtle
        //             newPlayer = Instantiate((GameObject)Resources.Load("Prefabs/Characters/Turtle Player"));
        //             playerComp = newPlayer.GetComponent<PlayerObject>();
        //             break;
        //     }
        //
        //     // adds player to manager
        //     // there can only be maximum of 4 players
        //     switch (i + 1)
        //     {
        //         case 1:
        //             manager.p1 = playerComp;
        //             break;
        //         case 2:
        //             manager.p2 = playerComp;
        //             break;
        //         case 3:
        //             manager.p3 = playerComp;
        //             break;
        //         case 4:
        //             manager.p4 = playerComp;
        //             break;
        //     }
        // }

        // TODO: check and see if the stage Start() needs to be called.

        // if the stage is not null, randomize the positions of the players
        if (stage != null)
        {
            // this is a bit finicky, but it works.
            // stage start has not yet been called, so the player spawns are searched for.
            stage.AddSpawnPoints(true);              // adds the spawn points since start() has not been called yet.
            stage.RandomizePlayerPositions(manager); // randomizes the player positions
            stage.findSpawns = false;                // don't need to find the spawns again.
        }


        // LOAD AUDIO
        {
            AudioClip clip = stage.bgm;

            if (clip == null)
            {
                clip = (AudioClip)(Resources.Load("Audio/BGMs/BGM_MAP_THEME_01"));
            }

            // gets the audio source
            AudioSource audioSource = manager.GetComponentInChildren <AudioSource>();

            // if there is an audio source, play the audio.
            if (audioSource != null)
            {
                // add in the clip
                audioSource.clip = clip;
                audioSource.mute = false;
                audioSource.Play();
            }

            // gets the audio loop component.
            // TODO: maybe save this somewhere to save load time?
            AudioLoop audioLoop = GetComponentInChildren <AudioLoop>();

            // looping audio
            if (audioLoop == null)
            {
                audioLoop = gameObject.AddComponent <AudioLoop>();
            }

            // enables audio loop
            // TODO: should you check if it's already enabled first?
            audioLoop.enabled   = true;
            audioLoop.clipStart = stage.bgmClipStart;
            audioLoop.clipEnd   = stage.bgmClipEnd;

            // TODO: safety check
        }

        // skybox
        {
            if (stage.skybox != null)
            {
                RenderSettings.skybox = stage.skybox;
            }
        }

        // items
        // clears out all items.
        ItemManager.GetInstance().ClearAllItemsInPool();

        // score
        if (winScore > 0)
        {
            manager.winScore = winScore;
        }

        // time
        if (countdownStart != -1)
        {
            // if countdown timer exists, give it this time.
            if (manager.countdownTimer != null)
            {
                manager.countdownTimer.SetCountdownStartTime(countdownStart);
            }
        }

        // next scene.
        if (sceneAfterGame != "")
        {
            // sets next scene if it exists. Leaves alone if not available.
            // if (SceneChanger.SceneExists(sceneAfterGame))

            manager.nextScene = sceneAfterGame;
        }

        // game has been loaded. Turn back on before going to a new scene to load game assets.
        loadGame = false;
    }
Ejemplo n.º 10
0
 public void PlayMusic(AudioLoop al)
 {
     Global.instance.PlayMusic(al);
 }
Ejemplo n.º 11
0
    public void TransitionMusic(string s)
    {
        AudioLoop activeMusic = FindAudioLoop(s);
        bool      MenuOpen    = (previousTheme == "Music_Credits" || previousTheme == "Music_Menu" || previousTheme == "Music_CarSelect");

        AudioSource intro;

        switch (previousTheme + ">" + s)
        {
        case ">Music_Menu":
            intro = CreateOneShot("Music_MenuIntro", 1);
            FindAudioLoop("Music_Menu").FadeAbsolute(true, 0f);
            FindAudioLoop("Music_Menu").source.Stop();
            FindAudioLoop("Music_Menu").source.PlayScheduled(AudioSettings.dspTime + intro.clip.length);
            break;

        case "Music_Gameplay>Music_CarSelect":
            if (FindAudioSource("Music_MenuIntro") != null)
            {
                TerminateSource(FindAudioSource("Music_MenuIntro"));
            }
            FindAudioLoop("Music_Gameplay").FadeAbsolute(false, 2f);

            firstCreditsEntry = true;
            intro             = CreateOneShot("Music_MenuIntro", 1);
            FindAudioLoop("Music_Menu").FadeAbsolute(true, 0f);
            FindAudioLoop("Music_Menu").source.PlayScheduled(AudioSettings.dspTime + intro.clip.length);
            break;

        case "Music_Credits>Music_CarSelect":
        case "Music_Credits>Music_Menu":
            //fade in menu intro
            //use menuintro if available
            if (FindAudioSource("Music_MenuIntro"))
            {
                //If fading menu intro out, stop
                if (menuIntroFade != null)
                {
                    StopCoroutine(menuIntroFade);
                }
                //fade in menuIntro
                menuIntroFade = StartCoroutine(MenuThemeFade(true, 1f));
            }
            FindAudioLoop("Music_Menu").FadeAbsolute(true, 1f);
            //fade out credits
            FindAudioLoop("Music_Credits").FadeAbsolute(false, 1f);
            break;

        case "Music_Menu>Music_Credits":
            if (firstCreditsEntry)
            {
                FindAudioLoop("Music_Credits").source.Play();
                FindAudioLoop("Music_Credits").FadeAbsolute(true, 0);
                firstCreditsEntry = false;
            }
            else
            {
                FindAudioLoop("Music_Credits").FadeAbsolute(true, 1);
            }
            //Edge case: fade out music intro instead of loop, instead set loop to 0 so delayed doesn't sneak in
            if (FindAudioSource("Music_MenuIntro"))
            {
                FindAudioLoop("Music_Menu").FadeAbsolute(false, 0f);
                if (menuIntroFade != null)
                {
                    StopCoroutine(menuIntroFade);
                }

                menuIntroFade = StartCoroutine(MenuThemeFade(false, 1f));
            }
            else
            {
                FindAudioLoop("Music_Menu").FadeAbsolute(false, 1f);
            }
            break;

        case "Music_CarSelect>Music_Menu":
            break;

        case "Music_Menu>Music_Gameplay":
        case "Music_CarSelect>Music_Gameplay":
            //cancel play scheduled
            FindAudioLoop("Music_Menu").FadeAbsolute(false, 0f);
            //Edge case: fade out music intro instead of loop
            if (FindAudioSource("Music_MenuIntro"))
            {
                if (menuIntroFade != null)
                {
                    StopCoroutine(menuIntroFade);
                }

                menuIntroFade = StartCoroutine(MenuThemeFade(false, 1f));
            }
            else
            {
                FindAudioLoop("Music_Menu").FadeAbsolute(false, 1f);
            }
            //fade in gameplay
            AudioLoop gameplay = FindAudioLoop("Music_Gameplay");
            gameplay.FadeAbsolute(true, 1f);
            gameplay.source.Stop();
            gameplay.source.Play();
            break;
        }

        previousTheme = s;
    }