Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding to custom events #130

Open
MSFX opened this issue Jan 29, 2022 · 1 comment
Open

Binding to custom events #130

MSFX opened this issue Jan 29, 2022 · 1 comment

Comments

@MSFX
Copy link

MSFX commented Jan 29, 2022

Hey,

Fantastic library, thanks so much for open sourcing it!

I'm running into a problem when trying to bind to an event I've made and wondered if you could point out where I'm going wrong please?

Unity code...

public class DebugManager : MonoBehaviour {

// first approach
        public delegate void OnDebugListChange(string json);
        public static event OnDebugListChange OnDebugListChangeEvent;
// second approach
        public static event UnityAction<string> OnUnityEventTest;

Javascript code...

msg = `{ "id": "OnDebugListChangeEvent", "q" : "/bind/DebugManager.OnDebugListChange" }`;
msg = `{ "id": "OnDebugListChangeEvent", "q" : "/bind/events.OnDebugListChange" }`;

I've tried two approach's with both a custom delegate and a UnityAction (since this is the type of "sceneLoaded" which is working perfectly) but it's still not working so I feel like I'm missing something.... I tried binding with various ways but no cigar... are you able to point me in the right direction please?

The log message I get is

Message: {"id":"OnDebugListChangeEvent","error":"Not Found"}

Thanks!

@gwaredd
Copy link
Owner

gwaredd commented Jan 31, 2022

Think of /bind like /q. It is a search of the (abstract) tree to select objects. What follows /bind is the query (GQL).

In the TestScene included with the library there are TestTicker objects on the cubes. So to bind to the first one you might use something like ...

{
  "id": "MyTestTickerBindingMessageThingy",
  "q" : "/bind/scene/Game/Cube[0].TestTicker.TickEvent"
}

FYI events is a top level object in the root of the tree, just as scene and stats is. GQL is not limited to just the scene graph. This is currently just used for binding to system event messages like debug and scene loading.

HTH

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants