您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
44 行
1.5 KiB
44 行
1.5 KiB
#if VFX_OUTPUTEVENT_CINEMACHINE_2_6_0_OR_NEWER
|
|
using Cinemachine;
|
|
|
|
namespace UnityEngine.VFX.Utility
|
|
{
|
|
[ExecuteAlways]
|
|
[RequireComponent(typeof(VisualEffect))]
|
|
class VFXOutputEventCinemachineCameraShake : VFXOutputEventAbstractHandler
|
|
{
|
|
public override bool canExecuteInEditor => true;
|
|
|
|
public enum Space
|
|
{
|
|
Local,
|
|
World
|
|
}
|
|
|
|
static readonly int k_Position = Shader.PropertyToID("position");
|
|
static readonly int k_Velocity = Shader.PropertyToID("velocity");
|
|
|
|
[Tooltip("The Cinemachine Impulse Source to use in order to send impulses.")]
|
|
public CinemachineImpulseSource cinemachineImpulseSource;
|
|
[Tooltip("The space in which the position and velocity attributes values are defined (local to the VFX, or world).")]
|
|
public Space attributeSpace;
|
|
|
|
public override void OnVFXOutputEvent(VFXEventAttribute eventAttribute)
|
|
{
|
|
if (cinemachineImpulseSource != null)
|
|
{
|
|
Vector3 pos = eventAttribute.GetVector3(k_Position);
|
|
Vector3 vel = eventAttribute.GetVector3(k_Velocity);
|
|
|
|
if (attributeSpace == Space.Local)
|
|
{
|
|
pos = transform.localToWorldMatrix.MultiplyPoint(pos);
|
|
vel = transform.localToWorldMatrix.MultiplyVector(vel);
|
|
}
|
|
|
|
cinemachineImpulseSource.GenerateImpulseAt(pos, vel);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
#endif
|