Author Topic: Global Functions  (Read 2315 times)

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Global Functions
« on: March 25, 2015, 12:46:50 PM »
Hey. First, I'm not sure if this is the right forum to ask, so please tell me if it isn't. It isn't really NGUI question, but it also is...

So:
Could someone please explain to me how the global functions in NGUI work? (I mean OnClick and so on) How are they called? Is is possible for me to easily add my own global functions to my project?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Global Functions
« Reply #1 on: March 27, 2015, 10:41:50 PM »
UICamera calls them using SendMessage. Not sure what you mean by last part. Add your own functions in which way? They'd need to match the name for NGUI to call them.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Global Functions
« Reply #2 on: March 28, 2015, 07:08:59 PM »
They're not really "global functions" as such, it's just that SendMessage can call private methods in components by name.

You just call them with

  1. aGameObject.SendMessage("MyMethod");

You can also use BroadcastMessage("MethodName") to send a message to ALL gameobject - closer to a real global method, I suppose, but it's a little performance heavy, so not recommended to do often.

webik150

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 36
    • View Profile
Re: Global Functions
« Reply #3 on: March 29, 2015, 12:41:45 PM »
They're not really "global functions" as such, it's just that SendMessage can call private methods in components by name.

You just call them with

  1. aGameObject.SendMessage("MyMethod");

You can also use BroadcastMessage("MethodName") to send a message to ALL gameobject - closer to a real global method, I suppose, but it's a little performance heavy, so not recommended to do often.

Oh! This is exactly what I'm looking for. Thanks a lot.

Actually, I don't really remember why I asked in the first place... Probably some crazy idea...