Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
        private static CommentBoxInfo ConvertToCommentInfo(CommentBoxView commentBoxView)
        {
            CommentBoxInfo commentBoxInfo = new CommentBoxInfo
            {
                comment         = commentBoxView.comment,
                positionInGraph = commentBoxView.rectInGraph.position,
                size            = commentBoxView.rectInGraph.size
            };

            return(commentBoxInfo);
        }
Exemplo n.º 3
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);
        }