Skip to content

Advanced trigger activator

User created LBs

Advanced trigger activator

Postby pax » 18 Apr 2011, 11:40

Smart Block that handles the trigger events with the specified GameObject

Syntax:
Using csharp Syntax Highlighting
using Antares.Vizio.Runtime;
using UnityEngine;


[VisualLogicBlockDescription("Use target object as trigger handle it events.")]
[VisualLogicBlock("Advanced Trigger Actovator", "Activators")]
public class AdvancedTriggerActivatorBlock : LogicBlock
{
    // is block enabled
    [Parameter(VariableType.In, typeof(bool), DefaultValue = true)]
    public Variable enabled;

    // target game object
    [Parameter(VariableType.In, typeof(GameObject))]
    public Variable target;

    // other Collider that is touching the trigger
    [Parameter(VariableType.Out, typeof(Collider), Name = "Other Collider")]
    public Variable otherCollider;

    // initialize activator
    public override void Awake()
    {
        GameObject go = target.Value as GameObject;
        if(go)
        {
            // get AdvancedTriggerActivatorComponent, that used for handle events
            var triggerComponent = go.GetComponent<AdvancedTriggerActivatorComponent>();
            if(triggerComponent == null)
            {
                triggerComponent = go.AddComponent<AdvancedTriggerActivatorComponent>();
            }

            // register current block to handle trigger events
            triggerComponent.RegisterActivator(this);
        }
    }

    // unregister block
    public override void OnDestroy()
    {
        GameObject go = target.Value as GameObject;
        if (go)
        {
            var triggerComponent = go.GetComponent<AdvancedTriggerActivatorComponent>();
            if (triggerComponent != null)
            {
                triggerComponent.UnRegisterActivator(this);
            }
        }
    }

    // three output triggers
    public override void OnInitializeDefaultData()
    {
        RegisterOutputTrigger("Enter"); //0
        RegisterOutputTrigger("Stay");  //1
        RegisterOutputTrigger("Exit");  //2
    }

    public void Enter(Collider other)
    {
        if((bool)enabled.Value)
        {
            otherCollider.Value = other;
            ActivateTrigger(0);
        }
    }

    public void Stay(Collider other)
    {
        if ((bool)enabled.Value)
        {
            otherCollider.Value = other;
            ActivateTrigger(1);
        }
    }

    public void Exit(Collider other)
    {
        if ((bool)enabled.Value)
        {
            otherCollider.Value = other;
            ActivateTrigger(2);
        }
    }


}
 
Parsed in 0.018 seconds, using GeSHi 1.0.8.4


This component is used to handle and dispatch trigger events
Syntax:
Using csharp Syntax Highlighting
using System.Collections.Generic;
using UnityEngine;

public class AdvancedTriggerActivatorComponent : MonoBehaviour
{
    // registerd activators for this trigger
    private readonly List<AdvancedTriggerActivatorBlock> activators
        = new List<AdvancedTriggerActivatorBlock>();

    // register activaror
    public void RegisterActivator(AdvancedTriggerActivatorBlock activator)
    {
        if (!activators.Contains(activator))
        {
            activators.Add(activator);
        }
    }

    // unregister activaror
    public void UnRegisterActivator(AdvancedTriggerActivatorBlock activator)
    {
        activators.Remove(activator);
    }


    // handle and dispatch trigger events

    public void OnTriggerEnter(Collider other)
    {
        foreach (var activator in activators)
        {
            if(activator.Component!= null)
            {
                activator.Enter(other);
            }
        }
    }

    public void OnTriggerExit( Collider other)
    {
        foreach (var activator in activators)
        {
            if (activator.Component != null)
            {
                activator.Exit(other);
            }
        }
    }

    public void OnTriggerStay(Collider other)
    {
        foreach (var activator in activators)
        {
            if (activator.Component != null)
            {
                activator.Stay(other);
            }
        }
    }

}
 
Parsed in 0.012 seconds, using GeSHi 1.0.8.4
Attachments
AdvancedTriggerActivatorComponent.cs
(1.45 KiB) Downloaded 131 times
AdvancedTriggerActivatorBlock.cs
(2.42 KiB) Downloaded 267 times
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: Advanced trigger activator

Postby Viziopleasure » 18 Apr 2011, 13:02

Thank you. Good stuff.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: Advanced trigger activator

Postby emadgh » 18 Apr 2011, 14:05

Thanks...
Unify Smart blocks are for you to use in your projects with Universe.
User avatar
emadgh
 
Posts: 48
Joined: 01 Feb 2011, 03:22
Location: 192.168.0.1

Re: Advanced trigger activator

Postby holyjewsus » 18 Apr 2011, 14:08

where do I place these scripts inside vizio?
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: Advanced trigger activator

Postby Viziopleasure » 18 Apr 2011, 14:28

holyjewsus wrote:where do I place these scripts inside vizio?


Copy them to your VIZIO > Plugins > CustomBlocks folder.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: Advanced trigger activator

Postby holyjewsus » 18 Apr 2011, 14:36

thanks!, i feel foolish
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: Advanced trigger activator

Postby pax » 18 Apr 2011, 14:37

holyjewsus wrote:where do I place these scripts inside vizio?


Viziopleasure wrote:
holyjewsus wrote:where do I place these scripts inside vizio?


Copy them to your VIZIO > Plugins > CustomBlocks folder.


Actually there is no special place. You can place it anywhere in the project (the only restriction - not in Editor folder).
User avatar
pax
 
Posts: 65
Joined: 27 Jan 2011, 20:21

Re: Advanced trigger activator

Postby Viziopleasure » 18 Apr 2011, 15:31

Yeah, just a suggestion for organization.
User avatar
Viziopleasure
 
Posts: 115
Joined: 31 Mar 2011, 12:08

Re: Advanced trigger activator

Postby RydnevJe » 23 Aug 2015, 22:41

Nice posts. Keep posting such needed information. Thank's!
RydnevJe
 
Posts: 15
Joined: 23 Aug 2015, 22:23


Return to Smart Blocks

Who is online

Registered users: No registered users