Esempio n. 1
0
    public virtual void Play()
    {
        if (_useDefaultSources)
        {
            switch (_defaultSourceType)
            {
            case DefaultSourceType.SFX:
                DefaultAudioSources.PlaySFX(_audioPlayable);
                break;

            case DefaultSourceType.SFX_Static:
                DefaultAudioSources.PlayStaticSFX(_audioPlayable);
                break;

            case DefaultSourceType.Music:
                if (_transitionSmoothly)
                {
                    DefaultAudioSources.TransitionToMusic(_audioPlayable);
                }
                else
                {
                    DefaultAudioSources.PlayMusic(_audioPlayable);
                }
                break;

            case DefaultSourceType.Voice:
                DefaultAudioSources.PlayVoice(_audioPlayable);
                break;
            }
        }
        else
        {
            _audioPlayable.PlayOn(_localSource);
        }
    }
Esempio n. 2
0
    [SerializeField] private AudioPlayable _damageSound; // global for now but can be per character/ennemy

    protected override void OnGamePresentationUpdate()
    {
        if (_audioSource == null)
        {
            return;
        }

        // Item sounds
        foreach (var gameActionEvent in PresentationEvents.GameActionEvents.SinceLastPresUpdate)
        {
            SimWorld.TryGetComponent(gameActionEvent.GameActionContext.Action, out SimAssetId entitySimAssetID);

            GameObject entityPrefab = PresentationHelpers.FindSimAssetPrefab(entitySimAssetID);
            if (entityPrefab != null)
            {
                var sfx = entityPrefab.GetComponent <GameActionAuth>()?.SfxOnUse;
                if (sfx != null)
                {
                    sfx.PlayOn(_audioSource);
                }
            }
        }

        // Damage sounds
        foreach (var hpDeltaEvent in PresentationEvents.HealthDeltaEvents.SinceLastPresUpdate)
        {
            if (_damageSound != null)
            {
                _damageSound.PlayOn(_audioSource);
            }
        }
    }
Esempio n. 3
0
    /// <returns>The standard source volume</returns>
    static private float Internal_PlayMusic(AudioPlayable playable, bool looping, float volumeMultiplier = 1)
    {
        if (!CheckResources_Instance() || !CheckResources_MusicSource())
        {
            return(0);
        }

        AudioSource source = GetAndIncrementMusicSource();

        source.volume = 1;

        if (looping)
        {
            playable.PlayLoopedOn(source, 1);
        }
        else
        {
            playable.PlayOn(source);
        }

        float stdVolume = source.volume;

        source.volume *= volumeMultiplier;
        return(stdVolume);
    }
Esempio n. 4
0
    private void Start()
    {
        Sfx.PlayOn(AudioSource, SfxVolumeCurve.Evaluate(transform.localScale.x));

        SpriteRenderer.DOFade(0, FadeAnimDuration).OnComplete(() =>
        {
            Destroy(gameObject, 2f);
        });
    }
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();

        AudioPlayable playable = target as AudioPlayable;

        EditorGUI.BeginDisabledGroup(serializedObject.isEditingMultipleObjects);

        GUILayoutOption largeHeight = GUILayout.Height(18 * 2 + 3);

        GUILayout.BeginHorizontal(largeHeight);

        GUI.enabled = previewAudioSource.isPlaying;
        if (GUILayout.Button("Stop", largeHeight))
        {
            previewAudioSource.Stop();
        }
        GUI.enabled = true;

        GUILayout.BeginVertical();
        if (GUILayout.Button("Preview"))
        {
            playable.PlayOn(previewAudioSource);
        }
        if (GUILayout.Button("Preview looped"))
        {
            if (previewAudioSource.isPlaying)
            {
                previewAudioSource.Stop();
            }
            playable.PlayLoopedOn(previewAudioSource);
        }
        GUILayout.EndVertical();

        GUILayout.EndHorizontal();
        EditorGUI.EndDisabledGroup();
    }
Esempio n. 6
0
    private static void PlayNonMusic(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source, AudioSource defaultSource)
    {
        if (playable == null)
        {
            return;
        }

        AudioSource theSource = source;

        if (theSource == null)
        {
            theSource = defaultSource;
        }

        if (delay > 0)
        {
            Instance.StartCoroutine(PlayNonMusicIn(playable, delay, volumeMultiplier, theSource));
            return;
        }
        else
        {
            playable.PlayOn(theSource, volumeMultiplier);
        }
    }
Esempio n. 7
0
    private void PlayNonMusic(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source, AudioSource defaultSource)
    {
        if (playable == null)
        {
            return;
        }

        AudioSource selectedSource = source;

        if (selectedSource == null)
        {
            selectedSource = defaultSource;
        }

        if (delay > 0)
        {
            StartCoroutine(PlayNonMusicIn(playable, delay, volumeMultiplier, selectedSource));
            return;
        }
        else
        {
            playable.PlayOn(selectedSource, volumeMultiplier);
        }
    }
Esempio n. 8
0
    private static IEnumerator PlayNonMusicIn(AudioPlayable playable, float delay, float volumeMultiplier, AudioSource source)
    {
        yield return(new WaitForSecondsRealtime(delay));

        playable.PlayOn(source, volumeMultiplier);
    }