0
Answered

Bolt with NGUI

Real World 3 years ago updated by 유승수 2 years ago 3

Would it be possible to use Bolt with NGUI? I notice that there are lots of events for handling UGUI events but these obviously won't work with NGUI. Can I create custom events that handle these events?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
GOOD, I'M SATISFIED
Satisfaction mark by Real World 3 years ago
+2
Answered

Hi Real World! Welcome to the community :)

You're right, the amount of events needed would require some additional scripting integration.

Unfortunately, there is no documentation yet for creating these, but if you have good programming experience, you could deduce it from the existing events. You can add an event script anywhere in your assets folder.

For example, here is the code for the OnButtonClick event:

using Ludiq;
using UnityEngine.UI;
namespace Bolt
{
    /// <summary>
    /// Called when a user clicks the button and releases it.
    /// </summary>
    [UnitCategory("Events/GUI")]
    [TypeIcon(typeof(Button))]
    [UnitOrder(0)]
    public sealed class OnButtonClick : GameObjectEvent { }
}

And how it's registered in the message listener (you'll need to add one of these intermediate components to your UGUI objects to relay the messages to Bolt):

GetComponent<Button>()?.onClick?.AddListener(() => GameObjectEvent.Trigger<OnButtonClick>(gameObject));

The important part here (as it may work a bit differently in NGUI), is this:

GameObjectEvent.Trigger<OnButtonClick>(gameObject)

So that when you receive a click in NGUI, you relay it to your Bolt event.

For the message listener class, just make it inherit Bolt.MessageListener. Doing so, it will automatically get added to components that need to receive events at runtime.

There will be better documentation for these types of things in the future, it's on the roadmap!

Thanks for the quick reply Lazlo. I'll take a look at that and see if I can do something with that, Much appreciated.

My program level is very low.

Could you please put the button part of ngui in more detail or related files?