Comments (5)
Its called here:
https://github.com/Seneral/Node_Editor_Framework/blob/develop/Node_Editor_Framework/Runtime/Framework/Interface/NodeEditorInputControls.cs#L173
so it should call it once after the drag ended. It does not currently call it every frame, nor does it call it when the keyboard is used (that is a bug).
Note that the Receiver is only working as an instantiated MonoBehaviour due to implementation, I assume you don't have ExecuteInEditMode or are in play mode so the code will not execute. You will have to get a static script to work in edit mode and use the Actions, not sure how the details were for that in Unity.
Alternatively, you can take a look at what the built-in NodeGroup does. It implements custom controls that override the default drag in certain scenarios and also moves multiple nodes, that might be something to refer to. The static functions tagged with the proper attributes will be called automatically if you set the priorities right, but you might have to copy and modify the existing drag function which is more complex
from node_editor_framework.
@Seneral Thanks so much for such a quick and informative reply. I realized early on that I didn't have much of a use for the NodeGroups, so I didn't do much research into them, and turns out the NodeGroup
class was a perfect example to show me what to do. I spent today writing my own methods, structured similar to those in NodeGroup
and it's working perfectly now.
I used recursion since I don't just want a node's children to be dragged along, I want the whole subtree. Here's the code I wrote inside of my BaseBTNode
class:
public void SetNodeOffset(Node node)
{
this.offset = this.position - node.position;
for (int i = 0; i < children.Length; i++)
{
children[i].SetNodeOffset(node);
}
}
public void UpdatePosition(Node node)
{
//Debug.Log(offset);
this.position = node.position + offset;
for (int i = 0; i < children.Length; i++)
{
if (children[i] != null)
children[i].UpdatePosition(node);
}
}
[EventHandlerAttribute(EventType.MouseDown, 109)]
private static void HandleNodeStartDrag(NodeEditorInputInfo inputInfo)
{
//Debug.Log("Running OnMoveNode callback");
if (GUIUtility.hotControl > 0)
return; // GUI has control
NodeEditorState state = inputInfo.editorState;
if(inputInfo.inputEvent.button == 0 && !state.dragNode)
{
var n = NodeEditor.NodeAtPosition(NodeEditor.ScreenToCanvasSpace(inputInfo.inputPos)) as BaseBTNode;
if(n!=null)
{
for(int i = 0; i<n.children.Length; i++)
{
n.children[i].SetNodeOffset(n);
}
state.StartDrag("node", inputInfo.inputPos, n.position);
state.dragNode = true;
}
}
}
[EventHandlerAttribute(EventType.MouseDrag)]
private static void HandleNodeDragging(NodeEditorInputInfo inputInfo)
{
NodeEditorState state = inputInfo.editorState;
var n = state.selectedNode as BaseBTNode;
if(n!=null)
{
if(state.dragUserID != "node")
{
state.selectedNode = null;
state.dragNode = false;
return;
}
//Update drag operation
Vector2 dragChange = state.UpdateDrag("node", inputInfo.inputPos);
Vector2 newPos = state.dragObjectPos;
// Update positions
n.position = newPos;
for(int i = 0; i<n.children.Length; i++)
{
n.children[i].UpdatePosition(n);
}
inputInfo.inputEvent.Use();
NodeEditor.RepaintClients();
}
}
[EventHandlerAttribute(EventType.MouseUp)]
private static void HandleDraggingEnd(NodeEditorInputInfo inputInfo)
{
if(inputInfo.editorState.dragUserID == "node")
{
inputInfo.editorState.EndDrag("node");
NodeEditor.RepaintClients();
}
inputInfo.editorState.selectedNode = null;
inputInfo.editorState.dragNode = false;
}
from node_editor_framework.
Looking good, just one thing, I'd expect ypu need to change at least the drag id from "node" to something custom so the default mouseDrag events won't interfere. Right now it seems it will come down to chance which one will get called first, at least from a quick glance. Having a different drag id means the builtin function will not consider it as a drag it needs to handle.
Also make sure all your relevant canvas types are disallowing loops (via property) if you are relying on recursion like this, especially if you intend to have other users use the system.
from node_editor_framework.
Yeah, good point, I was wondering if that would cause an issue. In testing so far, it never seemed like the default mouseDrag events ever activated, I think perhaps because I set the priority of the EventHandlerAttribute to a lesser value, but it definitely would be good to change it to something unique.
And yeah, I never disallowed recursive loops, I just knew I wasn't going to be using them. How should I do that? Maybe in ValidateSelf()
in my custom Canvas class, if I detect any recursive loops I could delete one of the nodes?
from node_editor_framework.
Nevermind, Canvas
has an allowRecursion
property, that's what you meant, haha. Thanks again
from node_editor_framework.
Related Issues (20)
- The connections will miss when I add a new node. HOT 2
- GUIScaleUtility.cs Init Method NullReferenceException in Unity 2019.1.2f1 HOT 10
- Insane Bug from using RTEditorGUI.EnumPopup() HOT 3
- XML not saving node values HOT 10
- Is Project Active and Package Support? HOT 15
- `PlayModeStateChange' could not be found. Are you missing a using directive or an assembly reference? HOT 3
- [Solved] Context menu not showing up. HOT 2
- Multiple instances of node editors open at once HOT 1
- Toolbar is not showing up HOT 4
- All data is lost when I change the scene, even though I have extra saved as an asset file HOT 4
- How to input multiple outputs to a node? HOT 8
- Apple M1 computers not displaying Bezier curves HOT 3
- Added one node. Then it stoped working. (Remove the node, re-install, sitll not working) Unity 2020.2 LTS
- Implementation of a Logic Graph HOT 7
- XML import issue on UWP
- I deleted the ScriptableObjects in Assets/DefaultEditorResources/Node_Editor_Framework HOT 3
- Functional Nodes that are not tied to the Node Editor Window HOT 6
- Loading canvas based on Selection.activeTransform? HOT 4
- seems undo pro doesnt work with unity 2022.2.8 not sure what version it stopped working at HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node_editor_framework.