コード例 #1
0
ファイル: StateNode.cs プロジェクト: zh880517/UnityLib
 public void OnBeforeSerialize()
 {
     if (nodeData != null)
     {
         serializeData = TypeSerializerHelper.Serialize(nodeData);
     }
 }
コード例 #2
0
    public bool CopyFrom(StateGraph graph, IEnumerable <StateNodeRef> copyNodes, Vector2 offset)
    {
        List <StateNodeRef> nodes = copyNodes.Where(it => graph.CheckCopy(it)).ToList();

        foreach (var node in nodes)
        {
            NodeData data = new NodeData
            {
                Id       = node.Id,
                Bounds   = node.Node.Bounds,
                Data     = TypeSerializerHelper.Serialize(node.Node.Data),
                Name     = node.Node.Name,
                Comments = node.Node.Comments,
            };
            data.Bounds.position += offset;
            Datas.Add(data);
        }
        foreach (var link in graph.Links)
        {
            if (nodes.Contains(link.From) && nodes.Contains(link.To))
            {
                NodeLink nodeLink = new NodeLink
                {
                    FromIdx = Datas.FindIndex(it => it.Id == link.From.Id),
                    ToIdx   = Datas.FindIndex(it => it.Id == link.To.Id),
                    IsChild = link.IsChild
                };
                Links.Add(nodeLink);
            }
        }
        return(nodes.Count > 0);
    }
コード例 #3
0
ファイル: StateNode.cs プロジェクト: zh880517/UnityLib
 public void Deserialize()
 {
     nodeData = TypeSerializerHelper.Deserialize(serializeData) as IStateNode;
     if (nodeData == null)
     {
         Debug.LogErrorFormat("反序列化时数据为空 => {0}", serializeData);
     }
 }
コード例 #4
0
    public List <StateNode> PasteTo(StateGraph graph, Vector2 offset)
    {
        List <StateNode> creatNodes = new List <StateNode>();

        foreach (var data in Datas)
        {
            var node = graph.AddNode(TypeSerializerHelper.Deserialize(data.Data) as IStateNode, new Rect(data.Bounds.position + offset, data.Bounds.size));
            node.Name     = data.Name;
            node.Comments = data.Comments;
            creatNodes.Add(node);
        }
        foreach (var link in Links)
        {
            graph.AddLink(creatNodes[link.FromIdx], creatNodes[link.ToIdx], link.IsChild);
        }
        return(creatNodes);
    }