123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System;
- using UnityEngine;
- public class ONSPAudioSource : MonoBehaviour
- {
- public bool EnableSpatialization
- {
- get
- {
- return this.enableSpatialization;
- }
- set
- {
- this.enableSpatialization = value;
- }
- }
- public float Gain
- {
- get
- {
- return this.gain;
- }
- set
- {
- this.gain = Mathf.Clamp(value, 0f, 24f);
- }
- }
- public bool UseInvSqr
- {
- get
- {
- return this.useInvSqr;
- }
- set
- {
- this.useInvSqr = value;
- }
- }
- public float Near
- {
- get
- {
- return this.near;
- }
- set
- {
- this.near = Mathf.Clamp(value, 0f, 1000000f);
- }
- }
- public float Far
- {
- get
- {
- return this.far;
- }
- set
- {
- this.far = Mathf.Clamp(value, 0f, 1000000f);
- }
- }
- public bool DisableRfl
- {
- get
- {
- return this.disableRfl;
- }
- set
- {
- this.disableRfl = value;
- }
- }
- private void Awake()
- {
- AudioSource component = base.GetComponent<AudioSource>();
- this.SetParameters(ref component);
- }
- private void Start()
- {
- }
- private void Update()
- {
- AudioSource component = base.GetComponent<AudioSource>();
- this.SetParameters(ref component);
- }
- public void SetParameters(ref AudioSource source)
- {
- if (!Application.isPlaying || AudioListener.pause || !source.isPlaying || !source.isActiveAndEnabled)
- {
- source.spatialize = false;
- return;
- }
- source.spatialize = this.enableSpatialization;
- source.SetSpatializerFloat(0, this.gain);
- if (this.useInvSqr)
- {
- source.SetSpatializerFloat(1, 1f);
- }
- else
- {
- source.SetSpatializerFloat(1, 0f);
- }
- source.SetSpatializerFloat(2, this.near);
- source.SetSpatializerFloat(3, this.far);
- if (this.disableRfl)
- {
- source.SetSpatializerFloat(4, 1f);
- }
- else
- {
- source.SetSpatializerFloat(4, 0f);
- }
- }
- [SerializeField]
- private bool enableSpatialization = true;
- [SerializeField]
- private float gain;
- [SerializeField]
- private bool useInvSqr;
- [SerializeField]
- private float near = 1f;
- [SerializeField]
- private float far = 10f;
- [SerializeField]
- private bool disableRfl;
- }
|