Пример #1
0
        /// <summary>
        /// Plays a feedback at a position and a rotation in world space
        /// </summary>
        /// <param name="position">The target feedback position</param>
        /// <param name="rotation">The target feedback rotation</param>
        /// <param name="owner">The target owner of the feedback</param>
        public void Play(Vector3 position, Quaternion rotation, Transform owner = null)
        {
            Transform parent = null;

            if (owner != null && _parentToOwner)
            {
                parent = owner;
            }

            //Instantiates a particle system
            if (_particleSystem != null)
            {
                if (_followOwnerRotation && owner != null)
                {
                    rotation *= owner.rotation;
                }
                ParticleSystem vfxInstance = Instantiate(_particleSystem, position, rotation, parent);
                vfxInstance.transform.localScale *= _scaleMultiplier;
            }

            //Instantiates a one shot audio source
            if (_soundEffect != null)
            {
                FeedbackAudioSource sfxInstance = Instantiate(_source, position, Quaternion.identity, parent);
                sfxInstance.GetSource();
                sfxInstance.Source.clip         = _soundEffect;
                sfxInstance.Source.pitch        = Random.Range(_randomPitchRange.x, _randomPitchRange.y);
                sfxInstance.Source.volume       = _volume;
                sfxInstance.Source.spatialBlend = _spatialBlend;
                sfxInstance.Play(_soundEffect.length);
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes the feedback audio source object
        /// </summary>
        internal static void InitAudioSource()
        {
            if (_sourceInstance != null)
            {
                return;
            }

            GameObject          sourceGO = new GameObject("One Shot Audio Source");
            FeedbackAudioSource source   = sourceGO.gameObject.AddComponent <FeedbackAudioSource>();

            source.Init();
            DontDestroyOnLoad(sourceGO);
            _sourceInstance = source;
        }