示例#1
0
    private void Awake()
    {
        if (S != null)
        {
            DestroyImmediate(gameObject);
            return;
        }

        S = this;

        currentBgm = previousBgm = BgmSoundCode.None;



        Camera mainCamera = Camera.main;

        bgmSpeaker = mainCamera.GetComponent <AudioSource>();
        if (bgmSpeaker == null)
        {
            bgmSpeaker = mainCamera.gameObject.AddComponent <AudioSource>();
        }
        bgmSpeaker.loop = true;


        EventManager.StartListening(typeof(SoundEvent), SoundListener);
    }
 public SoundEvent(SoundType soundType, FxSoundCode fxSoundCode, Vector3 fxSoundPosition)
 {
     this.soundType            = soundType;
     this.bgmSoundCode         = BgmSoundCode.None;
     this.fxSoundCode          = fxSoundCode;
     this.fxSoundWorldPosition = fxSoundPosition;
 }
示例#3
0
    private void StopAndPlayBgmSound(BgmSoundCode bgmSoundCode)
    {
        if ((int)bgmSoundCode >= bgmSounds.Count || bgmSounds[(int)bgmSoundCode] == null)
        {
            return;
        }



        previousBgm = currentBgm;

        bgmSpeaker.Stop();

        if (bgmSoundCode == BgmSoundCode.None)
        {
            bgmSpeaker.clip = null;
        }
        else
        {
            bgmSpeaker.clip = bgmSounds[(int)bgmSoundCode];
            bgmSpeaker.Play();
        }

        currentBgm = bgmSoundCode;
    }
 public SoundEvent(SoundType soundType, BgmSoundCode bgmSoundCode)
 {
     this.soundType       = soundType;
     this.bgmSoundCode    = bgmSoundCode;
     this.fxSoundCode     = FxSoundCode.None;
     fxSoundWorldPosition = Vector3.zero;
 }