Seneral / Node_Editor_Framework

A flexible and modular Node Editor Framework for creating node based displays and editors in Unity
https://nodeeditor.seneral.dev
MIT License
2.01k stars 414 forks source link

Example or more thorough documentation regarding events anywhere? #81

Closed snarlynarwhal closed 8 years ago

snarlynarwhal commented 8 years ago

I'm using the Node Editor as tool to modify/move/add/remove components in the Editor (not in play mode). I'd imagine that I want to use the NodeEditorCallbacks class and not the NodeEditorCallbackReceiver one. I understand how to implement the second method, but not the prior. Any examples anywhere?

Seneral commented 8 years ago

You need to build a 3rd editor script anywhere that subscribes to these events. So you'd do NodeEditorFramework.NodeEditorCallbacks.OnNodeMove += MyCallbackMethod Hope that helps!

snarlynarwhal commented 8 years ago

I can't seem to get it working, here's my code:

image

I added a Debug.Log in the OnEnable function, but got nothing. o.0 I haven't dealt with subscribing or delegates before, and have dabbled very little in editor scripts so I'm a novice to this.

ps - I owe you for all the help. So I'll definitely be contributing a feature or two to the project soon. :)

snarlynarwhal commented 8 years ago

Finally got it working but adding this line:

[CustomEditor(typeof(MachineNode))]

However, it keeps adding the connection OnEnable (duh). I added a static bool to track whether or not I've subscribed to the delegate. It appears to work fine! Or would there be a better place to subscribe?

Seneral commented 8 years ago

Sorry, was unavailable. Yes for it to execute you need to make it a custom editor (in this case).

For delegates, I tend to first unsubscribe (-=) and then subscribe (+=). If you haven't subsribed before it will do nothing but if you did you won't have duplicate subscribers:)

snarlynarwhal commented 8 years ago

No worries! And ahh got it thanks! :D