コード例 #1
0
    private IEnumerator PlayAudioClipDelayed(AudioClipConfig clipConfig, float delay, bool is3D, Vector3 position)
    {
        yield return(new WaitForSeconds(delay));

        if (is3D)
        {
            CreateAndPlay3DAudioClip(clipConfig, position);
        }
        else
        {
            CreateAndPlay2DAudioClip(clipConfig);
        }
    }
コード例 #2
0
    private void CreateAndPlay2DAudioClip(AudioClipConfig clipConfig)
    {
        var audioSource = new GameObject("2D Audio Source").AddComponent <AudioSource>();

        audioSource.playOnAwake           = false;
        audioSource.loop                  = false;
        audioSource.spatialize            = false;
        audioSource.clip                  = clipConfig.Clip;
        audioSource.volume                = clipConfig.Volume;
        audioSource.outputAudioMixerGroup = clipConfig.OutputAudioMixerGroup;
        audioSource.Play();
        Destroy(audioSource.gameObject, clipConfig.Clip.length);
    }
コード例 #3
0
    private void CreateAndPlay3DAudioClip(AudioClipConfig clipConfig, Vector3 position)
    {
        var audioSource = new GameObject("3D Audio Source").AddComponent <AudioSource>();

        audioSource.transform.position = position;
        audioSource.playOnAwake        = false;
        audioSource.loop                  = false;
        audioSource.spatialize            = true;
        audioSource.clip                  = clipConfig.Clip;
        audioSource.volume                = clipConfig.Volume;
        audioSource.spatialBlend          = 1;
        audioSource.maxDistance           = _maxSoundDistance;
        audioSource.outputAudioMixerGroup = clipConfig.OutputAudioMixerGroup;
        audioSource.Play();
        Destroy(audioSource.gameObject, clipConfig.Clip.length);
    }
コード例 #4
0
        protected override void OnDelayedAttachAsMain(Character target)
        {
            SfxPlayer.instance.AddIntervalConfig(new IntervalConfigEntry()
            {
                id       = skillId.StringValue,
                interval = info.Smc.interval
            });
            CharacterId     targetCharacterId = targetEntity.GetComponent <SkillComponent>().CharacterId;
            AudioClipConfig acc = null;

            foreach (AudioAndCharacterId aaci in info.Smc.overrides)
            {
                if (aaci.charId.Equals(targetCharacterId.StringValue))
                {
                    if (aaci.audioClips.Count > 0)
                    {
                        acc = aaci.audioClips[BattleUtils.RandomRangeInt(0, aaci.audioClips.Count)];
                    }
                }
            }

            if (acc == null)
            {
                if (info.Smc.audioClips.Count > 0)
                {
                    acc = info.Smc.audioClips[BattleUtils.RandomRangeInt(0, info.Smc.audioClips.Count)];
                }
            }

            if (acc != null)
            {
                SfxPlayer.instance.AddPlaybackRequest(new PlaybackRequest()
                {
                    intervalId = skillId.StringValue,
                    audioPath  = acc.audioPath,
                    pitch      = acc.pitch,
                    volume     = acc.volume
                });
            }
        }