79 lines
1.7 KiB
C#
79 lines
1.7 KiB
C#
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
|
|
|
|
using UnityEngine;
|
|
|
|
namespace HutongGames.PlayMaker.Actions
|
|
{
|
|
[ActionCategory(ActionCategory.Quaternion)]
|
|
[Tooltip("Spherically interpolates between from and to by t.")]
|
|
public class QuaternionSlerp : QuaternionBaseAction
|
|
{
|
|
|
|
[RequiredField]
|
|
[Tooltip("From Quaternion.")]
|
|
public FsmQuaternion fromQuaternion;
|
|
|
|
[RequiredField]
|
|
[Tooltip("To Quaternion.")]
|
|
public FsmQuaternion toQuaternion;
|
|
|
|
[RequiredField]
|
|
[Tooltip("Interpolate between fromQuaternion and toQuaternion by this amount. Value is clamped to 0-1 range. 0 = fromQuaternion; 1 = toQuaternion; 0.5 = half way between.")]
|
|
[HasFloatSlider(0f, 1f)]
|
|
public FsmFloat amount;
|
|
|
|
[RequiredField]
|
|
[UIHint(UIHint.Variable)]
|
|
[Tooltip("Store the result in this quaternion variable.")]
|
|
public FsmQuaternion storeResult;
|
|
|
|
public override void Reset()
|
|
{
|
|
fromQuaternion = new FsmQuaternion { UseVariable = true };
|
|
toQuaternion = new FsmQuaternion { UseVariable = true };
|
|
amount = 0.1f;
|
|
storeResult = null;
|
|
everyFrame = true;
|
|
everyFrameOption = everyFrameOptions.Update;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
DoQuatSlerp();
|
|
|
|
if (!everyFrame)
|
|
{
|
|
Finish();
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
if (everyFrameOption == everyFrameOptions.Update )
|
|
{
|
|
DoQuatSlerp();
|
|
}
|
|
}
|
|
public override void OnLateUpdate()
|
|
{
|
|
if (everyFrameOption == everyFrameOptions.LateUpdate )
|
|
{
|
|
DoQuatSlerp();
|
|
}
|
|
}
|
|
public override void OnFixedUpdate()
|
|
{
|
|
if (everyFrameOption == everyFrameOptions.FixedUpdate )
|
|
{
|
|
DoQuatSlerp();
|
|
}
|
|
}
|
|
|
|
void DoQuatSlerp()
|
|
{
|
|
storeResult.Value = Quaternion.Slerp(fromQuaternion.Value, toQuaternion.Value, amount.Value);
|
|
}
|
|
}
|
|
}
|
|
|