コード例 #1
0
        public byte[] Serialize(NavGraph graph)
        {
            StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();

            TinyJsonSerializer.Serialize(graph, stringBuilder);
            return(this.encoding.GetBytes(stringBuilder.ToString()));
        }
コード例 #2
0
        private static byte[] SerializeNodeIndices(NavGraph[] graphs)
        {
            MemoryStream memoryStream            = new MemoryStream();
            BinaryWriter writer                  = new BinaryWriter(memoryStream);
            int          maxNodeIndexInAllGraphs = AstarSerializer.GetMaxNodeIndexInAllGraphs(graphs);

            writer.Write(maxNodeIndexInAllGraphs);
            int maxNodeIndex2 = 0;

            Action <GraphNode> < > 9__0;
            for (int i = 0; i < graphs.Length; i++)
            {
                if (graphs[i] != null)
                {
                    NavGraph           navGraph = graphs[i];
                    Action <GraphNode> action;
                    if ((action = < > 9__0) == null)
                    {
                        action = (< > 9__0 = delegate(GraphNode node)
                        {
                            maxNodeIndex2 = Math.Max(node.NodeIndex, maxNodeIndex2);
                            writer.Write(node.NodeIndex);
                        });
                    }
                    navGraph.GetNodes(action);
                }
            }
            if (maxNodeIndex2 != maxNodeIndexInAllGraphs)
            {
                throw new Exception("Some graphs are not consistent in their GetNodes calls, sequential calls give different results.");
            }
            byte[] result = memoryStream.ToArray();
            writer.Close();
            return(result);
        }
コード例 #3
0
 public void SerializeExtraInfo()
 {
     if (!this.settings.nodes)
     {
         return;
     }
     if (this.graphs == null)
     {
         throw new InvalidOperationException("Cannot serialize extra info with no serialized graphs (call SerializeGraphs first)");
     }
     byte[] bytes = AstarSerializer.SerializeNodeIndices(this.graphs);
     this.AddChecksum(bytes);
     this.AddEntry("graph_references.binary", bytes);
     for (int i = 0; i < this.graphs.Length; i++)
     {
         if (this.graphs[i] != null)
         {
             bytes = AstarSerializer.SerializeGraphExtraInfo(this.graphs[i]);
             this.AddChecksum(bytes);
             this.AddEntry("graph" + i + "_extra.binary", bytes);
             bytes = AstarSerializer.SerializeGraphNodeReferences(this.graphs[i]);
             this.AddChecksum(bytes);
             this.AddEntry("graph" + i + "_references.binary", bytes);
         }
     }
     bytes = this.SerializeNodeLinks();
     this.AddChecksum(bytes);
     this.AddEntry("node_link2.binary", bytes);
 }
コード例 #4
0
 public void DeserializeEditorSettings(GraphEditorBase[] graphEditors)
 {
     if (graphEditors == null)
     {
         return;
     }
     for (int i = 0; i < graphEditors.Length; i++)
     {
         if (graphEditors[i] != null)
         {
             for (int j = 0; j < this.graphs.Length; j++)
             {
                 if (graphEditors[i].target == this.graphs[j])
                 {
                     int      num      = this.graphIndexInZip[this.graphs[j]];
                     ZipEntry zipEntry = this.zip["graph" + num + "_editor.json"];
                     if (zipEntry != null)
                     {
                         string          @string         = AstarSerializer.GetString(zipEntry);
                         JsonReader      jsonReader      = new JsonReader(@string, this.readerSettings);
                         GraphEditorBase graphEditorBase = graphEditors[i];
                         jsonReader.PopulateObject <GraphEditorBase>(ref graphEditorBase);
                         graphEditors[i] = graphEditorBase;
                         break;
                     }
                 }
             }
         }
     }
 }
コード例 #5
0
        private byte[] SerializeMeta()
        {
            if (this.graphs == null)
            {
                throw new Exception("No call to SerializeGraphs has been done");
            }
            this.meta.version    = AstarPath.Version;
            this.meta.graphs     = this.graphs.Length;
            this.meta.guids      = new string[this.graphs.Length];
            this.meta.typeNames  = new string[this.graphs.Length];
            this.meta.nodeCounts = new int[this.graphs.Length];
            for (int i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.meta.guids[i]     = this.graphs[i].guid.ToString();
                    this.meta.typeNames[i] = this.graphs[i].GetType().FullName;
                }
            }
            StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();
            JsonWriter    jsonWriter    = new JsonWriter(stringBuilder, this.writerSettings);

            jsonWriter.Write(this.meta);
            return(this.encoding.GetBytes(stringBuilder.ToString()));
        }
コード例 #6
0
 public void DeserializeEditorSettings(GraphEditorBase[] graphEditors)
 {
     if (graphEditors == null)
     {
         return;
     }
     for (int i = 0; i < graphEditors.Length; i++)
     {
         if (graphEditors[i] != null)
         {
             for (int j = 0; j < this.graphs.Length; j++)
             {
                 if (graphEditors[i].target == this.graphs[j])
                 {
                     int      num   = this.graphIndexInZip[this.graphs[j]];
                     ZipEntry entry = this.GetEntry("graph" + num + "_editor.json");
                     if (entry != null)
                     {
                         TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(entry), graphEditors[i].GetType(), graphEditors[i]);
                         break;
                     }
                 }
             }
         }
     }
 }
コード例 #7
0
        private byte[] SerializeMeta()
        {
            if (this.graphs == null)
            {
                throw new Exception("No call to SerializeGraphs has been done");
            }
            this.meta.version   = AstarPath.Version;
            this.meta.graphs    = this.graphs.Length;
            this.meta.guids     = new List <string>();
            this.meta.typeNames = new List <string>();
            for (int i = 0; i < this.graphs.Length; i++)
            {
                if (this.graphs[i] != null)
                {
                    this.meta.guids.Add(this.graphs[i].guid.ToString());
                    this.meta.typeNames.Add(this.graphs[i].GetType().FullName);
                }
                else
                {
                    this.meta.guids.Add(null);
                    this.meta.typeNames.Add(null);
                }
            }
            StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();

            TinyJsonSerializer.Serialize(this.meta, stringBuilder);
            return(this.encoding.GetBytes(stringBuilder.ToString()));
        }
コード例 #8
0
        public byte[] Serialize(NavGraph graph)
        {
            StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();
            JsonWriter    jsonWriter    = new JsonWriter(stringBuilder, this.writerSettings);

            jsonWriter.Write(graph);
            return(this.encoding.GetBytes(stringBuilder.ToString()));
        }
コード例 #9
0
        private void DeserializeNodeLinks(GraphNode[] int2Node)
        {
            ZipEntry entry = this.GetEntry("node_link2.binary");

            if (entry == null)
            {
                return;
            }
            NodeLink2.DeserializeReferences(new GraphSerializationContext(AstarSerializer.GetBinaryReader(entry), int2Node, 0u, this.meta));
        }
コード例 #10
0
        private GraphMeta DeserializeMeta(ZipEntry entry)
        {
            if (entry == null)
            {
                throw new Exception("No metadata found in serialized data.");
            }
            string     @string    = AstarSerializer.GetString(entry);
            JsonReader jsonReader = new JsonReader(@string, this.readerSettings);

            return((GraphMeta)jsonReader.Deserialize(typeof(GraphMeta)));
        }
コード例 #11
0
        private static byte[] SerializeGraphExtraInfo(NavGraph graph)
        {
            MemoryStream memoryStream     = new MemoryStream();
            BinaryWriter writer           = new BinaryWriter(memoryStream);
            GraphSerializationContext ctx = new GraphSerializationContext(writer);

            graph.SerializeExtraInfo(ctx);
            byte[] result = memoryStream.ToArray();
            AstarSerializer.CloseOrDispose(writer);
            return(result);
        }
コード例 #12
0
 // Token: 0x0600285B RID: 10331 RVA: 0x001BBF3C File Offset: 0x001BA13C
 public void DeserializeEditorSettingsCompatibility()
 {
     for (int i = 0; i < this.graphs.Length; i++)
     {
         int      num   = this.graphIndexInZip[this.graphs[i]];
         ZipEntry entry = this.GetEntry("graph" + num + "_editor.json");
         if (entry != null)
         {
             ((IGraphInternals)this.graphs[i]).SerializedEditorSettings = AstarSerializer.GetString(entry);
         }
     }
 }
コード例 #13
0
        private void DeserializeNodeLinks(GraphNode[] int2Node)
        {
            ZipEntry zipEntry = this.zip["node_link2.binary"];

            if (zipEntry == null)
            {
                return;
            }
            BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(zipEntry);
            GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, int2Node, 0u, this.meta);

            NodeLink2.DeserializeReferences(ctx);
        }
コード例 #14
0
 public bool OpenDeserialize(byte[] bytes)
 {
     this.zipStream = new MemoryStream();
     this.zipStream.Write(bytes, 0, bytes.Length);
     this.zipStream.Position = 0L;
     try
     {
         this.zip = ZipFile.Read(this.zipStream);
     }
     catch (Exception arg)
     {
         Debug.LogError("Caught exception when loading from zip\n" + arg);
         this.zipStream.Dispose();
         return(false);
     }
     if (this.ContainsEntry("meta.json"))
     {
         this.meta = this.DeserializeMeta(this.GetEntry("meta.json"));
     }
     else
     {
         if (!this.ContainsEntry("meta.binary"))
         {
             throw new Exception("No metadata found in serialized data.");
         }
         this.meta = this.DeserializeBinaryMeta(this.GetEntry("meta.binary"));
     }
     if (AstarSerializer.FullyDefinedVersion(this.meta.version) > AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from a newer version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.meta.version,
             "\nThis is usually fine as the stored data is usually backwards and forwards compatible.\nHowever node data (not settings) can get corrupted between versions (even though I try my best to keep compatibility), so it is recommended to recalculate any caches (those for faster startup) and resave any files. Even if it seems to load fine, it might cause subtle bugs.\n"
         }));
     }
     else if (AstarSerializer.FullyDefinedVersion(this.meta.version) < AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Upgrading serialized pathfinding data from version ",
             this.meta.version,
             " to ",
             AstarPath.Version,
             "\nThis is usually fine, it just means you have upgraded to a new version.\nHowever node data (not settings) can get corrupted between versions (even though I try my best to keep compatibility), so it is recommended to recalculate any caches (those for faster startup) and resave any files. Even if it seems to load fine, it might cause subtle bugs.\n"
         }));
     }
     return(true);
 }
コード例 #15
0
        private GraphMeta DeserializeBinaryMeta(ZipEntry entry)
        {
            GraphMeta    graphMeta    = new GraphMeta();
            BinaryReader binaryReader = AstarSerializer.GetBinaryReader(entry);

            if (binaryReader.ReadString() != "A*")
            {
                throw new Exception("Invalid magic number in saved data");
            }
            int num  = binaryReader.ReadInt32();
            int num2 = binaryReader.ReadInt32();
            int num3 = binaryReader.ReadInt32();
            int num4 = binaryReader.ReadInt32();

            if (num < 0)
            {
                graphMeta.version = new Version(0, 0);
            }
            else if (num2 < 0)
            {
                graphMeta.version = new Version(num, 0);
            }
            else if (num3 < 0)
            {
                graphMeta.version = new Version(num, num2);
            }
            else if (num4 < 0)
            {
                graphMeta.version = new Version(num, num2, num3);
            }
            else
            {
                graphMeta.version = new Version(num, num2, num3, num4);
            }
            graphMeta.graphs = binaryReader.ReadInt32();
            graphMeta.guids  = new List <string>();
            int num5 = binaryReader.ReadInt32();

            for (int i = 0; i < num5; i++)
            {
                graphMeta.guids.Add(binaryReader.ReadString());
            }
            graphMeta.typeNames = new List <string>();
            num5 = binaryReader.ReadInt32();
            for (int j = 0; j < num5; j++)
            {
                graphMeta.typeNames.Add(binaryReader.ReadString());
            }
            return(graphMeta);
        }
コード例 #16
0
        private static byte[] SerializeGraphNodeReferences(NavGraph graph)
        {
            MemoryStream memoryStream     = new MemoryStream();
            BinaryWriter writer           = new BinaryWriter(memoryStream);
            GraphSerializationContext ctx = new GraphSerializationContext(writer);

            graph.GetNodes(delegate(GraphNode node)
            {
                node.SerializeReferences(ctx);
                return(true);
            });
            AstarSerializer.CloseOrDispose(writer);
            return(memoryStream.ToArray());
        }
コード例 #17
0
        private bool DeserializeExtraInfo(NavGraph graph)
        {
            int      num   = this.graphIndexInZip[graph];
            ZipEntry entry = this.GetEntry("graph" + num + "_extra.binary");

            if (entry == null)
            {
                return(false);
            }
            GraphSerializationContext ctx = new GraphSerializationContext(AstarSerializer.GetBinaryReader(entry), null, graph.graphIndex, this.meta);

            graph.DeserializeExtraInfo(ctx);
            return(true);
        }
コード例 #18
0
        private bool DeserializeExtraInfo(NavGraph graph)
        {
            int      num      = this.graphIndexInZip[graph];
            ZipEntry zipEntry = this.zip["graph" + num + "_extra.binary"];

            if (zipEntry == null)
            {
                return(false);
            }
            BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(zipEntry);
            GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, null, graph.graphIndex);

            graph.DeserializeExtraInfo(ctx);
            return(true);
        }
コード例 #19
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            Type graphType = this.meta.GetGraphType(zipIndex);

            if (object.Equals(graphType, null))
            {
                return(null);
            }
            NavGraph navGraph = this.data.CreateGraph(graphType);

            navGraph.graphIndex = (uint)graphIndex;
            string name  = "graph" + zipIndex + ".json";
            string name2 = "graph" + zipIndex + ".binary";

            if (this.ContainsEntry(name))
            {
                TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(this.GetEntry(name)), graphType, navGraph);
            }
            else
            {
                if (!this.ContainsEntry(name2))
                {
                    throw new FileNotFoundException(string.Concat(new object[]
                    {
                        "Could not find data for graph ",
                        zipIndex,
                        " in zip. Entry 'graph",
                        zipIndex,
                        ".json' does not exist"
                    }));
                }
                BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(this.GetEntry(name2));
                GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, null, navGraph.graphIndex, this.meta);
                navGraph.DeserializeSettingsCompatibility(ctx);
            }
            if (navGraph.guid.ToString() != this.meta.guids[zipIndex])
            {
                throw new Exception(string.Concat(new object[]
                {
                    "Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n",
                    navGraph.guid,
                    " != ",
                    this.meta.guids[zipIndex]
                }));
            }
            return(navGraph);
        }
コード例 #20
0
 public bool OpenDeserialize(byte[] bytes)
 {
     this.readerSettings = new JsonReaderSettings();
     this.readerSettings.AddTypeConverter(new VectorConverter());
     this.readerSettings.AddTypeConverter(new BoundsConverter());
     this.readerSettings.AddTypeConverter(new LayerMaskConverter());
     this.readerSettings.AddTypeConverter(new MatrixConverter());
     this.readerSettings.AddTypeConverter(new GuidConverter());
     this.readerSettings.AddTypeConverter(new UnityObjectConverter());
     this.str = new MemoryStream();
     this.str.Write(bytes, 0, bytes.Length);
     this.str.Position = 0L;
     try
     {
         this.zip = ZipFile.Read(this.str);
     }
     catch (Exception arg)
     {
         Debug.LogWarning("Caught exception when loading from zip\n" + arg);
         this.str.Dispose();
         return(false);
     }
     this.meta = this.DeserializeMeta(this.zip["meta.json"]);
     if (AstarSerializer.FullyDefinedVersion(this.meta.version) > AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from a newer version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.meta.version,
             "\nThis is usually fine as the stored data is usually backwards and forwards compatible.\nHowever node data (not settings) can get corrupted between versions, so it is recommended to recalculate any caches (those for faster startup) and resave any files. Even if it seems to load fine, it might cause subtle bugs.\n"
         }));
     }
     else if (AstarSerializer.FullyDefinedVersion(this.meta.version) < AstarSerializer.FullyDefinedVersion(AstarPath.Version))
     {
         Debug.LogWarning(string.Concat(new object[]
         {
             "Trying to load data from an older version of the A* Pathfinding Project\nCurrent version: ",
             AstarPath.Version,
             " Data version: ",
             this.meta.version,
             "\nThis is usually fine, it just means you have upgraded to a new version.\nHowever node data (not settings) can get corrupted between versions, so it is recommended to recalculate any caches (those for faster startup) and resave any files. Even if it seems to load fine, it might cause subtle bugs.\n"
         }));
     }
     return(true);
 }
コード例 #21
0
        private GraphNode[] DeserializeNodeReferenceMap()
        {
            ZipEntry entry = this.GetEntry("graph_references.binary");

            if (entry == null)
            {
                throw new Exception("Node references not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
            }
            BinaryReader reader = AstarSerializer.GetBinaryReader(entry);
            int          num    = reader.ReadInt32();

            GraphNode[] int2Node = new GraphNode[num + 1];
            try
            {
                Action <GraphNode> < > 9__0;
                for (int i = 0; i < this.graphs.Length; i++)
                {
                    NavGraph           navGraph = this.graphs[i];
                    Action <GraphNode> action;
                    if ((action = < > 9__0) == null)
                    {
                        action = (< > 9__0 = delegate(GraphNode node)
                        {
                            int num2 = reader.ReadInt32();
                            int2Node[num2] = node;
                        });
                    }
                    navGraph.GetNodes(action);
                }
            }
            catch (Exception innerException)
            {
                throw new Exception("Some graph(s) has thrown an exception during GetNodes, or some graph(s) have deserialized more or fewer nodes than were serialized", innerException);
            }
            if (reader.BaseStream.Position != reader.BaseStream.Length)
            {
                throw new Exception(string.Concat(new object[]
                {
                    reader.BaseStream.Length / 4L,
                    " nodes were serialized, but only data for ",
                    reader.BaseStream.Position / 4L,
                    " nodes was found. The data looks corrupt."
                }));
            }
            reader.Close();
            return(int2Node);
        }
コード例 #22
0
        private void DeserializeNodeReferences(NavGraph graph, GraphNode[] int2Node)
        {
            int      num   = this.graphIndexInZip[graph];
            ZipEntry entry = this.GetEntry("graph" + num + "_references.binary");

            if (entry == null)
            {
                throw new Exception("Node references for graph " + num + " not found in the data. Was this loaded from an older version of the A* Pathfinding Project?");
            }
            BinaryReader binaryReader     = AstarSerializer.GetBinaryReader(entry);
            GraphSerializationContext ctx = new GraphSerializationContext(binaryReader, int2Node, graph.graphIndex, this.meta);

            graph.GetNodes(delegate(GraphNode node)
            {
                node.DeserializeReferences(ctx);
            });
        }
コード例 #23
0
        public void SerializeUserConnections(UserConnection[] conns)
        {
            if (conns == null)
            {
                conns = new UserConnection[0];
            }
            StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();
            JsonWriter    jsonWriter    = new JsonWriter(stringBuilder, this.writerSettings);

            jsonWriter.Write(conns);
            byte[] bytes = this.encoding.GetBytes(stringBuilder.ToString());
            if (bytes.Length <= 2)
            {
                return;
            }
            this.AddChecksum(bytes);
            this.zip.AddEntry("connections.json", bytes);
        }
コード例 #24
0
        private NavGraph DeserializeGraph(int zipIndex, int graphIndex)
        {
            Type graphType = this.meta.GetGraphType(zipIndex);

            if (object.Equals(graphType, null))
            {
                return(null);
            }
            ZipEntry zipEntry = this.zip["graph" + zipIndex + ".json"];

            if (zipEntry == null)
            {
                throw new FileNotFoundException(string.Concat(new object[]
                {
                    "Could not find data for graph ",
                    zipIndex,
                    " in zip. Entry 'graph",
                    zipIndex,
                    ".json' does not exist"
                }));
            }
            NavGraph navGraph = this.data.CreateGraph(graphType);

            navGraph.graphIndex = (uint)graphIndex;
            string     @string    = AstarSerializer.GetString(zipEntry);
            JsonReader jsonReader = new JsonReader(@string, this.readerSettings);

            jsonReader.PopulateObject <NavGraph>(ref navGraph);
            if (navGraph.guid.ToString() != this.meta.guids[zipIndex])
            {
                throw new Exception(string.Concat(new object[]
                {
                    "Guid in graph file not equal to guid defined in meta file. Have you edited the data manually?\n",
                    navGraph.guid,
                    " != ",
                    this.meta.guids[zipIndex]
                }));
            }
            return(navGraph);
        }
コード例 #25
0
 public void SerializeEditorSettings(GraphEditorBase[] editors)
 {
     if (editors == null || !this.settings.editorSettings)
     {
         return;
     }
     for (int i = 0; i < editors.Length; i++)
     {
         if (editors[i] == null)
         {
             return;
         }
         StringBuilder stringBuilder = AstarSerializer.GetStringBuilder();
         TinyJsonSerializer.Serialize(editors[i], stringBuilder);
         byte[] bytes = this.encoding.GetBytes(stringBuilder.ToString());
         if (bytes.Length > 2)
         {
             this.AddChecksum(bytes);
             this.AddEntry("graph" + i + "_editor.json", bytes);
         }
     }
 }
コード例 #26
0
ファイル: AstarPathEditor.cs プロジェクト: klobodnf/st1
    public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
    {
        Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(script.astarData, settings);
        sr.OpenSerialize();
        script.astarData.SerializeGraphsPart (sr);
        sr.SerializeEditorSettings (graphEditors);
        byte[] bytes = sr.CloseSerialize();
        checksum = sr.GetChecksum ();
        #if ASTARDEBUG
        Debug.Log ("Got a whole bunch of data, "+bytes.Length+" bytes");
        #endif
        return bytes;

        //Forward to runtime serializer
        //return script.astarData.SerializeGraphs(Pathfinding.Serialization.SerializeSettings.Settings, out checksum);
    }
コード例 #27
0
	public byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum) {
		byte[] bytes = null;
		uint ch = 0;

		// Add a work item since we cannot be sure that pathfinding (or graph updates)
		// is not running at the same time
		AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (force => {
			var sr = new Pathfinding.Serialization.AstarSerializer(script.astarData, settings);
			sr.OpenSerialize();
			script.astarData.SerializeGraphsPart (sr);
			sr.SerializeEditorSettings (graphEditors);
			bytes = sr.CloseSerialize();
			ch = sr.GetChecksum ();
			return true;
		}));

		// Make sure the above work item is executed immediately
		AstarPath.active.FlushWorkItems();
		checksum = ch;
		return bytes;
	}
コード例 #28
0
	public void DeserializeGraphs (byte[] bytes) {
		
		AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (delegate (bool force) {
			Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(script.astarData);
			if (sr.OpenDeserialize(bytes)) {
				script.astarData.DeserializeGraphsPart (sr);
				
				//Make sure every graph has a graph editor
				CheckGraphEditors ();
				sr.DeserializeEditorSettings (graphEditors);
				
				sr.CloseDeserialize();
			} else {
				Debug.LogWarning ("Invalid data file (cannot read zip).\nThe data is either corrupt or it was saved using a 3.0.x or earlier version of the system");
				//Make sure every graph has a graph editor
				CheckGraphEditors ();
			}
			return true;
		}));
		
		//Make sure the above work item is run directly
		AstarPath.active.FlushWorkItems();
	}
コード例 #29
0
	public byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum) {
		byte[] bytes = null;
		uint ch = 0;
		AstarPath.active.AddWorkItem (new AstarPath.AstarWorkItem (delegate (bool force) {
			Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(script.astarData, settings);
			sr.OpenSerialize();
			script.astarData.SerializeGraphsPart (sr);
			sr.SerializeEditorSettings (graphEditors);
			bytes = sr.CloseSerialize();
			ch = sr.GetChecksum ();
	#if ASTARDEBUG
			Debug.Log ("Got a whole bunch of data, "+bytes.Length+" bytes");
	#endif
			return true;
		}));
		
		//Make sure the above work item is run directly
		AstarPath.active.FlushWorkItems();
		checksum = ch;
		return bytes;
		
		//Forward to runtime serializer
		//return script.astarData.SerializeGraphs(Pathfinding.Serialization.SerializeSettings.Settings, out checksum);
	}
コード例 #30
0
 private GraphMeta DeserializeMeta(ZipEntry entry)
 {
     return(TinyJsonDeserializer.Deserialize(AstarSerializer.GetString(entry), typeof(GraphMeta), null) as GraphMeta);
 }
コード例 #31
0
	public void DeserializeGraphs (byte[] bytes) {
		
		Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(script.astarData);
		if (sr.OpenDeserialize(bytes)) {
			script.astarData.DeserializeGraphsPart (sr);
			
			//Make sure every graph has a graph editor
			CheckGraphEditors ();
			sr.DeserializeEditorSettings (graphEditors);
			
			sr.CloseDeserialize();
		} else {
			Debug.Log ("Invalid data file (cannot read zip). Trying to load with old deserializer (pre 3.1)...");
			AstarSerializer serializer = new AstarSerializer (script);
			script.astarData.DeserializeGraphs_oldInternal (serializer,bytes);
			
			//Make sure every graph has a graph editor
			CheckGraphEditors ();
		}
		
		
		/*serializer = serializer.OpenDeserialize (data);
		
		//Deserialize the main bulk of the data
		script.astarData.DeserializeGraphsPart (serializer);
		
		CheckGraphEditors ();
		
		//Deserialize editor data
		for (int i=0;i<script.graphs.Length;i++) {
			NavGraph graph = script.graphs[i];
			
			GraphEditor graphEditor = graphEditors[i];
			
			if (serializer.MoveToAnchor ("EditorSettings_"+i)) {
				ISerializableGraphEditor serializableEditor = graphEditor as ISerializableGraphEditor;
				if (serializableEditor != null) {
					//Set an unique prefix for all variables in this graph
					serializer.sPrefix = i.ToString ()+"E";
					serializer.DeSerializeEditorSettings (graph,serializableEditor,script);
					//serializableEditor.DeSerializeSettings (graph,serializer);
				}
			}
		}
		
		serializer.Close ();*/
		
		//script.astarData.DeserializeGraphs(data);
	}
コード例 #32
0
	public byte[] SerializeGraphs (Pathfinding.Serialization.SerializeSettings settings, out uint checksum) {
		Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(script.astarData, settings);
		sr.OpenSerialize();
		script.astarData.SerializeGraphsPart (sr);
		sr.SerializeEditorSettings (graphEditors);
		byte[] bytes = sr.CloseSerialize();
		checksum = sr.GetChecksum ();
		return bytes;
		
		//Forward to runtime serializer
		//return script.astarData.SerializeGraphs(Pathfinding.Serialization.SerializeSettings.Settings, out checksum);
	}