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,特开辟出一块新地来啃啃这块有意思的骨头 自定义节 ...
随机推荐
- 阿里云Ansible自动化运维平台部署
以下是在阿里云平台上基于Ansible实现自动化运维的完整实践指南,整合所有核心操作流程和命令,适配指定的服务器规划: 一.环境规划 主机名 IP地址 角色 操作系统 manage01 192.168 ...
- 如何在 Linux 上检查开放的端口并关闭不需要的端口
检查服务器开放端口并关闭不必要的端口是网络安全管理中的关键环节,开放端口如同服务器的"窗口",若其中存在未被利用或未受保护的端口,就如同为潜在的攻击者敞开了大门,他们可能会利用这些 ...
- SQL 强化练习 (四)
继续每日一练 sql 肯定会无敌强的后面. 恰好今天项目弄报表这块, 用了国产的 BI 工具, 帆软Report, 除了页面控件做得有些 low 外, 我感觉其他各方面都特别适合做 中国式的报表. 明 ...
- JavaScript 从零实现物理模拟
@charset "UTF-8"; .markdown-body { line-height: 1.75; font-weight: 400; font-size: 15px; o ...
- 【.NET必读】RabbitMQ 4.0+重大变更!C#开发者必须掌握的6大升级要点
RabbitMQ 作为一款广受欢迎的消息队列中间件,近年来从 3.x 版本升级到 4.0+,带来了显著的功能增强和架构调整.与此同时,其官方 C# 客户端也从 6.x 版本跃升至 7.0,引入了全新的 ...
- 【语义分割专栏】:FCN实战篇(附上完整可运行的代码pytorch)
目录 前言 FCN全流程代码 模型搭建(model) 数据处理(dataloader) 评价指标(metric) 训练流程(train) 模型测试(test) 效果图 结语 前言 FCN原理篇讲解:[ ...
- 必看!手把手教你玩转Dify的3大核心工具!
Dify 中的工具是指其平台内置或支持集成的功能插件,用于扩展 AI 应用的能力. 1.工具作用 扩展 LLM 的能力:工具可以赋予 LLM 连接外部世界的能力,例如联网搜索.科学计算.绘制图片等.例 ...
- MySQL设置字符集、排序规则和区分字母大小
摘要:在MySQL中,设置字符集和排序规则,在查询时区分字母大小写,utf8mb4支持emoji表情,而utf8不支持. 问题综述 在工作中,设置的一些唯一标志字符串和登录密码都是区分大小写的,但 ...
- python C3算法
Python MRO C3算法是python当中计算类继承顺序的一个算法,从python2.3以后就一直使用此算法了. c3 linearization算法称为c3线性化算法 C3算法原理 首先定义几 ...
- 知名开源项目Alist被收购!惹程序员众怒,开团炮轰甲方
知名开源网盘项目 Alist 被黑产收购?涉及泄露用户隐私?众多开发者成为黑奴?程序员集体炮轰项目评论区? 听起来还挺炸裂的,作为一名程序员,带大家扒一扒这个事件的来龙去脉. 什么是 Alist? A ...