Ejemplo n.º 1
0
    /// <summary>
    /// 初始化,挂载舞台上
    /// </summary>
    /// <param name="root"></param>
    public static void InitRoot(Transform root)
    {
        if (_instance != null)
        {
            return;
        }

        GameObject go = new GameObject();

        go.name             = "SoundManager";
        go.transform.parent = root;
        _instance           = go.AddComponent <SoundManager>();

        _bgmPlayer = new BgmPlayer();
        _bgmPlayer.Init(go.transform);

        _soundPlayer = new SoundPlayer();
        _soundPlayer.Init(go.transform);
    }
Ejemplo n.º 2
0
    /// <summary>
    /// 初始化
    /// </summary>
    protected virtual void Init()
    {
        //音频扬声器模式;
        //API修改(AudioSettings.driverCapabilities;在IOS上无声音) (修改前:AudioSettings.speakerMode = AudioSettings.driverCapabilities) by邓成
        AudioConfiguration confuguration = AudioSettings.GetConfiguration();

        confuguration.speakerMode = AudioSettings.driverCapabilities;
        AudioSettings.Reset(confuguration);
        //初始化播放源组件
        if (mySoundLoader != null)
        {
            GameObject.DestroyImmediate(mySoundLoader);
            mySoundLoader = null;
        }
        GameObject loaderObj = new GameObject("SoundLoader");

        loaderObj.transform.parent           = GameCenter.instance.transform;
        loaderObj.transform.localPosition    = Vector3.zero;
        loaderObj.transform.localEulerAngles = Vector3.zero;
        loaderObj.transform.localScale       = Vector3.one;
        mySoundLoader = loaderObj.AddComponent <SoundLoader>();

        if (mySoundPlayer != null)
        {
            GameObject.DestroyImmediate(mySoundPlayer);
            mySoundPlayer = null;
        }
        GameObject playerObj = new GameObject("SoundPlayer");

        playerObj.transform.parent           = GameCenter.instance.transform;
        playerObj.transform.localPosition    = Vector3.zero;
        playerObj.transform.localEulerAngles = Vector3.zero;
        playerObj.transform.localScale       = Vector3.one;
        mySoundPlayer = playerObj.AddComponent <SoundPlayer>();
        mySoundPlayer.Init(mySoundLoader);


        preLoadSound();
        GameCenter.systemSettingMng.OnUpdate += OnUpdateSystemSettings;
    }