70 lines
1.4 KiB
C#
70 lines
1.4 KiB
C#
// (c) Copyright HutongGames, LLC 2010-2016. All rights reserved.
|
|
|
|
using System;
|
|
using UnityEngine;
|
|
|
|
namespace HutongGames.PlayMaker.Actions
|
|
{
|
|
[ActionCategory(ActionCategory.Physics2D)]
|
|
[Tooltip("Tests if a Game Object's Rigid Body 2D is Kinematic.")]
|
|
public class IsKinematic2d : ComponentAction<Rigidbody2D>
|
|
{
|
|
[RequiredField]
|
|
[CheckForComponent(typeof(Rigidbody2D))]
|
|
[Tooltip("the GameObject with a Rigidbody2D attached")]
|
|
public FsmOwnerDefault gameObject;
|
|
|
|
[Tooltip("Event Sent if Kinematic")]
|
|
public FsmEvent trueEvent;
|
|
|
|
[Tooltip("Event sent if not Kinematic")]
|
|
public FsmEvent falseEvent;
|
|
|
|
[UIHint(UIHint.Variable)]
|
|
[Tooltip("Store the Kinematic state")]
|
|
public FsmBool store;
|
|
|
|
[Tooltip("Repeat every frame")]
|
|
public bool everyFrame;
|
|
|
|
public override void Reset()
|
|
{
|
|
gameObject = null;
|
|
trueEvent = null;
|
|
falseEvent = null;
|
|
store = null;
|
|
everyFrame = false;
|
|
}
|
|
|
|
public override void OnEnter()
|
|
{
|
|
DoIsKinematic();
|
|
|
|
if (!everyFrame)
|
|
{
|
|
Finish();
|
|
}
|
|
}
|
|
|
|
public override void OnUpdate()
|
|
{
|
|
DoIsKinematic();
|
|
}
|
|
|
|
void DoIsKinematic()
|
|
{
|
|
var go = Fsm.GetOwnerDefaultTarget(gameObject);
|
|
if (!UpdateCache(go))
|
|
{
|
|
return;
|
|
}
|
|
|
|
var isKinematic = rigidbody2d.isKinematic;
|
|
store.Value = isKinematic;
|
|
|
|
Fsm.Event(isKinematic ? trueEvent : falseEvent);
|
|
}
|
|
}
|
|
}
|
|
|