Exemple #1
0
        public IEnumerator LoadAudioFiles(DirectoryInfo dir)
        {
            FileInfo[] files = new DirectoryInfo(dir.FullName + "/Audio").GetFiles("*.wav");
            foreach (FileInfo file in files)
            {
                GeneralManager.Instance.LogToFileOrConsole("[PromDate] Loading audio file: " + file.Name);
                WWW www = new WWW("file:///" + file.FullName);
                yield return(www);

                if (www.error != null)
                {
                    GeneralManager.Instance.LogToFileOrConsole(www.error);
                }
                AudioClip clip = www.GetAudioClip(false, false);
                clip.LoadAudioData();
                clip.name = file.Name.Split('.')[0];
                while (clip.loadState == AudioDataLoadState.Loading || clip.loadState == AudioDataLoadState.Unloaded)
                {
                    yield return(0);
                }
                AudioCategory category = AudioController.GetCategory(clip.name.Split('_')[0].ToUpper());
                if (category == null)
                {
                    category = AudioController.GetCategory("VOICE");
                }
                AudioItem audioItem = AudioController.AddToCategory(category, clip, clip.name);
                ((Dictionary <string, AudioItem>) typeof(AudioController).GetField("_audioItems", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(AudioController.Instance)).Add(audioItem.Name, audioItem);
                GeneralManager.Instance.LogToFileOrConsole("[PromDate] Finished loading audio: " + file.Name);
            }
        }
        /// <summary>
        /// 检测并返回一个Audio Item
        /// </summary>
        /// <param name="_name">音效名字</param>
        /// <param name="_category">音效类别</param>
        /// <returns></returns>
        public AudioItem CheckAudioItem(string _name, string _category)
        {
            if (true == string.IsNullOrEmpty(_name))
            {
                return(null);
            }
            if (true == AudioController.IsValidAudioID(_name))
            {
                return(AudioController.GetAudioItem(_name));
            }
            AudioClip audioClip = null;

            // 加载音频资源
            if (null != loadResEvent)
            {
                var audioObject = loadResEvent(_name, "audio");
                if (null != audioObject && true == audioObject is AudioClip)
                {
                    audioClip = (AudioClip)audioObject;
                }
            }
            if (null == audioClip)
            {
                this.Warr(StringCacheFactory.GetFree().Add("无法加载音频 = ").Add(_name));
                return(null);
            }
            var audio_category = AudioController.GetCategory(_category);

            if (null != audio_category)
            {
                AudioItem audioItem = AudioController.AddToCategory(audio_category, audioClip, _name);
                return(audioItem);
            }
            return(null);
        }
Exemple #3
0
    void DrawGuiRightSide()
    {
        int ypos        = 50;
        int yposOff     = 35;
        int buttonWidth = 300;

        if (!wasCategoryAdded)
        {
            if (customAudioClip != null && GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Create new category with custom AudioClip"))
            {
                var category = AudioController.NewCategory("Custom Category");
                AudioController.AddToCategory(category, customAudioClip, "CustomAudioItem");
                wasClipAdded     = true;
                wasCategoryAdded = true;
            }
        }
        else
        {
            if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play custom AudioClip"))
            {
                AudioController.Play("CustomAudioItem");
            }

            if (wasClipAdded)
            {
                ypos += yposOff;

                if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Remove custom AudioClip"))
                {
                    if (AudioController.RemoveAudioItem("CustomAudioItem"))
                    {
                        wasClipAdded = false;
                    }
                }
            }
        }

        ypos = 130;

#if !UNITY_AUDIO_FEATURES_4_1
        GUI.enabled = false;
#endif

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play gapless audio loop [Unity v4.1]"))
        {
            AudioController.Play("GaplessLoopTest").Stop(1, 4);
        }
        ypos += yposOff;

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play random loop sequence [Unity v4.1]"))
        {
            AudioController.Play("RandomLoopSequence");
        }

#if !UNITY_AUDIO_FEATURES_4_1
        GUI.enabled = true;
#endif
    }
Exemple #4
0
    public static void PlayList(List <string> playList)
    {
        var category = AudioController.GetCategory("StoryMusic");

        foreach (var strAudio in playList)
        {
            AudioClip clip = Resources.Load(ResoucesPathEnum.musicPath + strAudio, typeof(AudioClip)) as AudioClip;
            AudioController.AddToCategory(category, clip, strAudio);
        }
        AudioController.AddPlaylist("test", playList.ToArray());
        AudioController.Instance.loopPlaylist = true;
        AudioController.PlayMusicPlaylist("test");
    }
Exemple #5
0
    void DrawGuiRightSide()
    {
        int ypos        = 10;
        int yposOff     = 35;
        int buttonWidth = 300;

        if (!wasCategoryAdded)
        {
            if (customAudioClip != null && GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Create new category with custom AudioClip"))
            {
                var category = AudioController.NewCategory("Custom Category");
                AudioController.AddToCategory(category, customAudioClip, "CustomAudioItem");
                wasClipAdded     = true;
                wasCategoryAdded = true;
            }
            ypos += yposOff;
        }
        else
        {
            if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play custom AudioClip"))
            {
                AudioController.Play("CustomAudioItem");
            }

            ypos += yposOff;

            if (wasClipAdded)
            {
                if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Remove custom AudioClip"))
                {
                    if (AudioController.RemoveAudioItem("CustomAudioItem"))
                    {
                        wasClipAdded = false;
                    }
                }
            }
        }

        ypos += yposOff;

#if !UNITY_AUDIO_FEATURES_4_1
        BeginDisabledGroup(true);
#endif

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play gapless audio loop"))
        {
            AudioController.Play("GaplessLoopTest").Stop(1, 4);
        }
        ypos += yposOff;

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play random loop sequence"))
        {
            AudioController.Play("RandomLoopSequence");
        }
        ypos += yposOff;

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 50), "Play intro-loop-outro sequence\ngatling gun"))
        {
            introLoopOutroAudio = AudioController.Play("IntroLoopOutro_Gun");
        }

        ypos += 20;
        ypos += yposOff;

        BeginDisabledGroup(introLoopOutroAudio == null);

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Finish gatling gun sequence"))
        {
            introLoopOutroAudio.FinishSequence();
        }

        EndDisabledGroup();
        ypos += yposOff;

#if !UNITY_AUDIO_FEATURES_4_1
        EndDisabledGroup();
#endif

        ypos += 10;

        const float textWidth = 500;

        GUI.skin.box.alignment = TextAnchor.UpperLeft;
        GUI.skin.box.wordWrap  = true;
        GUI.skin.box.richText  = true;

        const string infoText =
            "<size=18><color=orange>Welcome to Audio Toolkit!\n</color></size>" +
            "<size=14>The number one audio management solution for Unity used in AAA titles!\n\n" +
            "What does the toolkit do? In a nutshell:\n" +
            "1) It separates scripting from managing audio:\n" +
            " Let your audio artist define complex behaviours of what 'MySoundID' will sound like. All within the Unity inspector.\n" +
            "2) Trigger audio without any scripting knowledge using the example behaviours like <color=lightblue>PlayAudio</color> or by script with\n" +
            " a simple function call, e.g. <color=lightblue>AudioController.Play( \"MySoundID\" );</color>\n" +
            "3) It makes life much easier in many ways: control volume by categories, play random effects, chain sequences of sound files, define sound alternatives, manage playlists, ...\n" +
            "\n<color=cyan>Select the AudioController game object to see how to configure audio in the inspector!</color>" +
            "</size>";

        GUI.Box(new Rect(Screen.width - textWidth, ypos, textWidth - 10, Screen.height - ypos - 60), infoText);
    }
Exemple #6
0
    void DrawGuiRightSide()
    {
        int ypos        = 50;
        int yposOff     = 35;
        int buttonWidth = 300;

        if (!wasCategoryAdded)
        {
            if (customAudioClip != null && GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Create new category with custom AudioClip"))
            {
                var category = AudioController.NewCategory("Custom Category");
                AudioController.AddToCategory(category, customAudioClip, "CustomAudioItem");
                wasClipAdded     = true;
                wasCategoryAdded = true;
            }
        }
        else
        {
            if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play custom AudioClip"))
            {
                AudioController.Play("CustomAudioItem");
            }

            if (wasClipAdded)
            {
                ypos += yposOff;

                if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Remove custom AudioClip"))
                {
                    if (AudioController.RemoveAudioItem("CustomAudioItem"))
                    {
                        wasClipAdded = false;
                    }
                }
            }
        }

        ypos = 130;

#if !UNITY_AUDIO_FEATURES_4_1
        BeginDisabledGroup(true);
#endif

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play gapless audio loop"))
        {
            AudioController.Play("GaplessLoopTest").Stop(1, 4);
        }
        ypos += yposOff;

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Play random loop sequence"))
        {
            AudioController.Play("RandomLoopSequence");
        }
        ypos += yposOff;

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 50), "Play intro-loop-outro sequence\ngatling gun"))
        {
            introLoopOutroAudio = new PoolableReference <AudioObject>(AudioController.Play("IntroLoopOutro_Gun"));
        }

        ypos += 20;
        ypos += yposOff;

        BeginDisabledGroup(!(introLoopOutroAudio != null && introLoopOutroAudio.Get() != null));

        if (GUI.Button(new Rect(Screen.width - (buttonWidth + 20), ypos, buttonWidth, 30), "Finish gatling gun sequence"))
        {
            introLoopOutroAudio.Get().FinishSequence();
        }

        EndDisabledGroup();

#if !UNITY_AUDIO_FEATURES_4_1
        EndDisabledGroup();
#endif
    }