82 lines
1.4 KiB
C#
82 lines
1.4 KiB
C#
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
|
|
|
|
using UnityEngine;
|
|
|
|
namespace HutongGames.PlayMaker.Actions
|
|
{
|
|
[ActionCategory(ActionCategory.Animator)]
|
|
[Tooltip("Sets the layer's current weight")]
|
|
public class SetAnimatorLayerWeight: FsmStateAction
|
|
{
|
|
[RequiredField]
|
|
[CheckForComponent(typeof(Animator))]
|
|
[Tooltip("The Target. An Animator component is required")]
|
|
public FsmOwnerDefault gameObject;
|
|
|
|
[RequiredField]
|
|
[Tooltip("The layer's index")]
|
|
public FsmInt layerIndex;
|
|
|
|
[RequiredField]
|
|
[Tooltip("Sets the layer's current weight")]
|
|
public FsmFloat layerWeight;
|
|
|
|
[Tooltip("Repeat every frame. Useful for changing over time.")]
|
|
public bool everyFrame;
|
|
|
|
private Animator _animator;
|
|
|
|
public override void Reset()
|
|
{
|
|
gameObject = null;
|
|
layerIndex = null;
|
|
layerWeight= null;
|
|
everyFrame = false;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
// get the animator component
|
|
var go = Fsm.GetOwnerDefaultTarget(gameObject);
|
|
|
|
if (go==null)
|
|
{
|
|
Finish();
|
|
return;
|
|
}
|
|
|
|
_animator = go.GetComponent<Animator>();
|
|
|
|
if (_animator==null)
|
|
{
|
|
Finish();
|
|
return;
|
|
}
|
|
|
|
DoLayerWeight();
|
|
|
|
if (!everyFrame)
|
|
{
|
|
Finish();
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
DoLayerWeight();
|
|
}
|
|
|
|
|
|
void DoLayerWeight()
|
|
{
|
|
if (_animator==null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
_animator.SetLayerWeight(layerIndex.Value,layerWeight.Value);
|
|
|
|
}
|
|
|
|
}
|
|
} |