playMaker

Author Topic: Trigger Broadcast Event  (Read 8202 times)

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Trigger Broadcast Event
« on: May 02, 2011, 07:28:43 PM »
Supposing you want to broadcast an event after a specific trigger event, by default you always have to drive the execution flow to another state (using Trigger Event), and in that state you execute the 'broadcast event' action. In some circumstances this can be really bad since some messages just have to be sent/broadcasted as quickly as possible and there's apparently some minor overhead (delay) in switching states, which can make all the difference between things working as you want or not. I've created 'Trigger Broadcast Event' exactly to fill this gap - although I recognize that a proper SubFSM structure (a mini-FSM which would be executed in the same update and return to the calling point once finished) would be perfect for such scenarios and instantly render such actions obsolete.

Yet the clock won't stop ticking, so, meanwhile.. enjoy :)
--
Breno "MaDDoX" Azevedo
@brenoazevedo

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Trigger Broadcast Event
« Reply #1 on: May 03, 2011, 01:19:22 AM »
Hi,

 Yes, subFsm, or mini fsm standing on its own would be really handy sometimes, not only in that case but also for reusable behaviors etc etc.

 Bye,

 Jean

tobbeo

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 186
Re: Trigger Broadcast Event
« Reply #2 on: May 04, 2011, 05:38:17 PM »
Hi,

 Yes, subFsm, or mini fsm standing on its own would be really handy sometimes, not only in that case but also for reusable behaviors etc etc.

 Bye,

 Jean

Fully agree, an subFsm that could be used as always looking for a sent variable from another Fsm. I've needed that on lots of occasions and I don't really like the workarounds I have. They work, but way too much unnecessary work that could be avoided.

Thanks again for the custom action MaddoX, you rock.

MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Trigger Broadcast Event
« Reply #3 on: May 04, 2011, 10:52:31 PM »
Thanks to you for the kind words Tobbeo :)

We're actually on a roll with new actions here at the studio, I barely have the time to post them hehe. Curiously we agree that most of them will be deprecated once the new system for global variables and nested/subFSMs kick in, yet it's a great exercise on action creation and it's allowing us to be fully productive right away. That's the kind of flexibility that any user loves in a tool, and why I say - Alex, you rock! ^_^
--
Breno "MaDDoX" Azevedo
@brenoazevedo

Alex Chouls

  • Administrator
  • Hero Member
  • *****
  • Posts: 3987
  • Official Playmaker Support
    • LinkedIn
Re: Trigger Broadcast Event
« Reply #4 on: May 08, 2011, 04:01:17 AM »
No you guys rock! Love to see the community sharing actions and helping each other out this much - I'm just trying to keep up my end of the deal ;)
« Last Edit: May 08, 2011, 04:05:25 AM by alexchouls »

lion-gv

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Trigger Broadcast Event
« Reply #5 on: November 06, 2011, 06:29:36 AM »
This is exactly what I need, but where is the code?

lion-gv

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Trigger Broadcast Event
« Reply #6 on: November 06, 2011, 08:44:38 AM »
Ok, I modified the Trigger Event with some code from the new Send Event action. It's dirty but it does the trick. Require you to set the collider to a variable and then to reuse that variable as the target.

Code: [Select]
// (c) Copyright HutongGames, LLC 2010-2011. All rights reserved.
// Modified by Studio Interrupt

using UnityEngine;

namespace HutongGames.PlayMaker.Actions
{
[ActionCategory(ActionCategory.Physics)]
[Tooltip("Detect collisions with a Tagged trigger.\nNOTE: TRIGGER ENTER, TRIGGER STAY, and TRIGGER EXIT are sent automatically when objects collide with ANY trigger. Use this action to send custom events when colliding with a particular Tag.")]
public class TriggerEventToCollider : FsmStateAction
{
public TriggerType trigger;
[UIHint(UIHint.Tag)]
public FsmString collideTag;
public FsmEvent sendEvent;

[UIHint(UIHint.Variable)]
public FsmGameObject storeCollider;
//public FsmBool sendToCollider;
public FsmEventTarget eventTarget;

public override void Reset()
{
trigger = TriggerType.OnTriggerEnter;
collideTag = "Untagged";
sendEvent = null;
storeCollider = null;
//sendToCollider = false;
}

void StoreCollisionInfo(Collider collisionInfo)
{
storeCollider.Value = collisionInfo.gameObject;

}

public override void DoTriggerEnter(Collider other)
{
if (trigger == TriggerType.OnTriggerEnter)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
//Fsm.Event(sendEvent);
Fsm.Event(eventTarget, sendEvent);
}
}
}

public override void DoTriggerStay(Collider other)
{
if (trigger == TriggerType.OnTriggerStay)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
//Fsm.Event(sendEvent);
Fsm.Event(eventTarget, sendEvent);
}
}
}

public override void DoTriggerExit(Collider other)
{
if (trigger == TriggerType.OnTriggerExit)
{
if (other.gameObject.tag == collideTag.Value)
{
StoreCollisionInfo(other);
//Fsm.Event(sendEvent);
Fsm.Event(eventTarget, sendEvent);
}
}
}

public override string ErrorCheck()
{
return ActionHelpers.CheckOwnerPhysicsSetup(Owner);
}


}
}


MaDDoX

  • 1.2 Beta
  • Full Member
  • *
  • Posts: 165
    • FluidPlay Studios
Re: Trigger Broadcast Event
« Reply #7 on: November 17, 2011, 01:22:06 AM »
This is exactly what I need, but where is the code?
It's attached to the first post. Can't you see it? :o
--
Breno "MaDDoX" Azevedo
@brenoazevedo

lion-gv

  • Playmaker Newbie
  • *
  • Posts: 5
Re: Trigger Broadcast Event
« Reply #8 on: November 17, 2011, 08:19:10 AM »
Now I do, thanks for pointing that out!