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

How to input multiple outputs to a node? #193

Closed Ragueel closed 4 years ago

Ragueel commented 4 years ago

I have been trying to create some sort of level editor which will contain how the level would be created. For example, there would LevelRootNode which will take as input several WaveNode maybe something like List<WaveNode>. WaveNode will also input many EnemyNode something like List<EnemyNode>. I didn't found any docs about that so I need some help with how can I do something like that.

Ragueel commented 4 years ago

Here is what I mean: image

Seneral commented 4 years ago

You need to setup the knobs so you can connect them, and there are several ways you could go about it. If you have some data you want to pass along, you could create a WaveData and EnemyData type connection for the respective input and output knobs. If you only care about tr fact that they are conmected, you can create knobs which don't pass data (See Flow Node example) - only a semantic difference.

Unfortunately currently the UI editing doesn't allow true multi-multi connections (see #149), so if you want to have multiple inputs to a knob, the output you want to connect them to need to be limited to one output connection. This might even be desirable in your case. If it causes a problem however, as a workaround you can manually create more input knobs as you add inputs (see Resizing Node example), however that's a bit of work, so if you can avoid it, try to. Hope that helps

Ragueel commented 4 years ago

Thanks for your explanation. I was able to figure out how some parts work but I didn't get the idea how can I pass data. image This is something that looks similar to what I wanted to achieve. Could you give a simple example with EnemyData because what I am thinking probably is a bit stupid.

So to connect EnemyNode with WaveNode, I created the class

public class EnemyNodeConnectionType : ValueConnectionType
    {
        public override Type Type => typeof(EnemyNode);
        public override string Identifier => "EnemyNode";
        public override Color Color => Color.blue; // Color didn't change in the editor
    }

I connected it in EnemyNode with:

[ValueConnectionKnob("EnemyInfo", Direction.Out, typeof(EnemyNodeConnectionType))]
public ValueConnectionKnob enemyOut;

And in WaveNode I did:

[ValueConnectionKnob("Enemies", Direction.In, typeof(EnemyNodeConnectionType), ConnectionCount.Multi)]
public ValueConnectionKnob waveIn;        

I don't think I have anything that needs to be calculated, I only need some sort of data flow so I can create enemies and waves. To do that I was thinking of using maybe inputPorts inside Node class. 😃

Seneral commented 4 years ago

Take a look at the example nodes, especially the FloatCalculation one. the Type overload for ValueConnectionKnobis only used for when you did NOT explicitly create a ValueConnectionType - it will take the type and generate a color for it, for quick prototyping. Since you did create an explicit type, replace the third parameter with the identifier you specified, "EnemyNode". However, seeing you specified typeof(EnemyNode) as the type of data you want the connection to pass, it looks like you only want to create a connection with two nodes, but don't care about actually passing data through it. So you could use a normal ConnectionKnob (without value), like in the Flow node example. This will still give the node information about the nodes it is connected to, which I believe is what you want.

Ragueel commented 4 years ago

Ahh, I finally get it. Thanks for the help. 👍 So far node editor looks really good. Is there way to make background dark? :)

Seneral commented 4 years ago

Are you perhaps on a Mac? Thought you changed the look intentionally at first, but there was a perhaps related issue before (#172) however I could not reproduce it. Can you play with the texture import settings and see if you can get it to look like in the title image? If you could get it to work I could figure out if and which import settings cause this.

Ragueel commented 4 years ago

I checked textures they seem to be gray.

image

The strange thing is that they have normal color when I view it outside the unity image

After setting sRGB texture now it appears to be normal color.

image

Full settings of the image: image

I can create pull request with it if you want.

Seneral commented 4 years ago

That looks good, thank you alot. Will probably have to change the metadata in an earlier version of unity so that they are still supported. Can do that next update