Unity编辑器拓展(GraphView制作对话系统编辑器)

Posted 萧寒大大

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Unity编辑器拓展(GraphView制作对话系统编辑器)相关的知识,希望对你有一定的参考价值。

1.介绍

1.无限的分支和合并的对话能力。
2.对话框、图形保存/加载系统。
3.小地图,便于导航。
4.有节点创建的搜索窗口。
5.黑板填写属性值。
6.用于分组节点的注释块。
7.由Unity的嵌入式GraphView API支持。
8.在压缩包中提供完整demo和代码注释。 

 

2.基础知识

 1.GraphView

Experimental.GraphView.GraphView - Unity 脚本 APIhttps://docs.unity.cn/cn/current/ScriptReference/Experimental.GraphView.GraphView.html2.UIElement

Unity2019 UIElement 笔记(一)创建脚本_工 具 人-CSDN博客https://blog.csdn.net/qq_43500611/article/details/89604455

3.Node

Experimental.GraphView.Node - Unity 脚本 APIhttps://docs.unity.cn/cn/current/ScriptReference/Experimental.GraphView.Node.html

3.部分代码示例

       public StoryGraphView(StoryGraph editorWindow)
       
            //网格绘制
            styleSheets.Add(Resources.Load<StyleSheet>("NarrativeGraph"));
            SetupZoom(ContentZoomer.DefaultMinScale, ContentZoomer.DefaultMaxScale);

            this.AddManipulator(new ContentDragger());
            this.AddManipulator(new SelectionDragger());
            this.AddManipulator(new RectangleSelector());
            this.AddManipulator(new FreehandSelector());

            var grid = new GridBackground();
            Insert(0, grid);
            grid.StretchToParentSize();

            //开始节点
            AddElement(GetEntryPointNodeInstance());
            //搜索窗口
            AddSearchWindow(editorWindow);
        
 /// <summary>
        /// 工具栏绘制
        /// </summary>
        private void GenerateToolbar()
        
            var toolbar = new Toolbar();

            var fileNameTextField = new TextField("File Name:");
            fileNameTextField.SetValueWithoutNotify(_fileName);
            fileNameTextField.MarkDirtyRepaint();
            fileNameTextField.RegisterValueChangedCallback(evt => _fileName = evt.newValue);
            toolbar.Add(fileNameTextField);

            toolbar.Add(new Button(() => RequestDataOperation(true)) text = "Save Data");

            toolbar.Add(new Button(() => RequestDataOperation(false)) text = "Load Data");
            // toolbar.Add(new Button(() => _graphView.CreateNewDialogueNode("Dialogue Node")) text = "New Node",);
            rootVisualElement.Add(toolbar);
        


/// <summary>
        /// 小地图绘制
        /// </summary>
        private void GenerateMiniMap()
        
            var miniMap = new MiniMap anchored = true;
            var cords = _graphView.contentViewContainer.WorldToLocal(new Vector2(this.maxSize.x - 10, 30));
            miniMap.SetPosition(new Rect(cords.x, cords.y, 200, 140));
            _graphView.Add(miniMap);
        


/// <summary>
        /// 小黑板绘制
        /// </summary>
        private void GenerateBlackBoard()
        
            var blackboard = new Blackboard(_graphView);
            blackboard.Add(new BlackboardSection title = "Exposed Variables");
            blackboard.addItemRequested = _blackboard =>
            
                _graphView.AddPropertyToBlackBoard(ExposedProperty.CreateInstance(), false);
            ;
            blackboard.editTextRequested = (_blackboard, element, newValue) =>
            
                var oldPropertyName = ((BlackboardField) element).text;
                if (_graphView.ExposedProperties.Any(x => x.PropertyName == newValue))
                
                    EditorUtility.DisplayDialog("Error", "This property name already exists, please chose another one.",
                        "OK");
                    return;
                

                var targetIndex = _graphView.ExposedProperties.FindIndex(x => x.PropertyName == oldPropertyName);
                _graphView.ExposedProperties[targetIndex].PropertyName = newValue;
                ((BlackboardField) element).text = newValue;
            ;
            blackboard.SetPosition(new Rect(10,30,200,300));
            _graphView.Add(blackboard);
            _graphView.Blackboard = blackboard;
        

代码资源下载地址

Unity对话系统编辑器-互联网文档类资源-CSDN文库https://download.csdn.net/download/m0_46712616/46797276

以上是关于Unity编辑器拓展(GraphView制作对话系统编辑器)的主要内容,如果未能解决你的问题,请参考以下文章

Unity3D插件使用AnyPortrait插件制作角色动画(AnyPortrait插件教程)

Unity3D插件AnyPortrait二维角色动画编辑器插件教程分享

Unity的GraphView

UNITY3D拓展编辑器 - 目录

Unity编辑器拓展最全实现

(转 )Unity对Lua的编辑器拓展