Exemple #1
0
    public float PlaySound(AudioClipData data, AudioGroupType group, Action <float> OnFinishTime = null)
    {
        if (data == null || string.IsNullOrEmpty(data.AudioRes))
        {
            return(0);
        }
        var clip = Resources.Load <AudioClip>(data.AudioRes);

        PlaySound(clip, null, AudioListenerNode.position, false, data.Volume, group, OnFinishTime);
        return(clip.length);
    }
        protected override void onUpdate(float dt)
        {
            ActiveDungeon activeDungeon = GameLogic.Binder.GameState.ActiveDungeon;

            if ((activeDungeon != null) && (((base.CharacterView.Character != null) && base.CharacterView.Character.IsPrimaryPlayerCharacter) && !base.CharacterView.Character.IsSupport))
            {
                if (((Time.timeScale == 1f) && (base.CharacterView.Animator.CurrentAction == AbstractCharacterAnimator.Action.NONE)) && ((base.CharacterView.Animator.TargetState == AbstractCharacterAnimator.State.RUN) && (activeDungeon.CurrentGameplayState == GameplayState.ACTION)))
                {
                    if (activeDungeon.Dungeon.Theme == DungeonThemeType.Theme002)
                    {
                        this.m_footStepTypeL = AudioGroupType.SfxGrpGameplay_HeroStepGrassL;
                        this.m_footStepTypeR = AudioGroupType.SfxGrpGameplay_HeroStepGrassR;
                    }
                    else if (activeDungeon.Dungeon.Theme == DungeonThemeType.Theme003)
                    {
                        this.m_footStepTypeL = AudioGroupType.SfxGrpGameplay_HeroStepIceL;
                        this.m_footStepTypeR = AudioGroupType.SfxGrpGameplay_HeroStepIceR;
                    }
                    else
                    {
                        this.m_footStepTypeL = AudioGroupType.SfxGrpGameplay_HeroStepL;
                        this.m_footStepTypeR = AudioGroupType.SfxGrpGameplay_HeroStepR;
                    }
                    if ((PlayerView.Binder.AudioSystem.numberOfSfxAudioGroupPlaying(this.m_footStepTypeL) == 0) && (PlayerView.Binder.AudioSystem.numberOfSfxAudioGroupPlaying(this.m_footStepTypeR) == 0))
                    {
                        AudioSystem.PlaybackParameters pp = new AudioSystem.PlaybackParameters();
                        pp.PitchMin = 1f;
                        pp.PitchMax = 1f;
                        PlayerView.Binder.AudioSystem.playSfxGrp(this.m_footStepTypeL, pp);
                        AudioSystem.PlaybackParameters parameters2 = new AudioSystem.PlaybackParameters();
                        parameters2.DelayMin = 0.28f;
                        parameters2.DelayMax = 0.28f;
                        parameters2.PitchMin = 1f;
                        parameters2.PitchMax = 1f;
                        PlayerView.Binder.AudioSystem.playSfxGrp(this.m_footStepTypeR, parameters2);
                    }
                    this.updateArmorLayer(true);
                }
                else
                {
                    this.updateArmorLayer(false);
                }
            }
        }
Exemple #3
0
    public uint PlaySound(AudioClip clip, Transform posNode, Vector3 pos, bool loop, float volume, AudioGroupType group, Action <float> OnFinishTime = null)
    {
        if (clip == null)
        {
            return(0);
        }
        if (!loop && !AudioNode.gameObject.activeSelf)
        {
            return(0);
        }
        if (posNode != null)
        {
            pos = posNode.transform.position;
        }
        pos.z = AudioListenerNode.position.z;
        var dist2 = (AudioListenerNode.position - pos).sqrMagnitude;

        if (!loop && dist2 > MaxSourceDistance * MaxSourceDistance)
        {
            return(0);
        }
        var source = AllocSoundSource();

        if (source == null)
        {
            return(0);
        }

        AudioClip clipHandle = clip;

        if (clipHandle == null)
        {
            _freeSoundSourceList.Push(source);
            return(0);
        }


        source.outputAudioMixerGroup = MixerGroups[(int)group];
        var handle = ObjectPool <AudioHandle> .DefaultAlloc();

        handle.HandleId  = ++_soundHandleId;
        handle.StartTime = Time.realtimeSinceStartup;
        handle.Source    = source;
        handle.PosNode   = posNode;
        handle.Loop      = loop;
        handle.Volume    = volume;

        source.transform.position = pos;
        _usingSoundList.Add(handle);
        source.volume = _soundVolume <= 0 ? _soundVolume : _soundVolume *volume *GetVolume(Mathf.Sqrt(dist2));

        source.loop = loop;
        handle.Clip = clipHandle;
        if (OnFinishTime != null)
        {
            OnFinishTime(handle.ClipLength);
        }
        return(handle.HandleId);
    }