示例#1
0
        public void DeserializeGraphsPart(AstarSerializer sr)
        {
            this.ClearGraphs();
            this.graphs = sr.DeserializeGraphs();
            if (this.graphs != null)
            {
                for (int j = 0; j < this.graphs.Length; j++)
                {
                    if (this.graphs[j] != null)
                    {
                        this.graphs[j].graphIndex = (uint)j;
                    }
                }
            }
            this.userConnections = sr.DeserializeUserConnections();
            sr.DeserializeExtraInfo();
            int i;

            for (i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.graphs[i].GetNodes(delegate(GraphNode node)
                    {
                        node.GraphIndex = (uint)i;
                        return(true);
                    });
                }
            }
            sr.PostDeserialization();
        }
示例#2
0
        /** Deserializes common info.
         * Common info is what is shared between the editor serialization and the runtime serializer.
         * This is mostly everything except the graph inspectors which serialize some extra data in the editor
         */
        public void DeserializeGraphsPart(AstarSerializer sr)
        {
            ClearGraphs();
            graphs = sr.DeserializeGraphs();
            if (graphs != null)
            {
                for (var i = 0; i < graphs.Length; i++)
                {
                    if (graphs[i] != null)
                    {
                        graphs[i].graphIndex = (uint)i;
                    }
                }
            }

            userConnections = sr.DeserializeUserConnections();
            //sr.DeserializeNodes();
            sr.DeserializeExtraInfo();

            //Assign correct graph indices.
            for (var i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] == null)
                {
                    continue;
                }
                graphs[i].GetNodes(delegate(GraphNode node) {
                    node.GraphIndex = (uint)i;
                    return(true);
                });
            }

            sr.PostDeserialization();
        }
示例#3
0
        public void DeserializeGraphsPartAdditive(AstarSerializer sr)
        {
            if (this.graphs == null)
            {
                this.graphs = new NavGraph[0];
            }
            if (this.userConnections == null)
            {
                this.userConnections = new UserConnection[0];
            }
            List <NavGraph> list = new List <NavGraph>(this.graphs);

            list.AddRange(sr.DeserializeGraphs());
            this.graphs = list.ToArray();
            if (this.graphs != null)
            {
                for (int l = 0; l < this.graphs.Length; l++)
                {
                    if (this.graphs[l] != null)
                    {
                        this.graphs[l].graphIndex = (uint)l;
                    }
                }
            }
            List <UserConnection> list2 = new List <UserConnection>(this.userConnections);

            list2.AddRange(sr.DeserializeUserConnections());
            this.userConnections = list2.ToArray();
            sr.DeserializeNodes();
            DebugHelper.Assert(this.graphs != null, "不能为空");
            int i;

            for (i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.graphs[i].GetNodes(delegate(GraphNode node)
                    {
                        node.GraphIndex = (uint)i;
                        return(true);
                    });
                }
            }
            sr.DeserializeExtraInfo();
            sr.PostDeserialization();
            for (int j = 0; j < this.graphs.Length; j++)
            {
                for (int k = j + 1; k < this.graphs.Length; k++)
                {
                    if (this.graphs[j] != null && this.graphs[k] != null && this.graphs[j].guid == this.graphs[k].guid)
                    {
                        Debug.LogWarning("Guid Conflict when importing graphs additively. Imported graph will get a new Guid.\nThis message is (relatively) harmless.");
                        this.graphs[j].guid = Guid.NewGuid();
                        break;
                    }
                }
            }
        }
示例#4
0
 public void DeserializeGraphsPart(AstarSerializer sr)
 {
     this.ClearGraphs();
     this.graphs = sr.DeserializeGraphs();
     if (this.graphs != null)
     {
         for (int i = 0; i < this.graphs.Length; i++)
         {
             if (this.graphs[i] != null)
             {
                 this.graphs[i].graphIndex = (uint)i;
             }
         }
     }
     this.userConnections = sr.DeserializeUserConnections();
     sr.DeserializeExtraInfo();
示例#5
0
        /** Deserializes all graphs and also user connections \deprecated */
        public void DeserializeGraphsPart(AstarSerializer serializer)
        {
            if (serializer.error != AstarSerializer.SerializerError.Nothing) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.Log ("Error encountered : "+serializer.error+"\nWriting data to AstarData.data_backup");
                graphs = new NavGraph[0];
                return;
            }

            try {
                int count1 = serializer.readerStream.ReadInt32 ();
                int count2 = serializer.readerStream.ReadInt32 ();

                if (count1 != count2) {
                    Debug.LogError ("Data is corrupt ("+count1 +" != "+count2+")");
                    graphs = new NavGraph[0];
                    return;
                }

                NavGraph[] _graphs = new NavGraph[count1];
                //graphs = new NavGraph[count1];

                for (int i=0;i<_graphs.Length;i++) {

                    if (!serializer.MoveToAnchor ("Graph"+i)) {
                        Debug.LogError ("Couldn't find graph "+i+" in the data");
                        Debug.Log ("Logging... "+serializer.anchors.Count);
                        foreach (KeyValuePair<string,int> value in serializer.anchors) {
                            Debug.Log ("KeyValuePair "+value.Key);
                        }
                        _graphs[i] = null;
                        continue;
                    }
                    string graphType = serializer.readerStream.ReadString ();

                    graphType = graphType.Replace ("ListGraph","PointGraph");

                    Guid guid = new Guid (serializer.readerStream.ReadString ());

                    //Search for existing graphs with the same GUID. If one is found, that means that we are loading another version of that graph
                    //Use that graph then and just load it with some new settings
                    NavGraph existingGraph = GuidToGraph (guid);

                    if (existingGraph != null) {
                        _graphs[i] = existingGraph;
                        //Replace
                        //graph.guid = new System.Guid ();
                        //serializer.loadedGraphGuids[i] = graph.guid.ToString ();
                    } else {
                        _graphs[i] = CreateGraph (graphType);
                    }

                    NavGraph graph = _graphs[i];

                    if (graph == null) {
                        Debug.LogError ("One of the graphs saved was of an unknown type, the graph was of type '"+graphType+"'");
                        data_backup = data;
                        graphs = new NavGraph[0];
                        return;
                    }

                    _graphs[i].guid = guid;

                    //Set an unique prefix for all variables in this graph
                    serializer.sPrefix = i.ToString ();
                    serializer.DeSerializeSettings (graph,active);
                }

                serializer.SetUpGraphRefs (_graphs);

                for (int i=0;i<_graphs.Length;i++) {

                    NavGraph graph = _graphs[i];

                    if (serializer.MoveToAnchor ("GraphNodes_Graph"+i)) {
                        serializer.mask = serializer.readerStream.ReadInt32 ();
                        serializer.sPrefix = i.ToString ()+"N";
                        serializer.DeserializeNodes (graph,_graphs,i,active);
                        serializer.sPrefix = "";
                    }

                    //Debug.Log ("Graph "+i+" has loaded "+(graph.nodes != null ? graph.nodes.Length.ToString () : "null")+" nodes");

                }

                userConnections = serializer.DeserializeUserConnections ();

                //Remove null graphs
                List<NavGraph> tmp = new List<NavGraph>(_graphs);
                for (int i=0;i<_graphs.Length;i++) {
                    if (_graphs[i] == null) {
                        tmp.Remove (_graphs[i]);
                    }
                }

                graphs = tmp.ToArray ();
            } catch (System.Exception e) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray ();
                Debug.LogWarning ("Deserializing Error Encountered - Writing data to AstarData.data_backup:\n"+e.ToString ());
                graphs = new NavGraph[0];
                return;
            }
        }
示例#6
0
        /** Deserializes all graphs and also user connections \deprecated */
        public void DeserializeGraphsPart(AstarSerializer serializer)
        {
            if (serializer.error != AstarSerializer.SerializerError.Nothing)
            {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray();
                Debug.Log("Error encountered : " + serializer.error + "\nWriting data to AstarData.data_backup");
                graphs = new NavGraph[0];
                return;
            }

            try {
                int count1 = serializer.readerStream.ReadInt32();
                int count2 = serializer.readerStream.ReadInt32();

                if (count1 != count2)
                {
                    Debug.LogError("Data is corrupt (" + count1 + " != " + count2 + ")");
                    graphs = new NavGraph[0];
                    return;
                }

                NavGraph[] _graphs = new NavGraph[count1];
                //graphs = new NavGraph[count1];

                for (int i = 0; i < _graphs.Length; i++)
                {
                    if (!serializer.MoveToAnchor("Graph" + i))
                    {
                        Debug.LogError("Couldn't find graph " + i + " in the data");
                        Debug.Log("Logging... " + serializer.anchors.Count);
                        foreach (KeyValuePair <string, int> value in serializer.anchors)
                        {
                            Debug.Log("KeyValuePair " + value.Key);
                        }
                        _graphs[i] = null;
                        continue;
                    }
                    string graphType = serializer.readerStream.ReadString();

                    //Old graph naming
                    graphType = graphType.Replace("ListGraph", "PointGraph");

                    Guid guid = new Guid(serializer.readerStream.ReadString());

                    //Search for existing graphs with the same GUID. If one is found, that means that we are loading another version of that graph
                    //Use that graph then and just load it with some new settings
                    NavGraph existingGraph = GuidToGraph(guid);

                    if (existingGraph != null)
                    {
                        _graphs[i] = existingGraph;
                        //Replace
                        //graph.guid = new System.Guid ();
                        //serializer.loadedGraphGuids[i] = graph.guid.ToString ();
                    }
                    else
                    {
                        _graphs[i] = CreateGraph(graphType);
                    }

                    NavGraph graph = _graphs[i];

                    if (graph == null)
                    {
                        Debug.LogError("One of the graphs saved was of an unknown type, the graph was of type '" + graphType + "'");
                        data_backup = data;
                        graphs      = new NavGraph[0];
                        return;
                    }

                    _graphs[i].guid = guid;

                    //Set an unique prefix for all variables in this graph
                    serializer.sPrefix = i.ToString();
                    serializer.DeSerializeSettings(graph, active);
                }

                serializer.SetUpGraphRefs(_graphs);


                for (int i = 0; i < _graphs.Length; i++)
                {
                    NavGraph graph = _graphs[i];

                    if (serializer.MoveToAnchor("GraphNodes_Graph" + i))
                    {
                        serializer.mask    = serializer.readerStream.ReadInt32();
                        serializer.sPrefix = i.ToString() + "N";
                        serializer.DeserializeNodes(graph, _graphs, i, active);
                        serializer.sPrefix = "";
                    }

                    //Debug.Log ("Graph "+i+" has loaded "+(graph.nodes != null ? graph.nodes.Length.ToString () : "null")+" nodes");
                }

                userConnections = serializer.DeserializeUserConnections();

                //Remove null graphs
                List <NavGraph> tmp = new List <NavGraph>(_graphs);
                for (int i = 0; i < _graphs.Length; i++)
                {
                    if (_graphs[i] == null)
                    {
                        tmp.Remove(_graphs[i]);
                    }
                }


                graphs = tmp.ToArray();
            } catch (System.Exception e) {
                data_backup = (serializer.readerStream.BaseStream as System.IO.MemoryStream).ToArray();
                Debug.LogWarning("Deserializing Error Encountered - Writing data to AstarData.data_backup:\n" + e.ToString());
                graphs = new NavGraph[0];
                return;
            }
        }
示例#7
0
        /** Deserializes common info additively
         * Common info is what is shared between the editor serialization and the runtime serializer.
         * This is mostly everything except the graph inspectors which serialize some extra data in the editor
         */
        public void DeserializeGraphsPartAdditive(AstarSerializer sr)
        {
            if (graphs == null)
            {
                graphs = new NavGraph[0];
            }
            if (userConnections == null)
            {
                userConnections = new UserConnection[0];
            }

            var gr = new List <NavGraph>(graphs);

            gr.AddRange(sr.DeserializeGraphs());
            graphs = gr.ToArray();
            if (graphs != null)
            {
                for (var i = 0; i < graphs.Length; i++)
                {
                    if (graphs[i] != null)
                    {
                        graphs[i].graphIndex = (uint)i;
                    }
                }
            }

            var conns = new List <UserConnection>(userConnections);

            conns.AddRange(sr.DeserializeUserConnections());
            userConnections = conns.ToArray();
            sr.DeserializeNodes();

            //Assign correct graph indices. Issue #21
            for (var i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] == null)
                {
                    continue;
                }
                graphs[i].GetNodes(delegate(GraphNode node) {
                    //GraphNode[] nodes = graphs[i].nodes;
                    node.GraphIndex = (uint)i;
                    return(true);
                });
            }

            sr.DeserializeExtraInfo();
            sr.PostDeserialization();

            for (var i = 0; i < graphs.Length; i++)
            {
                for (var j = i + 1; j < graphs.Length; j++)
                {
                    if (graphs[i] != null && graphs[j] != null && graphs[i].guid == graphs[j].guid)
                    {
                        Debug.LogWarning("Guid Conflict when importing graphs additively. Imported graph will get a new Guid.\nThis message is (relatively) harmless.");
                        graphs[i].guid = Guid.NewGuid();
                        break;
                    }
                }
            }
        }