unity自定义节点编辑器 GraphView
这篇还可以
https://blog.csdn.net/dmk17771552304/article/details/121499476
using System.Linq;
using UnityEngine;
using UnityEditor.Experimental.GraphView; public class LogNode : ProcessNode
{
private Port inputString; public LogNode() : base()
{
title = "Log"; inputString = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(string));
inputContainer.Add(inputString);
} public override void Execute()
{
var edge = inputString.connections.FirstOrDefault();
var node = edge.output.node as StringNode; if (node == null) return; Debug.Log(node.Text);
}
}
using UnityEditor.Experimental.GraphView; public abstract class ProcessNode : SampleNode
{
public Port InputPort;
public Port OutputPort; public ProcessNode()
{
InputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(Port));
InputPort.portName = "In";
inputContainer.Add(InputPort); OutputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(Port));
OutputPort.portName = "Out";
outputContainer.Add(OutputPort);
} public abstract void Execute();
}
using System.Linq;
using UnityEditor.Experimental.GraphView; public class RootNode : SampleNode
{
public Port OutputPort; public RootNode() : base()
{
title = "Root"; capabilities -= Capabilities.Deletable; OutputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(Port));
OutputPort.portName = "Out";
outputContainer.Add(OutputPort);
} //------------------------------------- }
using System.Linq;
using UnityEditor;
using UnityEngine.UIElements; public class SampleGraphEditorWindow : EditorWindow { [MenuItem("Window/Open SampleGraphView")]
public static void Open()
{
GetWindow<SampleGraphEditorWindow>("SampleGraphView");
} void OnEnable()
{
var graphView = new SampleGraphView()
{
style = { flexGrow = 1 }
};
rootVisualElement.Add(graphView); rootVisualElement.Add(new Button(graphView.Execute) { text = "Execute" });
}
}
using System.Collections.Generic;
using System.Linq;
using UnityEditor.Experimental.GraphView;
using UnityEngine;
using UnityEngine.UIElements; public class SampleGraphView : GraphView
{
public RootNode root; public SampleGraphView()
{
SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale); Insert(0, new GridBackground()); //AddElement(new SampleNode());
this.AddManipulator(new SelectionDragger()); var searchWindowProvider = ScriptableObject.CreateInstance<SampleSearchWindowProvider>();
searchWindowProvider.Initialize(this); root = new RootNode();
AddElement(root); nodeCreationRequest += context =>
{
SearchWindow.Open(new SearchWindowContext(context.screenMousePosition), searchWindowProvider);
};
} public override List<Port> GetCompatiblePorts(Port startAnchor, NodeAdapter nodeAdapter)
{
var compatiblePorts = new List<Port>();
foreach (var port in ports.ToList())
{
if (startAnchor.node == port.node ||
startAnchor.direction == port.direction ||
startAnchor.portType != port.portType)
{
continue;
} compatiblePorts.Add(port);
}
return compatiblePorts;
} public void Execute()
{
var rootEdge = root.OutputPort.connections.FirstOrDefault();
if (rootEdge == null) return; var currentNode = rootEdge.input.node as ProcessNode; while (true)
{
currentNode.Execute(); var edge = currentNode.OutputPort.connections.FirstOrDefault();
if (edge == null) break; currentNode = edge.input.node as ProcessNode;
}
}
}
using UnityEditor.Experimental.GraphView; public class SampleNode : Node
{
public SampleNode()
{
title = "Sample"; var inputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Input, Port.Capacity.Single, typeof(Port));
inputContainer.Add(inputPort); var outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Single, typeof(Port));
outputContainer.Add(outputPort);
}
}
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor.Experimental.GraphView; public class SampleSearchWindowProvider : ScriptableObject, ISearchWindowProvider
{
private SampleGraphView graphView; public void Initialize(SampleGraphView graphView)
{
this.graphView = graphView;
} List<SearchTreeEntry> ISearchWindowProvider.CreateSearchTree(SearchWindowContext context)
{
var entries = new List<SearchTreeEntry>();
entries.Add(new SearchTreeGroupEntry(new GUIContent("Create Node"))); foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach (var type in assembly.GetTypes())
{
if (type.IsClass && !type.IsAbstract && (type.IsSubclassOf(typeof(SampleNode)))
&& type != typeof(RootNode))
{
entries.Add(new SearchTreeEntry(new GUIContent(type.Name)) { level = 1, userData = type });
}
}
} return entries;
} bool ISearchWindowProvider.OnSelectEntry(SearchTreeEntry searchTreeEntry, SearchWindowContext context)
{
var type = searchTreeEntry.userData as System.Type;
var node = Activator.CreateInstance(type) as SampleNode;
graphView.AddElement(node);
return true;
}
}
using UnityEngine.UIElements;
using UnityEditor.Experimental.GraphView; public class StringNode : SampleNode
{
private TextField textField;
public string Text { get { return textField.value; } } public StringNode() : base()
{
title = "String"; var outputPort = Port.Create<Edge>(Orientation.Horizontal, Direction.Output, Port.Capacity.Multi, typeof(string));
outputContainer.Add(outputPort); textField = new TextField();
mainContainer.Add(textField);
}
}
unity自定义节点编辑器 GraphView的更多相关文章
- [Unity]自定义地图编辑器(Scene视图下,EditorWindow的简单应用)
最近的游戏又很多关卡需要配置(XML保存),给策划写了个非常简单的编辑器,记录下+废话下 1:Editor下打开新窗口需要继承EditorWindow,然后使用获取窗口即可,注意放在Editor文件夹 ...
- 用mel编写自定义节点的属性编辑器界面
用mel编写自定义节点的属性编辑器界面比较麻烦,而且网上例子又少,下面给出一个范例,说明基本的格式 // 初始化节点时调用 global proc initControl(string $attrNa ...
- Fabric Engine2.0的自定义节点功能
Fabric Engine是一个多用途的引擎,针对maya等软件写节点写功能很方便.尤其是canvas节点编辑面板,提供了大量现有的功能供用户调用,当然这些节点功能都是可被用户编辑修改的,除此之外还提 ...
- (转)Unity笔记之编辑器(UnityEditor)
在使用unity3d的过程中,时常会需要从场景中寻找或者调用一个对象,而Unity就提供了一个贴心的功能——拖拽.用鼠标拖一下中比写堆代码直观的多吧!但是Unity提供的远远不止这一丢丢,下面我们来简 ...
- 使用 TypeScript,React,ANTLR 和 Monaco Editor 创建一个自定义 Web 编辑器(二)
译文来源 欢迎阅读如何使用 TypeScript, React, ANTLR4, Monaco Editor 创建一个自定义 Web 编辑器系列的第二章节, 在这之前建议您阅读使用 TypeScrip ...
- WebConfig 自定义节点configSections配置信息
WebConfig 自定义节点configSections配置信息 示例: <configuration> <configSections> <!-- For ...
- Web.config自定义节点configSections
1.为什么需要自定义节点 为了增加应用程序的可移植性,通常网站需要配置一些自定义的节点,例如:文件上传的路径等,再深入的应用,可以定义工厂方法需要创建的类. 2.configSections使用方法 ...
- springmvc自定义日期编辑器
1.控制器 @Controller public class MyController { // 处理器方法 @RequestMapping(value = "/first.do" ...
- (Unity)Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进展混淆,避免被反编译
Unity自定义Debug日志文件,利用VS生成Dll文件并使用Dotfuscated进行混淆,避免被反编译. 1.打开VS,博主所用版本是Visual Studio 2013. 2.新建一个VC项目 ...
- Spring源码情操陶冶-自定义节点的解析
本文承接前文Spring源码情操陶冶-DefaultBeanDefinitionDocumentReader#parseBeanDefinitions,特开辟出一块新地来啃啃这块有意思的骨头 自定义节 ...
随机推荐
- 【经验】CiteSpace|Wiley Online Library或除知网以外的其他网站的文献怎么导入CiteSpace 6.1.6?
如果没安装,请看这篇博客安装,现在新版(6.1.6)的不需要额外下载java了,就很妙~: 最新版citespace软件的安装与配置 结论:导出成RIS然后用它自带的转换成WoS. 文章目 ...
- 仿EXCEL插件,智表ZCELL产品V3.0 版本发布,底层采用canvas全部重构,功能大幅扩展,性能极致提升,满足千万级单元格加载
本次更新是底层全部重构,按照现代浏览器要求,采用canvas方式进行了重构,预留了将来扩展空间,特别是在大数据量性能提升方面有了较大提升,可以满足千万级单元格加载,欢迎大家体验使用. 体验地址:zce ...
- 仿EXCEL插件,智表ZCELL产品V2.2 版本发布,增加获取单元格类型、样式功能,优化键盘事件、数值千分位等功能
详细请移步 智表(ZCELL)官网www.zcell.net 更新说明 这次更新主要应用户要求,增加获取单元格类型.样式功能,优化键盘事件.数值千分位等功能 ,欢迎大家体验使用. 本次版本更新内容如 ...
- vue3 基础-API-响应式 ref, reactive
上篇咱介绍了 CompositionAPI, 其核心思想是直接在函数作用域内定义响应式状态变量,并将从多个函数中得到的状态组合起来处理复杂问题. 然后初介绍了 setup 函数的作用, 即其是在 cr ...
- 网络编程:TCP故障模式
故障模式总结 异常情况可归结为两大类: 第一类,是对端无FIN包发送出来的情况:第二类是对端有FIN包发出来 对端无FIN包发送出 网络终端造成对端无FIN包 很多原因都会造成网络中断,这种情况,TC ...
- win10无选字框
设置-->时间与语言-->语言-->中文-->选项 下滑到最底 微软拼音-->选项 常规-->(下滑到最底)打开使用以前版本的微软拼音输入法-->确定
- 2003 can't connect to mysql server on
把配置文件my.ini换成如下所示: mysql和mysql数据存放路径都是加双斜线 [mysql] # 设置mysql客户端默认字符集 default-character-set=utf8 [mys ...
- 虚拟机搭建CDH6详细过程_三节点为例
准备工作 一.安装虚拟机.centos 1.安装VMwareWorkstation虚拟化软件 首先我们使用VMwareWorkstation来快速的进行虚拟机的新建. 本文使用的版本为VMwareWo ...
- Java 下载网络资源
从网络URL下载文件到指定目录,自适应文件类型,并且重命名下载后的文件名.这里使用XtremePapers如下URL的网络资源作为测试文件: https://papers.xtremepape.rs/ ...
- 【中文】【吴恩达课后编程作业】Course 5 - 序列模型 - 第三周作业 - 机器翻译与触发词检测
[中文][吴恩达课后编程作业]Course 5 - 序列模型 - 第三周作业 - 机器翻译与触发词检测 上一篇:[课程5 - 第三周测验]※※※※※ [回到目录]※※※※※下一篇:无 致谢: 感谢@e ...