Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

nGUI and Behavior Designer

Discussion in 'Scripting' started by SeriousBusinessFace, May 12, 2014.

  1. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Does anyone have experience getting nGUI and Behavior Designer to work together? In specific, how would I send button click data to Behavior Designer?
     
  2. opsive

    opsive

    Joined:
    Mar 15, 2010
    Posts:
    5,086
    Because the tasks are not derived from MonoBehaviour it isn't completely straight forward, but it doesn't involve too much work either.

    The easiest way would be to create a new MonoBehavior script that receives the NGUI click events. That script would then call the task that you want to receive the click data. In order to reference that task from the MonoBehaviour script you will need to create a variable of that task type. You could also do this using events but this is the most straight forward.

    Here's the task:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using BehaviorDesigner.Runtime.Tasks;
    4.  
    5. public class MyTask : Action
    6. {
    7.     public override void OnAwake()
    8.     {
    9.         gameObject.GetComponent<GUIClickEventReceiver>().myTask = this;
    10.     }
    11.  
    12.     public void SendData(object data)
    13.     {
    14.         ...
    15.     }
    16. }
    17.  
    GUIClickEventReceiver would then look something like:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. public class GUIClickEventReceiver : MonoBehaviour {
    4.    
    5.     public MyTask myTask;
    6.    
    7.     public void OnClick()
    8.     {
    9.         myTask.SendData(data);
    10.     }
    11. }
    12.  
     
  3. SeriousBusinessFace

    SeriousBusinessFace

    Joined:
    May 10, 2014
    Posts:
    127
    Thanks; that looks pretty simple and sensible.