Skip to content

NGUI

Easy way to connect with other extensions

NGUI

Postby holyjewsus » 21 Dec 2011, 19:33

I just picked up NGUI as 3.5 won't have the new GUI system and I need to begin work now.
http://www.tasharen.com/?page_id=160

I'm interested in how to receive events from the event system in ngui. It interfaces with the UIcamera script placed on a camera in the scene,

http://www.tasharen.com/?page_id=148

Can I use wizards for this?
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby holyjewsus » 22 Dec 2011, 01:17

Syntax:
Using csharp Syntax Highlighting
public class CustomListener : MonoBehaviour
{
        void OnClick()
        {
                Debug.Log("I was clicked on!");
        }
       
        void OnHover (bool val)
        {
                Debug.Log("I was " + (val ? "hovered on" : "not hovered on"));
        }
}
Parsed in 0.006 seconds, using GeSHi 1.0.8.4



some code from the unity forum thread

Image



http://www.tasharen.com/?page_id=401

minute 13:09 has some code examples
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby Neodrop » 22 Dec 2011, 08:23

Well, as a quick integration method, you can use MessageManager to move controll from this MonoBehaviour methods to your graph. Like this : example-on-send-and-receive-message-using-vizio-messaging-t405.html#p911

Something like this one :

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

public class CustomListener : MonoBehaviour
{
        void OnClick()
        {
                Debug.Log("I was clicked on!");
                MessageManager.SendMsg("OnClick", "Called from NGUI !");
        }
       
        void OnHover (bool val)
        {
                Debug.Log("I was " + (val ? "hovered on" : "not hovered on"));
                MessageManager.SendMsg("OnHover", "Called from NGUI !", val);
        }
}
Parsed in 0.007 seconds, using GeSHi 1.0.8.4
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: NGUI

Postby Neodrop » 22 Dec 2011, 08:27

I will looking for a little bit deeper inside NGUI when I find some free time for it.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: NGUI

Postby holyjewsus » 25 Dec 2011, 09:57

Syntax:
Using csharp Syntax Highlighting
using UnityEngine;

[NodePath("Events/NGUI")]
[NodeToolTip("NGUI Event receiver")]
[NodeDescription("NGUI Event receiver node")]
[NodeComponentType(typeof(Collider))]
[FriendlyName("NGUI Event")]
public class NGUIuScript : uScriptEvent
{
        public class BoolEventArgs : System.EventArgs
        {
                bool mVal;
                public bool state { get { return mVal; } }
                public BoolEventArgs (bool value) { mVal = value; }
        }

        public class Vector2EventArgs : System.EventArgs
        {
                Vector2 mVal;
                public Vector2 delta { get { return mVal; } }
                public Vector2EventArgs (Vector2 value) { mVal = value; }
        }

        public class GameObjectEventArgs : System.EventArgs
        {
                GameObject mVal;
                public GameObject draggedObject { get { return mVal; } }
                public GameObjectEventArgs (GameObject value) { mVal = value; }
        }

        public delegate void uScriptEventHandlerVoid (object sender, System.EventArgs args);
        public delegate void uScriptEventHandlerBool (object sender, BoolEventArgs args);
        public delegate void uScriptEventHandlerVector2 (object sender, Vector2EventArgs args);
        public delegate void uScriptEventHandlerGameObject (object sender, GameObjectEventArgs args);

        [FriendlyName("On Click")]
        public event uScriptEventHandlerVoid onClick;

        [FriendlyName("On Hover")]
        public event uScriptEventHandlerBool onHover;

        [FriendlyName("On Press")]
        public event uScriptEventHandlerBool onPress;

        [FriendlyName("On Select")]
        public event uScriptEventHandlerBool onSelect;

        [FriendlyName("On Drag")]
        public event uScriptEventHandlerVector2 onDrag;

        [FriendlyName("On Drop")]
        public event uScriptEventHandlerGameObject onDrop;

        [FriendlyName("On Tooltip")]
        public event uScriptEventHandlerBool onTooltip;

        void OnClick () { if (null != onClick) onClick(this, new System.EventArgs()); }
        void OnHover (bool isOver) { if (null != onHover) onHover(this, new BoolEventArgs(isOver)); }
        void OnPress (bool pressed) { if (null != onPress) onPress(this, new BoolEventArgs(pressed)); }
        void OnSelect (bool selected) { if (null != onSelect) onSelect(this, new BoolEventArgs(selected)); }
        void OnDrag (Vector2 delta) { if (null != onDrag) onDrag(this, new Vector2EventArgs(delta)); }
        void OnDrop (GameObject go) { if (null != onDrop) onDrop(this, new GameObjectEventArgs(go)); }
        void OnTooltip (bool show) { if (null != onTooltip) onTooltip(this, new BoolEventArgs(show)); }
}
Parsed in 0.019 seconds, using GeSHi 1.0.8.4


Hey neodrop, thought this might be useful, this is how the event system for NGUI hooks into uscript, not sure if it's helpful or confusing, but thought you might want to see it.

code was written by ArenMook - ngui creator
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby holyjewsus » 27 Dec 2011, 05:56

I added that custom listener script to a ngui widget thats part of my UI, I can get all the messages on my universe graph by using the message manager, but the message seems to be broadcast to all objects, how can I send the message to only the graph on the object the customlistener is on?
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby holyjewsus » 27 Dec 2011, 06:15

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

public class CustomListener : MonoBehaviour
{
        void OnClick()
        {
                Debug.Log("I was clicked on!");
                MessageManager.SendMsg(this,"OnClick", "Called from NGUI !");
        }
       
        void OnHover(bool val)
        {
                Debug.Log("I was " + (val ? "hovered on" : "not hovered on"));
                MessageManager.SendMsg(this,"OnHover", val);
        }
               
                void OnPress (bool val)
        {
                Debug.Log("I was pressed");
                                MessageManager.SendMsg(this,"OnPress", val);        
                }
                void OnSelect(bool val)
        {
                Debug.Log("I was selected");
                                MessageManager.SendMsg(this,"OnSelect", val);        
                }
                void OnDrag(Vector2 delta)
        {
                Debug.Log("I am being Dragged");
                                MessageManager.SendMsg(this,"OnDrag", delta);        
                }
                void OnDrop(GameObject go)
        {
                Debug.Log("I was Dropped");
                                MessageManager.SendMsg(this,"OnDrop", go);        
                }
                void OnTooltip(bool val)
        {
                Debug.Log("Tooltip Time");
                                MessageManager.SendMsg(this,"OnTooltip",val);        
                }
       
}
Parsed in 0.013 seconds, using GeSHi 1.0.8.4


I think this is better and gives no errors when running, had some extra string parameters in there before for no reason.
Last edited by holyjewsus on 08 Apr 2012, 15:17, edited 1 time in total.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby Neodrop » 08 Apr 2012, 14:49

Did NGUI have a fixed events list ? If so, can somebody post it here? I will write a smart block to manage this events inside Universe.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: NGUI

Postby holyjewsus » 08 Apr 2012, 15:16

http://www.tasharen.com/?page_id=160

theres also a few more though, where you can specify the event name, I believe like OnSelectionChange() for the Popuplist and another for Sliders
but these are the main ones.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby Neodrop » 27 Apr 2012, 11:43

Done. Here is the NGUI Event listener for Universe. Export to your project and add to your NGUI elements from NGUI/UNIVERSE/Forward Events menu.
It's work with Universe message, which will be autoimaticaly generated by this button :
Attachments
ngui.jpg
ngui.jpg (14.32 KiB) Viewed 4293 times
NGUI2Universe.unitypackage
(2.21 KiB) Downloaded 146 times
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: NGUI

Postby Neodrop » 01 May 2012, 11:07

New, a little bit improved version. With event, this code will provide a link to the sender.
NOTE : Regenerate the Universe Messages by button from NGUI_2_Universe component.
Cheers.
Attachments
NGUI2Universe.unitypackage
(2.23 KiB) Downloaded 193 times
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Re: NGUI

Postby kyy921 » 08 Oct 2012, 23:36

I can be worked in the scene with only on button,, but when I have a lot of of button in the scene, how I know with button I pressed?
kyy921
 
Posts: 56
Joined: 15 Jul 2012, 08:29

Re: NGUI

Postby holyjewsus » 09 Oct 2012, 04:24

theres multiple ways, neodrops messages return the gameobject that was the sender, you can also check a variable in ngui camera,

"inside your event functions you can always figure out who sent the event (UICamera.currentCamera), RaycastHit that resulted in this event (UICamera.lastHit), as well as the on-screen position of the touch or mouse (UICamera.lastTouchPosition). You can also determine the ID of the touch event (UICamera.currentTouchID), which is ‘-1′ for the left mouse button, ‘-2′ for right, and ‘-3′ for middle." - quoted from ngui docs

If you use my scripts you could always change the message that the button sends.... but this would probably get really confusing fast.

You could also try using the UIeventlistener class, but I don't think theres a way to directly hook up the delegates to universe so you'd be creating a listener that would subscribe to different button events and then route them to the correct messages on a graph or graphs.
holyjewsus
 
Posts: 390
Joined: 08 Apr 2011, 00:58

Re: NGUI

Postby kyy921 » 01 Feb 2013, 14:04

is that possible define some string in front of the message name in each script, so we can deal with all the button message in one vizio object
kyy921
 
Posts: 56
Joined: 15 Jul 2012, 08:29

Re: NGUI

Postby Neodrop » 02 Feb 2013, 00:10

All Universe (Vizio) messages are global. Any object (graph) which has been waiting for message "myMess" will receive it in any case. I'm not sure, about your task.
If you want to send it directly to some object, you can add a message parameter (GameObject) and specified unique target for it. When some graph will receive this message, his can check equality between himself and message target parameter.
User avatar
Neodrop
Администратор
 
Posts: 1068
Joined: 15 Jan 2011, 13:18

Next

Return to Bridges

Who is online

Registered users: No registered users