コード例 #1
0
ファイル: GraphEditorWindow.cs プロジェクト: zcvdf/FlatNode
        public static void ShowWindow()
        {
            GraphEditorWindow graphEditorWindow = GetWindow <GraphEditorWindow>();

            graphEditorWindow.minSize      = new Vector2(800, 600);
            graphEditorWindow.titleContent = new GUIContent("FlatNode编辑器");
        }
コード例 #2
0
        public CommentBoxView(GraphEditorWindow graph, Vector2 startPositionInGraph, Vector2 endPositionInGraph)
        {
            this.graph  = graph;
            rectInGraph = new Rect(startPositionInGraph,
                                   new Vector2(endPositionInGraph.x - startPositionInGraph.x, endPositionInGraph.y - startPositionInGraph.y));

            rectInWindow.position = graph.GraphPositionToWindowPosition(rectInGraph.position);
            rectInWindow.max      = graph.GraphPositionToWindowPosition(rectInGraph.max);
        }
コード例 #3
0
        public static void DrawDraggingCommentBox(GraphEditorWindow graph, Vector2 startPositionInGraph,
                                                  Vector2 endPositionInGraph)
        {
            Vector2 startPositionInWindow = graph.GraphPositionToWindowPosition(startPositionInGraph);
            Vector2 endPositionInWindow   = graph.GraphPositionToWindowPosition(endPositionInGraph);

            Rect drawRect = new Rect(startPositionInWindow,
                                     new Vector2(endPositionInWindow.x - startPositionInWindow.x, endPositionInWindow.y - startPositionInWindow.y));

            GUI.DrawTexture(drawRect, Utility.GetCommentBoxTexture(), ScaleMode.StretchToFill, true);
        }
コード例 #4
0
        public CommentBoxView(GraphEditorWindow graph, Vector2 startPositionInGraph, Vector2 endPositionInGraph, string comment)
        {
            this.graph  = graph;
            rectInGraph = new Rect(startPositionInGraph,
                                   new Vector2(endPositionInGraph.x - startPositionInGraph.x, endPositionInGraph.y - startPositionInGraph.y));

            rectInWindow.position = graph.GraphPositionToWindowPosition(rectInGraph.position);
            rectInWindow.max      = graph.GraphPositionToWindowPosition(rectInGraph.max);
            UpdateHeadRect();

            this.comment = comment;
        }
コード例 #5
0
        private static NodeEditorView ParseNodeInfo(NodeConfigInfo nodeConfigInfo, GraphEditorWindow graph)
        {
            string nodeTypeName = nodeConfigInfo.nodeClassTypeName;
            Type   nodeType     = Type.GetType(nodeTypeName + ",Assembly-CSharp");

            if (nodeType == null)
            {
                Debug.LogErrorFormat("无法载入类型{0} ,该节点被跳过", nodeTypeName);
                return(null);
            }

            NodeReflectionInfo reflectionInfo = new NodeReflectionInfo(nodeType);
            NodeEditorView     nodeView       =
                new NodeEditorView(nodeConfigInfo.positionInGraph, graph, nodeConfigInfo.nodeId, reflectionInfo);

            return(nodeView);
        }
コード例 #6
0
        private void OnGUI()
        {
            instance = this;


            //初始化
            if (supportTypeNames == null)
            {
                supportTypeNames = new string[supportTypeList.Count];

                for (int i = 0; i < supportTypeList.Count; i++)
                {
                    supportTypeNames[i] = Utility.BeautifyTypeName(supportTypeList[i]);
                }
            }

            //draw title
            GUILayout.Label("行为图属性", Utility.GetGuiStyle("Title"));
            GUILayout.Space(10);

            GraphEditorWindow graphEditorWindow = GraphEditorWindow.instance;

            if (graphEditorWindow == null || graphEditorWindow.data == null)
            {
                GUILayout.Label("请先打开行为图编辑器窗口", Utility.GetGuiStyle("SkillGraphName"));
                return;
            }

            data = graphEditorWindow.data;

            DrawToolButtons();

            GUILayout.Space(30);

            DrawLocalVariableItemList();
        }
コード例 #7
0
ファイル: GraphEditorWindow.cs プロジェクト: zcvdf/FlatNode
 private void OnDestroy()
 {
     instance = null;
 }
コード例 #8
0
ファイル: GraphEditorWindow.cs プロジェクト: zcvdf/FlatNode
 private void OnEnable()
 {
     instance = this;
     data     = new GraphEditorData();
     Reset();
 }
コード例 #9
0
        private static CommentBoxView ParseCommentBoxInfo(CommentBoxInfo commentBoxInfo, GraphEditorWindow graph)
        {
            Vector2 startPositionInGraph = commentBoxInfo.positionInGraph;
            Vector2 boxSize            = commentBoxInfo.size;
            Vector2 endPositionInGraph = new Vector2(startPositionInGraph.x + boxSize.x, startPositionInGraph.y + boxSize.y);

            CommentBoxView commentBoxView =
                new CommentBoxView(graph, startPositionInGraph, endPositionInGraph, commentBoxInfo.comment);

            return(commentBoxView);
        }
コード例 #10
0
        public static GraphEditorData LoadGraph(GraphEditorWindow graph, int graphId)
        {
            GraphEditorData resultData = new GraphEditorData();

            string graphEditorConfigFilePath = Path.Combine(Application.dataPath,
                                                            string.Format("FlatNode/Editor/GraphSavedConfig/{0}.json", graphId));

            if (!File.Exists(graphEditorConfigFilePath))
            {
                Debug.LogErrorFormat("无法载入行为图配置文件: {0}", graphEditorConfigFilePath);
            }

            string          jsonString      = File.ReadAllText(graphEditorConfigFilePath);
            GraphConfigInfo graphConfigInfo = new GraphConfigInfo();

            EditorJsonUtility.FromJsonOverwrite(jsonString, graphConfigInfo);

            //处理注释框
            for (int i = 0; i < graphConfigInfo.commentBoxInfoList.Count; i++)
            {
                CommentBoxInfo commentBoxInfo = graphConfigInfo.commentBoxInfoList[i];
                CommentBoxView commentBoxView = ParseCommentBoxInfo(commentBoxInfo, graph);

                resultData.commentBoxViewList.Add(commentBoxView);
            }

            //变量
            for (int i = 0; i < graphConfigInfo.graphVariableInfoList.Count; i++)
            {
                if (!graphConfigInfo.graphVariableInfoList[i].Validate())
                {
                    continue;
                }

                resultData.graphVariableInfoList.Add(graphConfigInfo.graphVariableInfoList[i].OnDeserialized());
            }

            //如果有节点无法解析出来(可能是改了类名称之类的),则需要跳过这些节点
            HashSet <int> errorNodeIndexSet = new HashSet <int>();

            //首先将所有的节点都生成
            for (int i = 0; i < graphConfigInfo.nodesList.Count; i++)
            {
                NodeEditorView nodeView = ParseNodeInfo(graphConfigInfo.nodesList[i], graph);
                if (nodeView == null)
                {
                    errorNodeIndexSet.Add(i);
                    continue;
                }

                resultData.nodeList.Add(nodeView);
            }

            //然后再将所有节点的内容写进去,将节点连起来
            int nodeIndex = 0;

            for (int i = 0; i < graphConfigInfo.nodesList.Count; i++)
            {
                if (errorNodeIndexSet.Contains(i))
                {
                    //skip
                    continue;
                }

                UpdateNodeViewData(graphConfigInfo.nodesList[i], resultData.nodeList[nodeIndex], resultData);
                nodeIndex++;
            }

            resultData.graphId          = graphConfigInfo.graphId;
            resultData.graphName        = graphConfigInfo.graphName;
            resultData.graphDescription = graphConfigInfo.graphDescription;

            return(resultData);
        }
コード例 #11
0
        public NodeEditorView(Vector2 graphPosition, GraphEditorWindow graph, int nodeId, NodeReflectionInfo reflectionInfo)
        {
            this.graph          = graph;
            this.NodeId         = nodeId;
            this.ReflectionInfo = reflectionInfo;

            PositionInGraph  = graphPosition;
            PositionInWindow = graph.GraphPositionToWindowPosition(graphPosition);

            viewRect = new Rect(Vector2.zero, new Vector2(200, 400));

            allPortList        = new List <PortEditorView>();
            inputPortViewList  = new List <InputPortEditorView>();
            outputPortViewList = new List <OutputPortEditorView>();

            leftPortLayoutHelper  = new PortLayoutHelper();
            rightPortLayoutHelper = new PortLayoutHelper();

            if (reflectionInfo.HasFlowInPort)
            {
                flowInPortView        = new FlowInPortEditorView(this);
                flowInPortView.portId = 0;
                allPortList.Add(flowInPortView);
            }

            if (reflectionInfo.flowOutPortDefineAttributes.Length > 0)
            {
                flowOutPortViews = new FlowOutPortEditorView[reflectionInfo.flowOutPortDefineAttributes.Length];
                for (int i = 0; i < flowOutPortViews.Length; i++)
                {
                    flowOutPortViews[i]        = new FlowOutPortEditorView(this, reflectionInfo.flowOutPortDefineAttributes[i]);
                    flowOutPortViews[i].portId = i;
                    allPortList.Add(flowOutPortViews[i]);
                }
            }
            else
            {
                flowOutPortViews = new FlowOutPortEditorView[0];
            }

            List <InputPortReflectionInfo> inputPortReflectionInfos = reflectionInfo.inputPortInfoList;

            for (int i = 0; i < inputPortReflectionInfos.Count; i++)
            {
                InputPortReflectionInfo inputPortReflectionInfo = inputPortReflectionInfos[i];
                InputPortEditorView     inputPortView           = new InputPortEditorView(this, inputPortReflectionInfo);
                inputPortView.portId = i;

                inputPortViewList.Add(inputPortView);
                allPortList.Add(inputPortView);
            }

            List <OutputPortReflectionInfo> outputPortReflectionInfos = reflectionInfo.outputPortInfoList;

            for (int i = 0; i < outputPortReflectionInfos.Count; i++)
            {
                OutputPortReflectionInfo outputPortReflectionInfo = outputPortReflectionInfos[i];
                OutputPortEditorView     outputPortView           = new OutputPortEditorView(this, outputPortReflectionInfo, i);
                outputPortView.portId = i;

                outputPortViewList.Add(outputPortView);
                allPortList.Add(outputPortView);
            }

            CalculateNodeSize();
        }