Playmaker Forum
PlayMaker Updates & Downloads => Share New Actions => Topic started by: giyomu on July 06, 2011, 01:28:19 AM
-
me again ;D
similar to trigger event , but you can just filter it from a layer index.
using UnityEngine;
using HutongGames.PlayMaker;
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Send a trigger event based on layer mask of collider object")]
public class LayerMaskTriggerEvent : FsmStateAction
{
[UIHint(UIHint.Variable)]
[Tooltip("either use GetLayer action or GetLayerIndexFromName to feed this variable")]
public FsmInt layerIndex;
public TriggerType trigger;
[UIHint(UIHint.Variable)]
public FsmGameObject storeCollider;
[Tooltip("event to send if layer match with the collider layer value")]
public FsmEvent sendEvent;
public override void Reset ()
{
trigger = TriggerType.OnTriggerEnter;
layerIndex = null;
storeCollider = null;
sendEvent = null;
}
void StoreCollisionInfo(Collider collisionInfo)
{
storeCollider.Value = collisionInfo.gameObject;
}
public override void OnEnter ()
{
if(layerIndex == null)
Finish();
}
public override void DoTriggerEnter (Collider other)
{
if (trigger == TriggerType.OnTriggerEnter)
{
if (other.gameObject.layer == layerIndex.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
public override void DoTriggerStay (Collider other)
{
if (trigger == TriggerType.OnTriggerStay)
{
if (other.gameObject.layer == layerIndex.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
public override void DoTriggerExit (Collider other)
{
if (trigger == TriggerType.OnTriggerExit)
{
if (other.gameObject.layer == layerIndex.Value)
{
StoreCollisionInfo(other);
Fsm.Event(sendEvent);
}
}
}
}