Beispiel #1
0
        /// <summary>Generate an impulse event at a location in space,
        /// and broadcast it on the appropriate impulse channel</summary>
        /// <param name="position">Event originates at this position in world space</param>
        /// <param name="velocity">This direction is considered to be "down" for the purposes of the
        /// event signal, and the magnitude of the signal will be scaled according to the
        /// length of this vector</param>
        /// <returns>Returns the created event, so that the caller can modify it dynamically</returns>
        public CinemachineImpulseManager.ImpulseEvent CreateAndReturnEvent(Vector3 position, Vector3 velocity)
        {
            if (m_RawSignal == null || Mathf.Abs(m_TimeEnvelope.Duration) < UnityVectorExtensions.Epsilon)
            {
                return(null);
            }

            CinemachineImpulseManager.ImpulseEvent e
                         = CinemachineImpulseManager.Instance.NewImpulseEvent();
            e.m_Envelope = m_TimeEnvelope;

            // Scale the time-envelope decay as the root of the amplitude scale
            e.m_Envelope = m_TimeEnvelope;
            if (m_TimeEnvelope.m_ScaleWithImpact)
            {
                e.m_Envelope.m_DecayTime *= Mathf.Sqrt(velocity.magnitude);
            }

            e.m_SignalSource        = new SignalSource(this, velocity);
            e.m_Position            = position;
            e.m_Radius              = m_ImpactRadius;
            e.m_Channel             = m_ImpulseChannel;
            e.m_DirectionMode       = m_DirectionMode;
            e.m_DissipationMode     = m_DissipationMode;
            e.m_DissipationDistance = m_DissipationDistance;
            e.m_PropagationSpeed    = m_PropagationSpeed;
            CinemachineImpulseManager.Instance.AddImpulseEvent(e);

            return(e);
        }
Beispiel #2
0
        /// <summary>Generate an impulse event at a location in space,
        /// and broadcast it on the appropriate impulse channel</summary>
        /// <param name="position">Event originates at this position in world space</param>
        /// <param name="velocity">This direction is considered to be "down" for the purposes of the
        /// event signal, and the magnitude of the signal will be scaled according to the
        /// length of this vector</param>
        public CinemachineImpulseManager.ImpulseEvent CreateAndReturnEvent(
            Vector3 position, Vector3 velocity)
        {
            // Legacy mode
            if (m_ImpulseType == ImpulseTypes.Legacy)
            {
                return(LegacyCreateAndReturnEvent(position, velocity));
            }

            const float kBigNumber = 9999999.0f;

            if ((m_ImpulseShape == ImpulseShapes.Custom && m_CustomImpulseShape == null) ||
                Mathf.Abs(m_DissipationDistance) < UnityVectorExtensions.Epsilon ||
                Mathf.Abs(m_ImpulseDuration) < UnityVectorExtensions.Epsilon)
            {
                return(null);
            }

            CinemachineImpulseManager.ImpulseEvent e
                         = CinemachineImpulseManager.Instance.NewImpulseEvent();
            e.m_Envelope = new CinemachineImpulseManager.EnvelopeDefinition
            {
                m_SustainTime = m_ImpulseDuration
            };

            e.m_SignalSource        = new SignalSource(this, velocity);
            e.m_Position            = position;
            e.m_Radius              = m_ImpulseType == ImpulseTypes.Uniform ? kBigNumber : 0;
            e.m_Channel             = m_ImpulseChannel;
            e.m_DirectionMode       = CinemachineImpulseManager.ImpulseEvent.DirectionMode.Fixed;
            e.m_DissipationDistance = m_ImpulseType == ImpulseTypes.Uniform ? 0 : m_DissipationDistance;
            e.m_PropagationSpeed    = m_ImpulseType == ImpulseTypes.Propagating ? m_PropagationSpeed : kBigNumber;
            e.m_CustomDissipation   = m_DissipationRate;

            CinemachineImpulseManager.Instance.AddImpulseEvent(e);
            return(e);
        }