public void UpdateNode(ScriptNodeData node)
 {
     for (int i = 0; i < list.Count; ++i)
     {
         if (list[i].id == node.id)
         {
             list[i] = node;
             break;
         }
     }
 }
        public static ScriptGraphNode Deserialze(ScriptNodeData data)
        {
            ScriptGraphNode node = CreateNode(data);

            if (node == null)
            {
                Debug.LogError("node is null. type = " + data.type.ToString());
                return(null);
            }

            return(node);
        }
        public void AddNode(ScriptNodeData node)
        {
            for (int i = 0; i < list.Count; ++i)
            {
                if (list[i].id == node.id)
                {
                    list[i] = node;
                    return;
                }
            }

            list.Add(node);
        }
        private static ScriptGraphNode CreateNode(ScriptNodeData data)
        {
            ScriptGraphNode node;
            ByteArrayStream stream = new ByteArrayStream(data.serialData);

            switch (data.type)
            {
            case NodeType.Root:
            {
                node = new RootNode();
            }
            break;

            case NodeType.Message:
            {
                node = new MessageNode();
                var temp = node as MessageNode;
                temp.text = stream.ReadString();
            }
            break;

            case NodeType.Branch:
            {
                node = new BranchNode();
                var temp = node as BranchNode;
                temp.flag = stream.ReadBool();
            }
            break;

            case NodeType.None:
            default:
                node = null;
                break;
            }

            SetCommonData(node, data);

            return(node);
        }
        public static ScriptNodeData Serialize(ScriptGraphNode node)
        {
            ScriptNodeData data = new ScriptNodeData();

            data.id     = node.id;
            data.type   = node.Type;
            data.outIds = node.outIds.ToArray();
            data.rect   = node.GetPosition();

            ByteArrayStream stream = new ByteArrayStream();

            switch (node.Type)
            {
            case NodeType.Root:
                break;

            case NodeType.Message:
                Serialize(node as MessageNode, ref stream);
                break;

            case NodeType.Branch:
                Serialize(node as BranchNode, ref stream);
                break;

            case NodeType.None:
            default:
            {
                Debug.LogError("Invalid Node Type :" + node.Type.ToString());
            }
            break;
            }

            data.serialData = stream.GetBuffer();

            return(data);
        }
 private static void SetCommonData(ScriptGraphNode node, ScriptNodeData data)
 {
     node.id = data.id;
     node.outIds.AddRange(data.outIds);
     node.SetPosition(data.rect);
 }