Skip to content

NGUI Activators

NGUI Activators

Postby Alewinn » 11 Mar 2012, 18:51

Hi,

Here are ther NGUI activators smartblocks.

!! IMPORTANT !! : Each smartblock have a "Target" input that can be used ; in this case the "sensible" object will be the linked object.
Otherwise it's the Gameobject on which the Vizio component is that is considered by the logic.

Use : Drop the DLL inside the VISIO/Plugins/CustomBlocks/<name your subfolder> folder of your project.

Vizio_NGUI.rar
(4.39 KiB) Downloaded 158 times
Alewinn
 
Posts: 26
Joined: 08 Mar 2012, 15:01

Re: NGUI Activators

Postby Alewinn » 11 Mar 2012, 21:43

Need Code Too ?
Alewinn
 
Posts: 26
Joined: 08 Mar 2012, 15:01

Re: NGUI Activators

Postby holyjewsus » 11 Mar 2012, 22:42

thanks for sharing,

code would be great to learn from if you don't mind sharing!
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI Activators

Postby Alewinn » 11 Mar 2012, 23:02

Here is a Block/Component pair for the NGUI OnClick event.

The Vizio Block :

Syntax:
Using csharp Syntax Highlighting
/****************************************************************************
*
* <copyright file="TransparentShadowReceiver.pdf" company="Klakos">
* Copyright (c) 2010, 2010 All Rights Reserved, http://klakos.com
*
* LICENCE : GPLv2 [http://www.gnu.org/licenses/gpl-2.0.html]
*
* THIS DOCUMENT AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* </copyright>
*
* <author>Jean-Christophe Romain</author>
* <email>Jean-Christophe __at__ klakos.com</email>
* <date>2012-03-11</date>
*
***************************************************************************/


// Generated with Antares LogicBlock Wizard at Saturday, March 10, 2012  2:09:18 PM
using Antares.Vizio.Runtime;
using UnityEngine;

[VisualLogicBlockDescription("OnClick activator for NGUI ")]
[VisualLogicBlock("NGUIOnClick", "NGUI", ParentName = "Activators")]
public class NGUIOnClickBlock:LogicBlock
{
    [Parameter(VariableType.In, typeof(GameObject), Name = "Target", Comment = "By default, the Gameobject where the Visio Graph lies on is used. \n When provided, the Target GameObject is used as Activator.")]
    public Variable target;

    [Parameter(VariableType.In, typeof(bool), Name = "enabled", DefaultValue = true)]
    public Variable enabled;

    public override void OnInitializeDefaultData()
    {
        RegisterOutputTrigger("Clicked");      // 0      
    }

    /// <summary>
    /// Put a NGUIOnSelectActivatorComponent on
    /// the current GameObject, if any.
    /// </summary>
    public override void Awake()
    {
        NGUIOnClickActivatorComponent ComponentToRegister;
        GameObject TargetGAO = (GameObject)target.Value;

        if (!TargetGAO)
        {
            TargetGAO = this.VizioComponent.gameObject;
        }

        ComponentToRegister = TargetGAO.GetComponent<NGUIOnClickActivatorComponent>();

        // Adds a Component on the Target Object if any
        if (ComponentToRegister == null)
        {
            ComponentToRegister = TargetGAO.AddComponent<NGUIOnClickActivatorComponent>();
        }

        ComponentToRegister.RegisterActivator(this);
    }

    public override void OnDestroy()
    {
        NGUIOnClickActivatorComponent ComponentToUnRegister;
        GameObject TargetGAO = (GameObject)target.Value;

        if (!TargetGAO)
        {
            TargetGAO = this.VizioComponent.gameObject;
        }

        ComponentToUnRegister = TargetGAO.GetComponent<NGUIOnClickActivatorComponent>();

        if (ComponentToUnRegister != null)
        {
            ComponentToUnRegister.UnRegisterActivator(this);
        }
    }

    public void OnClick()
    {
        if ((bool)this.enabled.Value == true)
        {
            ActivateTrigger(0);
        }
    }

}
 
Parsed in 0.017 seconds, using GeSHi 1.0.8.4


The Component Block

Syntax:
Using csharp Syntax Highlighting
/****************************************************************************
*
* <copyright file="TransparentShadowReceiver.pdf" company="Klakos">
* Copyright (c) 2010, 2010 All Rights Reserved, http://klakos.com
*
* LICENCE : GPLv2 [http://www.gnu.org/licenses/gpl-2.0.html]
*
* THIS DOCUMENT AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
* KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
* PARTICULAR PURPOSE.
*
* </copyright>
*
* <author>Jean-Christophe Romain</author>
* <email>Jean-Christophe __at__ klakos.com</email>
* <date>2012-03-11</date>
*
***************************************************************************/


using System.Collections.Generic;
using UnityEngine;

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

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

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


    public void OnClick()
    {
        foreach (NGUIOnClickBlock activator in activators)
        {
            if (activator.Component != null)
            {
                activator.OnClick();
            }
        }
    }
}
 
Parsed in 0.009 seconds, using GeSHi 1.0.8.4


(The rest of the code is trivial, same for each NGui Event/Vizio component)

I thought of a "universal" component but currently, my needs are ok with theses ones.
In any case such a functionality can be engeneered inside a container...
Alewinn
 
Posts: 26
Joined: 08 Mar 2012, 15:01

Re: NGUI Activators

Postby RydnevJe » 23 Aug 2015, 22:31

This is very nice and cool post tahsnk for this ..........!!!!!!!!!!!!!!!!!!!!!!!!
RydnevJe
 
Posts: 15
Joined: 23 Aug 2015, 22:23


Return to GUI

Who is online

Registered users: No registered users