public void SetActive(bool active, AudioSource audioSource, SpriteRenderer spriteRenderer)
        {
            if (active)
            {
                // pick random clip
                int newClipIndex;
                if (this.audioClips.Length == 1)
                {
                    newClipIndex = 0;
                }
                else
                {
                    newClipIndex = rng.Next(0, this.audioClips.Length - 1);
                    if (newClipIndex >= this.lastClip)
                    {
                        newClipIndex++;
                    }
                }

                // play selected clip
                this.lastClip = newClipIndex;
                audioSource.PlayOneShot(this.audioClips[newClipIndex]);
                Debug.Log("Play sound " + this.audioClips[newClipIndex] + " for " + audioSource.GetComponentInParent <GameCharacterController>().selectedCharacter.character);

                // show sprite
                spriteRenderer.sprite = this.emoji;
            }
            else
            {
                // hide sprite
                spriteRenderer.sprite = null;
            }
        }
Exemple #2
0
    void DisplayEffect()
    {
        Vector3 textLocation = Camera.main.WorldToViewportPoint(audioSource.GetComponentInParent <Transform>().position);

        if (powerUpType != PowerUpType.TimeGoal)
        {
            textLocation.y += 0.2f;
        }
        textLocation = Camera.main.ViewportToScreenPoint(textLocation);

        GameObject prefab = (GameObject)Instantiate(textPrefab, Vector3.zero, Quaternion.identity);

        prefab.transform.SetParent(HUDCanvas.transform, false);
        prefab.transform.position = textLocation;

        Text text = prefab.GetComponent <Text>();

        switch (powerUpType)
        {
        case PowerUpType.TimeGoal:
            text.text  = "+ " + timeAttribute + " s";
            text.color = new Color(250, 0, 216);
            break;

        case PowerUpType.Enemy:
            text.text  = "- " + timeAttribute + " s";
            text.color = Color.red;
            break;

        case PowerUpType.Green:
            text.text  = "+ " + timeAttribute + " s";
            text.color = Color.green;
            break;

        case PowerUpType.Yellow:
            float d = Mathf.Round(timeAttribute * 1000 + RoadManager.distance * distanceAttribute);

            if (d < 1000)
            {
                text.text = "+ " + d + " m";
            }
            else if (d < 10000)
            {
                text.text = "+ " + Mathf.Round(d / 100f) / 10f + " Km";
            }
            else if (d < LevelManager.maxCountableDistance)
            {
                text.text = "+ " + Mathf.Round(d / 1000f) + " Km";
            }

            text.color = Color.yellow;
            break;

        case PowerUpType.Red:
            text.text  = "x " + distanceAttribute;
            text.color = Color.red;
            break;
        }
    }
Exemple #3
0
    void Start()
    {
        sonarPing.spatialize      = false;
        sonarPing.bypassEffects   = true;
        sonarReturn.bypassEffects = true;
        player = GameObject.FindGameObjectWithTag("Player");

        sonarReturn.GetComponentInParent <AudioLowPassFilter>().cutoffFrequency = cutoffFreq;
    }
    static bool ApplyDefaultSpatializationToAudioSource(AudioSource audioSrc, bool force = false)
    {
        if (audioSrc == null)
        {
            return(false);
        }

        var vrcsp = audioSrc.gameObject.GetComponent <VRC.SDKBase.VRC_SpatialAudioSource>();

        // don't make changes if we already have a vrcsp and we aren't forcing
        if (vrcsp != null && !force)
        {
            return(false);
        }

        if (force)
        {
            audioSrc.spatialBlend = 1;
        }

        bool initValues = force;

        // is audio source set to be 2D?
        bool is2D = audioSrc.spatialBlend == 0;

        if (vrcsp == null)
        {
            // no onsp and no vrcsp, so add
            vrcsp = audioSrc.gameObject.AddComponent <VRC.SDKBase.VRC_SpatialAudioSource>();
            if (is2D)
            {
                // this audio source was marked as 2D, leave the vrcsp disabled
                vrcsp.EnableSpatialization = false;
            }
            initValues = true;
        }

        audioSrc.spatialize = vrcsp.EnableSpatialization;
        vrcsp.enabled       = true;

        if (initValues)
        {
            bool isAvatar = audioSrc.GetComponentInParent <VRC.SDKBase.VRC_AvatarDescriptor>();

            vrcsp.Gain = isAvatar ? AudioManagerSettings.AvatarAudioMaxGain : AudioManagerSettings.RoomAudioGain;
            vrcsp.Near = 0;
            vrcsp.Far  = isAvatar ? AudioManagerSettings.AvatarAudioMaxRange : AudioManagerSettings.RoomAudioMaxRange;
            vrcsp.UseAudioSourceVolumeCurve = false;
        }

        return(true);
    }
Exemple #5
0
    private IEnumerator OffScreenIndicator()
    {
        while (true)
        {
            if (_audioSource.isPlaying && !_isPaused && !_enabled)
            {
                EnableIndicator(_audioSource.GetComponentInParent <Transform>());
            }
            else if (_audioSource.isPlaying && !_isPaused && _enabled)
            {
                yield return(null);
            }
            else
            {
                DisableIndicator();
            }

            yield return(null);
        }
    }
Exemple #6
0
    // OnStateEnter is called when a transition starts and the state machine starts to evaluate this state
    override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
    {
        audioSource = audioSource.GetComponentInParent(typeof(AudioSource)) as AudioSource;

        playClip();
    }
Exemple #7
0
 public static void BlendVolume(this AudioSource a, float Volume, float delay)
 {
     a.GetComponentInParent <MonoBehaviour>().StartCoroutine(_BlendVolume(a, Volume, delay));
 }
    static bool ApplyDefaultSpatializationToAudioSource(AudioSource audioSrc, bool force = false)
    {
        if (audioSrc == null)
        {
            return(false);
        }

        var vrcsp = audioSrc.gameObject.GetComponent <VRCSDK2.VRC_SpatialAudioSource>();

        // don't make changes if we already have a vrcsp and we aren't forcing
        if (vrcsp != null && !force)
        {
            return(false);
        }

        if (force)
        {
            audioSrc.spatialBlend = 1;
        }

        bool initValues = force;

        // is audio source set to be 2D?
        bool is2D = audioSrc.spatialBlend == 0;

#if SUPPORT_DEPRECATED_ONSP
        var onsp = audioSrc.GetComponent <ONSPAudioSource>();
        if (onsp != null)
        {
            if (vrcsp == null)
            {
                // copy the values from deprecated component
                vrcsp      = audioSrc.gameObject.AddComponent <VRCSDK2.VRC_SpatialAudioSource>();
                vrcsp.Gain = onsp.Gain;
                vrcsp.Near = onsp.Near;
                vrcsp.Far  = onsp.Far;
                vrcsp.UseAudioSourceVolumeCurve = !onsp.UseInvSqr;
                vrcsp.EnableSpatialization      = onsp.EnableSpatialization;
            }

            // remove deprecated component
            Component.DestroyImmediate(onsp);
        }
#endif
        if (vrcsp == null)
        {
            // no onsp and no vrcsp, so add
            vrcsp = audioSrc.gameObject.AddComponent <VRCSDK2.VRC_SpatialAudioSource>();
            if (is2D)
            {
                // this audio source was marked as 2D, leave the vrcsp disabled
                vrcsp.EnableSpatialization = false;
            }
            initValues = true;
        }

        audioSrc.spatialize = vrcsp.EnableSpatialization;
        vrcsp.enabled       = true;

        if (initValues)
        {
            bool isAvatar = audioSrc.GetComponentInParent <VRCSDK2.VRC_AvatarDescriptor>();

            vrcsp.Gain = isAvatar ? VRCSDK2.AudioManagerSettings.AvatarAudioMaxGain : VRCSDK2.AudioManagerSettings.RoomAudioGain;
            vrcsp.Near = 0;
            vrcsp.Far  = isAvatar ? VRCSDK2.AudioManagerSettings.AvatarAudioMaxRange : VRCSDK2.AudioManagerSettings.RoomAudioMaxRange;
            vrcsp.UseAudioSourceVolumeCurve = false;
        }

        return(true);
    }