Exemple #1
0
    private void voiceplay(float hearDistance, int setupData, byte[] data)
    {
        Camera main = Camera.main;

        if ((main != null) && (hearDistance > 0f))
        {
            USpeaker uspeaker = this.uspeaker;
            if (uspeaker == null)
            {
                Debug.LogWarning("voiceplayback:" + base.gameObject + " didn't have a USpeaker!?");
            }
            if (!uspeaker.HasSettings())
            {
                uspeaker.InitializeSettings(setupData);
            }
            if (data == null)
            {
                Debug.LogWarning("voiceplayback: data was null!");
            }
            float num  = Vector3.Distance(main.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0001f)), base.eyesOrigin);
            float num2 = Mathf.Clamp01(1f - (num / hearDistance));
            uspeaker.SpeakerVolume = num2;
            uspeaker.ReceiveAudio(data);
            AudioSource audio = uspeaker.audio;
            if (audio != null)
            {
                audio.rolloffMode = AudioRolloffMode.Linear;
                audio.maxDistance = hearDistance;
                audio.minDistance = 1f;
            }
        }
    }
Exemple #2
0
    private void voiceplay(float hearDistance, int setupData, byte[] data)
    {
        Camera camera = Camera.main;

        if (!camera)
        {
            return;
        }
        if (hearDistance <= 0f)
        {
            return;
        }
        USpeaker uSpeaker = this.uspeaker;

        if (!uSpeaker)
        {
            Debug.LogWarning(string.Concat("voiceplayback:", base.gameObject, " didn't have a USpeaker!?"));
        }
        if (!uSpeaker.HasSettings())
        {
            uSpeaker.InitializeSettings(setupData);
        }
        if (data == null)
        {
            Debug.LogWarning("voiceplayback: data was null!");
        }
        Vector3 worldPoint = camera.ViewportToWorldPoint(new Vector3(0.5f, 0.5f, 0.0001f));
        float   single     = Vector3.Distance(worldPoint, base.eyesOrigin);
        float   single1    = Mathf.Clamp01(1f - single / hearDistance);

        uSpeaker.SpeakerVolume = single1;
        uSpeaker.ReceiveAudio(data);
        AudioSource audioSource = uSpeaker.audio;

        if (audioSource)
        {
            audioSource.rolloffMode = AudioRolloffMode.Linear;
            audioSource.maxDistance = hearDistance;
            audioSource.minDistance = 1f;
        }
    }