Exemplo n.º 1
0
        private void SaveNodes()
        {
            string path = OutPutNodesPath + SavePath;

            File.WriteAllBytes(path, VisualGraphData.Write(GraphData));
            AssetDatabase.Refresh();
        }
Exemplo n.º 2
0
 private void SetSelectTextAsset(TextAsset textAsset)
 {
     byte[] bytes = textAsset.bytes;
     if (bytes != null && bytes.Length > 0)
     {
         GraphData = VisualGraphData.Read(bytes);
         GraphData.Link();
         WindowOffset = Vector2.zero;
         var path = AssetDatabase.GetAssetPath(textAsset);
         SavePath = path;
     }
 }
Exemplo n.º 3
0
        void LoadNode()
        {
            var path = EditorUtility.OpenFilePanel("select a node file", OutPutNodesPath + DefaultNodesPath, "bytes");

            Debug.Log(path);
            var       assetPath = path.Replace(Application.dataPath.Replace("Assets", ""), "");
            TextAsset txtAsset  = AssetDatabase.LoadAssetAtPath <TextAsset>(assetPath);

            if (txtAsset.bytes != null && txtAsset.bytes.Length > 0)
            {
                var gd = VisualGraphData.Read(txtAsset.bytes);
                gd.Link();
                Nodes.AddRange(gd.Nodes);
            }
            SavePath = assetPath;
        }
Exemplo n.º 4
0
        public static VisualGraphData Read(byte[] bytes)
        {
            VisualGraphData data  = new VisualGraphData();
            ByteBuffer      bfs   = new ByteBuffer(bytes);
            int             count = bfs.ReadInt32();

            for (int i = 0; i < count; ++i)
            {
                VisualNode.NodeType type = (VisualNode.NodeType)bfs.ReadShort();
                if (type == VisualNode.NodeType.SetVar)
                {
                    data.AddNode(SetVarNode.Read(bfs.ReadBytes()));
                }
                else if (type == VisualNode.NodeType.GetVar)
                {
                    data.AddNode(GetVarNode.Read(bfs.ReadBytes()));
                }
                else if (type == VisualNode.NodeType.Func)
                {
                    data.AddNode(FuncNode.Read(bfs.ReadBytes()));
                }
                else if (type == VisualNode.NodeType.AddOp)
                {
                    data.AddNode(AddOpNode.Read(bfs.ReadBytes(), new AddOpNode()));
                }
                else if (type == VisualNode.NodeType.MinusOp)
                {
                    data.AddNode(MinusOpNode.Read(bfs.ReadBytes(), new MinusOpNode()));
                }
                else if (type == VisualNode.NodeType.MultiplyOp)
                {
                    data.AddNode(MultiplyOpNode.Read(bfs.ReadBytes(), new MultiplyOpNode()));
                }
                else if (type == VisualNode.NodeType.DivisionOp)
                {
                    data.AddNode(DivisionOpNode.Read(bfs.ReadBytes(), new DivisionOpNode()));
                }
                else if (type == VisualNode.NodeType.Proc)
                {
                    data.AddNode(ProcNode.Read(bfs.ReadBytes()));
                }
            }
            return(data);
        }
Exemplo n.º 5
0
        public static byte[] Write(VisualGraphData data)
        {
            ByteBuffer bfs = new ByteBuffer();

            bfs.WriteInt32(data.Nodes.Count);
            for (int i = 0; i < data.Nodes.Count; ++i)
            {
                var d = data.Nodes[i];
                bfs.WriteShort((short)d.GetNodeType());
                if (d.GetNodeType() == VisualNode.NodeType.SetVar)
                {
                    bfs.WriteBytes(SetVarNode.Write(d as SetVarNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.GetVar)
                {
                    bfs.WriteBytes(GetVarNode.Write(d as GetVarNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.Func)
                {
                    bfs.WriteBytes(FuncNode.Write(d as FuncNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.AddOp)
                {
                    bfs.WriteBytes(AddOpNode.Write(d as AddOpNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.MinusOp)
                {
                    bfs.WriteBytes(MinusOpNode.Write(d as MinusOpNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.MultiplyOp)
                {
                    bfs.WriteBytes(MultiplyOpNode.Write(d as MultiplyOpNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.DivisionOp)
                {
                    bfs.WriteBytes(DivisionOpNode.Write(d as DivisionOpNode));
                }
                else if (d.GetNodeType() == VisualNode.NodeType.Proc)
                {
                    bfs.WriteBytes(ProcNode.Write(d as ProcNode));
                }
            }
            return(bfs.Getbuffer());
        }