Untitled diff

Created Diff never expires
14 removals
Lines
Total
Removed
Words
Total
Removed
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
140 lines
51 additions
Lines
Total
Added
Words
Total
Added
To continue using this feature, upgrade to
Diffchecker logo
Diffchecker Pro
177 lines
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
// (c) Copyright HutongGames, LLC 2010-2015. All rights reserved.


using UnityEngine;
using UnityEngine;


namespace HutongGames.PlayMaker.Actions
namespace HutongGames.PlayMaker.Actions
{
{
[ActionCategory(ActionCategory.Animator)]
[ActionCategory("Animator")]
[Tooltip("Sets the position, rotation and weights of an IK goal. A GameObject can be set to control the position and rotation, or it can be manually expressed.")]
[Tooltip("Sets the position, rotation and weights of an IK goal. A GameObject can be set to control the position and rotation, or it can be manually expressed.")]
[HelpUrl("https://hutonggames.fogbugz.com/default.asp?W1067")]
public class SetAnimatorIKGoal: FsmStateAction
public class SetAnimatorIKGoal: FsmStateAction
{
{
[RequiredField]
[RequiredField]
[CheckForComponent(typeof(Animator))]
[CheckForComponent(typeof(Animator))]
[Tooltip("The target.")]
[CheckForComponent(typeof(PlayMakerAnimatorIKProxy))]
[Tooltip("The target. An Animator component and a PlayMakerAnimatorIKProxy component are required")]
public FsmOwnerDefault gameObject;
public FsmOwnerDefault gameObject;
[Tooltip("The IK goal")]
[Tooltip("The IK goal")]
public AvatarIKGoal iKGoal;
public AvatarIKGoal iKGoal;
[Tooltip("The gameObject target of the ik goal")]
[Tooltip("The gameObject target of the ik goal")]
public FsmGameObject goal;
public FsmGameObject goal;
[Tooltip("The position of the ik goal. If Goal GameObject set, position is used as an offset from Goal")]
[Tooltip("The position of the ik goal. If Goal GameObject set, position is used as an offset from Goal")]
public FsmVector3 position;
public FsmVector3 position;
[Tooltip("The rotation of the ik goal.If Goal GameObject set, rotation is used as an offset from Goal")]
[Tooltip("The rotation of the ik goal.If Goal GameObject set, rotation is used as an offset from Goal")]
public FsmQuaternion rotation;
public FsmQuaternion rotation;
[HasFloatSlider(0f,1f)]
[HasFloatSlider(0f,1f)]
[Tooltip("The translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal)")]
[Tooltip("The translative weight of an IK goal (0 = at the original animation before IK, 1 = at the goal)")]
public FsmFloat positionWeight;
public FsmFloat positionWeight;
[HasFloatSlider(0f,1f)]
[HasFloatSlider(0f,1f)]
[Tooltip("Sets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal)")]
[Tooltip("Sets the rotational weight of an IK goal (0 = rotation before IK, 1 = rotation at the IK goal)")]
public FsmFloat rotationWeight;
public FsmFloat rotationWeight;
[Tooltip("Repeat every frame. Useful when changing over time.")]
[Tooltip("Repeat every frame. Useful when changing over time.")]
public bool everyFrame;
public bool everyFrame;

private PlayMakerAnimatorIKProxy _animatorProxy;
private Animator _animator;
private Animator _animator;
private Transform _transform;
private Transform _transform;
public override void Reset()
public override void Reset()
{
{
gameObject = null;
gameObject = null;
goal = null;
goal = null;
position = new FsmVector3() {UseVariable=true};
position = new FsmVector3() {UseVariable=true};
rotation = new FsmQuaternion() {UseVariable=true};
rotation = new FsmQuaternion() {UseVariable=true};
positionWeight = 1f;
positionWeight = 1f;
rotationWeight = 1f;
rotationWeight = 1f;
everyFrame = false;
everyFrame = false;
}
}


public override void OnEnter()
public override void OnEnter()
{
{
// get the animator component
// get the animator component
var go = Fsm.GetOwnerDefaultTarget(gameObject);
var go = Fsm.GetOwnerDefaultTarget(gameObject);
if (go==null)
if (go==null)
{
{
Finish();
Finish();
return;
return;
}
}
_animator = go.GetComponent<Animator>();
_animator = go.GetComponent<Animator>();
if (_animator==null)
if (_animator==null)
{
{
Finish();
Finish();
return;
return;
}
}

_animatorProxy = go.GetComponent<PlayMakerAnimatorIKProxy>();
if (_animatorProxy!=null)
{
_animatorProxy.OnAnimatorIKEvent += OnAnimatorIKEvent;
}else{
Debug.LogWarning("This action requires a PlayMakerAnimatorIKProxy. It may not perform properly if not present.");
}
GameObject _goal = goal.Value;
GameObject _goal = goal.Value;
if (_goal!=null)
if (_goal!=null)
{
{
_transform = _goal.transform;
_transform = _goal.transform;
}
}
DoSetIKGoal();


if (!everyFrame)
{
Finish();
}
}
}
public override void DoAnimatorIK (int layerIndex)
public void OnAnimatorIKEvent(int layer)
{
{
DoSetIKGoal();
if (_animatorProxy!=null)
{
DoSetIKGoal();

if (!everyFrame)
{
_animatorProxy.OnAnimatorIKEvent -= OnAnimatorIKEvent;
Finish();
}
}
}
}

/* not working
public override void OnUpdate()
{
if (_animatorProxy==null)
{
DoSetIKGoal();
}
}
*/
void DoSetIKGoal()
void DoSetIKGoal()
{
{
if (_animator==null)
if (_animator==null)
{
{
return;
return;
}
}
if (_transform!=null)
if (_transform!=null)
{
{
if (position.IsNone)
if (position.IsNone)
{
{
_animator.SetIKPosition(iKGoal,_transform.position);
_animator.SetIKPosition(iKGoal,_transform.position);
}else{
}else{
_animator.SetIKPosition(iKGoal,_transform.position+position.Value);
_animator.SetIKPosition(iKGoal,_transform.position+position.Value);
}
}
if (rotation.IsNone)
if (rotation.IsNone)
{
{
_animator.SetIKRotation(iKGoal,_transform.rotation);
_animator.SetIKRotation(iKGoal,_transform.rotation);
}else{
}else{
_animator.SetIKRotation(iKGoal,_transform.rotation*rotation.Value);
_animator.SetIKRotation(iKGoal,_transform.rotation*rotation.Value);
}
}
}else{
}else{
if (!position.IsNone)
if (!position.IsNone)
{
{
_animator.SetIKPosition(iKGoal,position.Value);
_animator.SetIKPosition(iKGoal,position.Value);
}
}
if (!rotation.IsNone)
if (!rotation.IsNone)
{
{
_animator.SetIKRotation(iKGoal,rotation.Value);
_animator.SetIKRotation(iKGoal,rotation.Value);
}
}
}
}
if (!positionWeight.IsNone)
if (!positionWeight.IsNone)
{
{
_animator.SetIKPositionWeight(iKGoal,positionWeight.Value);
_animator.SetIKPositionWeight(iKGoal,positionWeight.Value);
}
}
if (!rotationWeight.IsNone)
if (!rotationWeight.IsNone)
{
{
_animator.SetIKRotationWeight(iKGoal,rotationWeight.Value);
_animator.SetIKRotationWeight(iKGoal,rotationWeight.Value);
}
}
}
}
public override void OnExit()
{
if (_animatorProxy!=null)
{
_animatorProxy.OnAnimatorIKEvent -= OnAnimatorIKEvent;
}
}
}
}
}
}