前面说了如何通过GraphView创建出节点,然后节点如何连接。这一节介绍如何自己创建自定义的节点,这样才能根据需要制作符合功能的节点。下面我们制作2个节点,一个是int的加法节点和输出日志的节点。
展现的效果如下:

我们可以在节点上点击鼠标右键选择“执行”动作来执行当前节点。目前的执行逻辑很简单,是依次向下执行。
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
public class AddIntNode : MyBaseNode
{
private TextField Param1;
private TextField Param2;
private Port Result;
public AddIntNode()
{
title = "Int加";
Param1 = new TextField("参数1:");
Param1.RegisterValueChangedCallback(OnParam1ValueChange);
Param1.value = "0";
Param2 = new TextField("参数2:");
Param2.RegisterValueChangedCallback(OnParam2ValueChange);
Param2.value = "0";
Result = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(int));
Result.portName = "结果";
Result.source = 0;
inputContainer.Add(Param1);
inputContainer.Add(Param2);
outputContainer.Add(Result);
}
private void OnParam1ValueChange(ChangeEvent<string> e)
{
int r = 0;
if(int.TryParse(e.newValue,out r))
{
string s = string.Format("{0}", r);
Param1.value = s;
}
else
{
Param1.value = "0";
}
}
private void OnParam2ValueChange(ChangeEvent<string> e)
{
int r = 0;
if (int.TryParse(e.newValue, out r))
{
string s = string.Format("{0}", r);
Param2.value = s;
}
else
{
Param2.value = "0";
}
}
public override void OnExecute()
{
int r = int.Parse(Param1.value) + int.Parse(Param2.value);
Result.source = r;
base.OnExecute();
}
}
using UnityEditor.Experimental.GraphView;
using UnityEngine;
public class LogNode : MyBaseNode
{
private Port LogText;
public LogNode()
{
title = "Log打印";
LogText = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(object));
LogText.portName = "输出文本";
LogText.source = 0;
inputContainer.Add(LogText);
}
public override void OnExecute()
{
foreach(var v in LogText.connections)
{
if(v.output != null)
{
LogText.source = v.output.source;
}
}
Debug.Log(LogText.source);
base.OnExecute();
}
}
他们都来至于一个基类,方便以后扩展相同功能的方法和属性:
using UnityEditor.Experimental.GraphView;
using UnityEngine.UIElements;
public class MyBaseNode : Node
{
//处理节点计算
public virtual void OnExecute()
{
int count = outputContainer.childCount;
for(int i = 0; i < count; ++i)
{
if(outputContainer.ElementAt(i) is Port)
{
Port p = outputContainer.ElementAt(i) as Port;
foreach(var n in p.connections)
{
if(n.input != null)
{
MyBaseNode iNode = n.input.node as MyBaseNode;
if(iNode != null)
{
iNode.OnExecute();
}
}
}
}
}
}
public override void BuildContextualMenu(ContextualMenuPopulateEvent evt)
{
evt.menu.InsertAction(0, "执行", OnExcMenu);
}
private void OnExcMenu(DropdownMenuAction a)
{
OnExecute();
}
}
然后我们在MyGraphView的创建代理函数中,创建的时候默认创建这2个节点。后面我们来看如何扩展创建节点的菜单。
this.nodeCreationRequest += (NodeCreationContext t) =>{
Node s1 = new AddIntNode();
Node s2 = new LogNode();
AddElement(s1);
AddElement(s2);
};
我们修改添加上面的几处代码,就能创建这2个节点。我们选中Int加节点鼠标右键,看看是否能够正常计算自己填写的值呢?
目前这种方式存在问题。比如一个节点的输出连接了2个节点,上面的节点的输入又依赖于下面兄弟节点的输出,就会导致问题。因为代码中我们默认通过输出节点向下执行,但是输入的数据可能来不全,这个时候需要通过输入的连接执行父节点。下一节我们探索如何设计节点来规划这个问题。
zmozeroteriloren
I like this website very much, Its a very nice billet to read and incur info . “There is no exercise better for the heart than reaching down and lifting people up.” by John Andrew Holmes.
togel deposit 5000
Regards for this post, I am a big big fan of this internet site would like to go along updated.
zmozeroteriloren
I was reading some of your posts on this site and I conceive this website is really informative! Keep putting up.
joyboanny
peyronie’s disease and viagra Table 2 Serum Tumor Marker Indicators In Patients
actiole
Volume calculation was used to measure lymphedema finasterid Some say Lindsay paved the way for the city s brush with bankruptcy in the 1975
enviple
scPrognosis contains five steps as depicted in Fig 1 buy cialis online without a prescription
Cicaimb
com 20 E2 AD 90 20Viagra 20Shqip 20Sa 20Kushton 20 20Spektakl 20Viagra 20Recenzje spektakl viagra recenzje Гў We ve got a starting rotation that s relentless, and I said that before the series started tamoxifen and covid vaccine That is what my reforms are about
fountee
buy stromectol pills The Beidou system is so Mens Upflow Male Enhancement Pills do blood pressure meds cause erectile dysfunction powerful that you can log in to the Internet even at sea Principal Raphael excitedly held his mobile phone
The Best Romantic Places to Propose in Khartoum (Sudan)
I really like your blog.. very nice colors & theme. Did you create this website yourself or did you hire someone to do it for you? Plz reply as I’m looking to construct my own blog and would like to know where u got this from. thanks
Handbook Guide to a Railton - EIGHT (1937-39) (Classic Handbook Car Guide)
Some genuinely nice stuff on this internet site, I like it.
Learning and Understanding about Thyroid agenesis Disease (Volume 1)
whoah this blog is fantastic i love reading your posts. Keep up the good work! You know, lots of people are hunting around for this information, you could help them greatly.
The Best Places to find a Girlfriend in Torino (Italy)
I went over this site and I think you have a lot of excellent info , saved to my bookmarks (:.
The Best Places to Raise a Family in Lima (Peru)
I’d constantly want to be update on new blog posts on this website , saved to fav! .
The Best Things to do in Shaoyang (China)
so much excellent information on here, : D.
How to Start a Coop Cleaning Business (Beginners Guide)
Yay google is my king aided me to find this great internet site! .
Learning and Understanding about Non-lissencephalic cortical dysplasia Disease (Volume 1)
I got good info from your blog
Kaolinite - Ultimate Knowledge Handbook (Mineral Guide)
I’ve been exploring for a little for any high-quality articles or blog posts on this kind of area . Exploring in Yahoo I at last stumbled upon this site. Reading this information So i am happy to convey that I’ve an incredibly good uncanny feeling I discovered just what I needed. I most certainly will make sure to do not forget this site and give it a look regularly.
The Best Places to Buy a Property in Guigang (China)
I really like your writing style, wonderful information, appreciate it for posting : D.
How to Write a Business Plan for a Etchers Business
Hello my family member! I wish to say that this post is awesome, nice written and come with approximately all vital infos. I’d like to see more posts like this.
Handbook Guide to a Lancia - BETA HPE (Classic Handbook Car Guide)
I went over this internet site and I conceive you have a lot of great info, saved to bookmarks (:.
How to Start a Propane Business (Beginners Guide)
There are actually a variety of details like that to take into consideration. That is a nice level to convey up. I offer the ideas above as normal inspiration however clearly there are questions just like the one you carry up where the most important thing might be working in honest good faith. I don?t know if finest practices have emerged round issues like that, but I’m positive that your job is clearly identified as a good game. Each girls and boys really feel the impact of only a second’s pleasure, for the rest of their lives.
The Best Places to visit in Nakuru (Kenya)
Have you ever considered about adding a little bit more than just your articles? I mean, what you say is valuable and everything. Nevertheless just imagine if you added some great pictures or videos to give your posts more, “pop”! Your content is excellent but with images and clips, this website could undeniably be one of the most beneficial in its field. Amazing blog!
The Best Places to Live in Yixing (China)
When I originally commented I clicked the -Notify me when new comments are added- checkbox and now each time a comment is added I get four emails with the same comment. Is there any way you can remove me from that service? Thanks!
How to Write a Business Plan for a Bricks And Mouldings Made Of Magnesite Business
Hey just wanted to give you a quick heads up. The text in your post seem to be running off the screen in Opera. I’m not sure if this is a format issue or something to do with web browser compatibility but I figured I’d post to let you know. The design look great though! Hope you get the issue solved soon. Thanks
Dr. Mudri Sándor Balázs ügyvéd
Im not certain where you are getting your info, but good topic. I needs to spend a while finding out much more or working out more. Thank you for fantastic information I used to be looking for this information for my mission.
fiehymn
where to buy lasix online The baseline characteristics of the two groups recorded at or before dialysis initiation are summarized in Table 1
pippeferi
does nolvadex lower estrogen Scientists working for the Russian Academy of Sciences last week picketed the offices of Russia s central bank and the Ministry of Finance, demanding payment of their saries for February and March
Prierse
By tracking your BBT accurately over a few months, you may be able to predict when ovulation occurs ivermectin for humans walmart
Emereaw
Sodium retention and volume expansion in nephrotic syndrome implications for hypertension can i buy cialis without a prescription
GRIEDALIA
buy lasix pills At this moment, Androni stood dazedly before she came back to her senses, She blushed and was blood pressure meds lop so charming that she bit her lower lip and said bitterly Death Fengyue
Juseshext
The bottom number represents the pressure when the heart is at rest between contractions priligy kaufen my hormones must really have been driving me mad
roombinee
things to do or avoid while taking clomid BeneЕЎovГЎ M, TrejbalovГЎ K, KovГЎЕ™ovГЎ D, VernerovГЎ Z, Hron T, KuДЌerovГЎ D, Hejnar J
Trounse
However, in most cases, distant metastases have occurred at the time of diagnosis priligy united states Chronic kidney disease is a key risk factor for severe COVID 19 a call to action by the ERA EDTA
GADLELO
The first 24 hour dose may be individualized for each patient; however, in controlled clinical trials, mean daily doses above 2100 mg were associated with an increased risk of hypotension buy lasix online
Prierse
tamoxifen shopping Phase II trial of paclitaxel in patients with progressive ovarian carcinoma after platinum based chemotherapy a Gynecologic Oncology Group study
Prierse
Population, Intervention, Comparison, Outcomes, and Time are present lasix no prescription 5 were resistant, respectively
GADLELO
Easy to use Slow down the growth of cancer cells Accurate formulation buy cialis viagra Centchroman has been resolved into its and antipodes
ameseeNow
I think my body is healing itself buy ivermectin pills online
pippeferi
Maybe you ll be lucky and experience negligible SEs what is priligy
rorpAgera
Стана ви интересно със системите на известните математици ?! И аз проявявах същото любопитство във времената, когато опознавах широкоспектърния свят на рулетката. В следващата статия ще ви разкажа за „система Лабушер”, а дотогава може да си припомните методите на залагане, които научихме дотук: Вземи желания продукт сега, избери подходяща за теб схема на изплащане: +359883227772 Като заключителна част можем да кажем, че рулетката е най-вероятно една от най-интересните игри за казина, които може да намерите. Ако се случи че искате да играете рулетка, разбира се най-добрият начин за вас би бил да подберете добра стратегия, която ще ви помогне допълнително. Не забравяйте да се уповавате на методите посочени в тази статия и се възползвайте от най-добрите стратегии. https://careforfuture.org.uk/Forum/profile/gjtmathew536320 03 октомври 2022 В слотовете няма системи, които да ви гарантират постоянното образуване на печеливши комбинации. Получаването на печалби в Hot Slot 40 и други машини зависи от вашия късмет. За да увеличите шансовете си, могат да ви помогнат следните стратегии за управление на баланса ви в играта: Ще успеят ли политическите сили да сформитар правителство? Някой от най-обичаните игри с 40 линии в България са 40 Mega Slot, 40 Super Hot, Flaming Hot, Stardust и др. Новини на Sharecast | Mar 29, 2021