Esempio n. 1
0
    public static void Stop()
    {
        //list.Clear();

        // 便利所有的子对象,干掉

        /*if (instance == null)
         *      return;
         * foreach (Transform t in instance.transform)
         * {
         *      instance.StartCoroutine(instance.FadeOut(t.GetComponent<AudioSource>()));
         * }*/
        for (int i = 0; i < GaeList.Count; i++)
        {
            if (GaeList[i] != null && GaeList[i].gameObject.name != backGroundSoundName)
            {
                Debug.Log(i + "," + GaeList.Count + "," + GaeList[i].gameObject);
                GaeList[i].Stop();

                GameObjectActionAudioFade gaf = new GameObjectActionAudioFade(SOUND_MAX, 0, 0.5f);
                //if(GaeList.Count <= i)
                //	Debug.Log("Stop:元素被毁掉删除掉了");
                GaeList[i].AddAction(gaf);

                GameObjectActionDelayDestory gad = new GameObjectActionDelayDestory(0f);
                gad.m_complete = AudioDestroyCallBack;
                GaeList[i].AddAction(gad);
            }
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Play the specified ac, bLoop, bFade, bBackGround and delay.
    /// </summary>
    /// <param name="ac">Ac.</param>
    /// <param name="bLoop">If set to <c>true</c> b loop.</param>
    /// <param name="bFade">If set to <c>true</c> b fade.</param>
    /// <param name="bBackGround">是否是背景音乐.</param>
    /// <param name="delay">Delay.</param>
    public static void Play(AudioClip ac, bool bLoop, bool bFade, bool bBackGround = false, float delay = 0f)
    {
        if (denySound)
        {
            return;
        }

        // 开始播放
        if (instance == null)
        {
            return;
        }
        GameObject o = new GameObject(ac.name);

        o.transform.parent = instance.transform;
        AudioSource source = o.AddComponent <AudioSource>();

        source.clip        = ac;
        source.volume      = SOUND_MAX;
        source.minDistance = 1000f;
        source.maxDistance = 1000f;
        source.time        = 0f;
        source.loop        = bLoop;
        source.Play();
        o.AddComponent <NdAudioSprite>();
        GameObjectActionExcute gae = o.AddComponent <GameObjectActionExcute>();

        GaeList.Add(gae);

        if (bFade)
        {
            // 淡入
            GameObjectActionAudioFade gaf = new GameObjectActionAudioFade(0, SOUND_MAX, 0.5f);
            gae.AddAction(gaf);
        }
        if (!bBackGround)
        {
            GameObjectActionPlaySound gap = new GameObjectActionPlaySound(0f);
            gae.AddAction(gap);
        }
        // 等待播放结束
        if (!bLoop)
        {
            GameObjectActionDelayDestory gad = new GameObjectActionDelayDestory(delay);
            gad.m_complete = AudioDestroyCallBack;
            //Coroutine.DispatchService(instance.WaitEnd(source), instance.gameObject, null);*/
            gae.AddAction(gad);
        }
    }
Esempio n. 3
0
    /// <summary>
    /// 停止音乐播放
    /// </summary>
    public static void Stop(string soundFile, bool bFade)
    {
        if (string.IsNullOrEmpty(soundFile))
        {
            return;
        }

        for (int i = 0; i < GaeList.Count; i++)
        {
            if (GaeList[i] != null && GaeList[i].gameObject.name == soundFile)
            {
                GaeList[i].Stop();
                if (bFade)
                {
                    GameObjectActionAudioFade gaf = new GameObjectActionAudioFade(SOUND_MAX, 0, 0.5f);
                    GaeList[i].AddAction(gaf);
                }

                GameObjectActionDelayDestory gad = new GameObjectActionDelayDestory(0f);
                gad.m_complete = AudioDestroyCallBack;
                GaeList[i].AddAction(gad);
            }
        }
        // 从待播放列表中摘除
        //list.Remove(soundFile);

        // 便利所有的子对象,干掉

        /*if (instance == null)
         *      return;
         * foreach (Transform t in instance.transform)
         * {
         *      if (t.name != soundFile)
         *              continue;
         *
         *      // 符合条件,直接干掉
         *      if (! bFade)
         *              GameObject.Destroy(t.gameObject);
         *      else
         *      {
         *              // 需要淡出
         *              Coroutine.DispatchService(instance.FadeOut(t.GetComponent<AudioSource>()), instance.gameObject, null);
         *      }
         * }*/
    }