using UnityEngine;
namespace Cinemachine
{
///
/// An event-driven class that broadcasts an impulse signal to listeners.
///
/// This is the base class for custom impulse sources. It contains an impulse
/// definition, where the characteristics of the impulse signal are defined.
///
/// API methods are provided for actually broadcasting the impulse. Call these
/// methods from your custom code, or hook them up to game events in the Editor.
///
///
[DocumentationSorting(DocumentationSortingAttribute.Level.UserRef)]
[SaveDuringPlay]
[HelpURL(Documentation.BaseURL + "manual/CinemachineImpulseSourceOverview.html")]
public class CinemachineImpulseSource : MonoBehaviour
{
///
/// This defines the complete impulse signal that will be broadcast.
///
[CinemachineImpulseDefinitionProperty]
public CinemachineImpulseDefinition m_ImpulseDefinition = new CinemachineImpulseDefinition();
private void OnValidate()
{
m_ImpulseDefinition.OnValidate();
}
/// Broadcast the Impulse Signal onto the appropriate channels,
/// using a custom position and impact velocity
/// The world-space position from which the impulse will emanate
/// The impact magnitude and direction
public void GenerateImpulseAt(Vector3 position, Vector3 velocity)
{
if (m_ImpulseDefinition != null)
m_ImpulseDefinition.CreateEvent(position, velocity);
}
/// Broadcast the Impulse Signal onto the appropriate channels, using
/// a custom impact velocity, and this transfom's position.
/// The impact magnitude and direction
public void GenerateImpulse(Vector3 velocity)
{
GenerateImpulseAt(transform.position, velocity);
}
/// Broadcast the Impulse Signal onto the appropriate channels, using
/// a custom impact force, with the standard direction, and this transfom's position.
/// The impact magnitude. 1 is normal
public void GenerateImpulse(float force)
{
GenerateImpulseAt(transform.position, new Vector3(0, -force, 0));
}
/// Broadcast the Impulse Signal onto the appropriate channels,
/// with default velocity = (0, -1, 0), and a default position which is
/// this transform's location.
public void GenerateImpulse()
{
GenerateImpulse(Vector3.down);
}
}
}