|
|
|
|
|
|
|
|
|
|
namespace GameplayIngredients.Actions |
|
|
|
{ |
|
|
|
[RequireComponent(typeof(CinemachineImpulseSource))] |
|
|
|
SelfTransform, |
|
|
|
RemoteTransform, |
|
|
|
Self, |
|
|
|
ImpulseSource, |
|
|
|
OtherTransform, |
|
|
|
[NonNullCheck] |
|
|
|
public CinemachineImpulseSource impulseSource; |
|
|
|
[Header("Position")] |
|
|
|
public ImpulseLocation impulseLocation = ImpulseLocation.SelfTransform; |
|
|
|
public ImpulseLocation impulseLocation = ImpulseLocation.Self; |
|
|
|
[Tooltip("The Remote transform to use to generate impulses")] |
|
|
|
public Transform remoteImpulseLocation; |
|
|
|
bool useRemoteTransform => impulseLocation == ImpulseLocation.RemoteTransform; |
|
|
|
[Tooltip("The alternate transform to use to generate impulses")] |
|
|
|
public Transform otherTransform; |
|
|
|
bool useRemoteTransform => impulseLocation == ImpulseLocation.OtherTransform; |
|
|
|
public bool LocalSpace = true; |
|
|
|
public bool localSpace = true; |
|
|
|
[Tooltip("The Impulse Vector to Use")] |
|
|
|
public Vector3 baseImpulse = Vector3.up; |
|
|
|
[Tooltip("Whether to apply randomness as well")] |
|
|
|
|
|
|
[ShowIf(EConditionOperator.And, "randomImpulse", "normalize")] |
|
|
|
public Vector2 postNormalizeRemap = Vector2.one; |
|
|
|
|
|
|
|
|
|
|
|
CinemachineImpulseSource m_ImpulseSource; |
|
|
|
|
|
|
|
|
|
|
|
if(m_ImpulseSource == null) |
|
|
|
if(impulseSource == null) |
|
|
|
m_ImpulseSource = GetComponent<CinemachineImpulseSource>(); |
|
|
|
if (m_ImpulseSource == null) |
|
|
|
m_ImpulseSource = gameObject.AddComponent<CinemachineImpulseSource>(); |
|
|
|
Debug.LogWarning($"CinemachineCameraShakeAction : No Impulse source was provided"); |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
Vector3 impulse = baseImpulse; |
|
|
|
|
|
|
switch (impulseLocation) |
|
|
|
{ |
|
|
|
default: |
|
|
|
case ImpulseLocation.SelfTransform: |
|
|
|
if (LocalSpace) |
|
|
|
case ImpulseLocation.Self: |
|
|
|
if (localSpace) |
|
|
|
m_ImpulseSource.GenerateImpulse(impulse); |
|
|
|
impulseSource.GenerateImpulseAt(transform.position, impulse); |
|
|
|
case ImpulseLocation.RemoteTransform: |
|
|
|
if(remoteImpulseLocation != null) |
|
|
|
case ImpulseLocation.ImpulseSource: |
|
|
|
if (localSpace) |
|
|
|
impulse = impulseSource.transform.localToWorldMatrix.MultiplyVector(impulse); |
|
|
|
|
|
|
|
impulseSource.GenerateImpulseAt(impulseSource.transform.position, impulse); |
|
|
|
|
|
|
|
break; |
|
|
|
case ImpulseLocation.OtherTransform: |
|
|
|
if(otherTransform != null) |
|
|
|
if (LocalSpace) |
|
|
|
impulse = remoteImpulseLocation.localToWorldMatrix.MultiplyVector(impulse); |
|
|
|
if (localSpace) |
|
|
|
impulse = otherTransform.localToWorldMatrix.MultiplyVector(impulse); |
|
|
|
m_ImpulseSource.GenerateImpulseAt(remoteImpulseLocation.position, impulse); |
|
|
|
impulseSource.GenerateImpulseAt(otherTransform.position, impulse); |
|
|
|
if (LocalSpace) |
|
|
|
if (localSpace) |
|
|
|
m_ImpulseSource.GenerateImpulse(impulse); |
|
|
|
impulseSource.GenerateImpulse(impulse); |
|
|
|
if (LocalSpace) |
|
|
|
if (localSpace) |
|
|
|
m_ImpulseSource.GenerateImpulseAt(instigator.transform.position, impulse); |
|
|
|
impulseSource.GenerateImpulseAt(instigator.transform.position, impulse); |
|
|
|
if (LocalSpace) |
|
|
|
if (localSpace) |
|
|
|
m_ImpulseSource.GenerateImpulse(impulse); |
|
|
|
impulseSource.GenerateImpulse(impulse); |
|
|
|
} |
|
|
|
break; |
|
|
|
} |
|
|
|