playMaker

Author Topic: LayerMaskTriggerEvent  (Read 1475 times)

giyomu

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 108
    • View Profile
    • blog
LayerMaskTriggerEvent
« on: July 05, 2011, 10:28:19 PM »
me again  ;D

similar to trigger event , but you can just filter it from a layer index.

Code: [Select]
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);
}
}
}
}