0
Answered

Call FlowMachine UnityEvent from C# script

Dalibor 3 years ago updated 3 years ago 3

Can someone please help:

How can I call from C# script a Bolt flow graph?

I don't know is this possible...I know how to do it in editor for a single object.

I have a script for runtime created buttons/images and I need to call UnityEvent form Bolt Flow. Script is already attached to any button created at runtime and OnPointerDown Debug.Log ("clicked") is working fine.

Script:

using UnityEngine;
using UnityEngine.EventSystems;
using Bolt;

namespace RuntimeInspectorNamespace
{
    public class PointerEventListener : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
    {
        public delegate void PointerEvent( PointerEventData eventData );

        public event PointerEvent PointerDown, PointerUp, PointerClick;


        public void OnPointerDown( PointerEventData eventData )
        {
            if( PointerDown != null )
                PointerDown( eventData );
            
        }

        public void OnPointerUp( PointerEventData eventData )
        {
            if( PointerUp != null )
                PointerUp( eventData );
        }

        public void OnPointerClick( PointerEventData eventData )
        {
            if( PointerClick != null )
                PointerClick( eventData );
        }
    }
}



Thanks for any info.

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
+1
Answered

Hi Dalibor!

This is definitely possible, but with a Custom Event, not a UnityEvent.

See this page:https://support.ludiq.io/knowledge-bases/4/articles/415-events-api

A minute ago I've tested with Custom event and it works!

Thanks!


+1

Cool thing is that Custom event don't needs a listener. It can be self. I didn't got any error.


using UnityEngine;
using UnityEngine.EventSystems;
using System.Collections;
using Bolt;


namespace RuntimeInspectorNamespace
{
    public class PointerEventListener : MonoBehaviour, IPointerDownHandler, IPointerUpHandler, IPointerClickHandler
    {
        public delegate void PointerEvent( PointerEventData eventData );

        public event PointerEvent PointerDown, PointerUp, PointerClick;

        public GameObject BoltFlow;

        public void OnPointerDown( PointerEventData eventData )
        {
            if( PointerDown != null )
                PointerDown( eventData );
        }

        public void OnPointerUp( PointerEventData eventData )
        {
            if( PointerUp != null )
                PointerUp( eventData );
        }

        public void OnPointerClick( PointerEventData eventData )
        {
            if( PointerClick != null )
                PointerClick( eventData );
            BoltFlow = GameObject.Find ("Bolt_SelectObject");
            Bolt.CustomEvent.Trigger(BoltFlow, "coolEv", 5);
        }
    }
}