Ejemplo n.º 1
0
 /** Main serializer function.
  * Serializes all graphs to a byte array
  * A similar function exists in the AstarEditor.cs script to save additional info */
 public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
 {
     Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(this, settings);
     sr.OpenSerialize();
     SerializeGraphsPart(sr);
     byte[] bytes = sr.CloseSerialize();
     checksum = sr.GetChecksum();
     return(bytes);
 }
Ejemplo n.º 2
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarPathEditor.cs script to save additional info */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
        {
            AstarPath.active.BlockUntilPathQueueBlocked();

            var sr = new Pathfinding.Serialization.AstarSerializer(this, settings);

            sr.OpenSerialize();
            SerializeGraphsPart(sr);
            byte[] bytes = sr.CloseSerialize();
            checksum = sr.GetChecksum();
            return(bytes);
        }
Ejemplo n.º 3
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarEditor.cs script to save additional info */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
        {
            Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(this, settings);
            sr.OpenSerialize();
            SerializeGraphsPart(sr);
            byte[] bytes = sr.CloseSerialize();
            checksum = sr.GetChecksum();
#if ASTARDEBUG
            Debug.Log("Got a whole bunch of data, " + bytes.Length + " bytes");
#endif
            return(bytes);
        }
Ejemplo n.º 4
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarPathEditor.cs script to save additional info */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
        {
            var graphLock = active.PausePathfinding();
            var sr        = new Pathfinding.Serialization.AstarSerializer(this, settings);

            sr.OpenSerialize();
            SerializeGraphsPart(sr);
            byte[] bytes = sr.CloseSerialize();
            checksum = sr.GetChecksum();
            graphLock.Release();
            return(bytes);
        }
Ejemplo n.º 5
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarPathEditor.cs script to save additional info */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
        {
            var graphLock = AssertSafe();
            var sr        = new Pathfinding.Serialization.AstarSerializer(this, settings);

            sr.OpenSerialize();
            sr.SerializeGraphs(graphs);
            sr.SerializeExtraInfo();
            byte[] bytes = sr.CloseSerialize();
            checksum = sr.GetChecksum();
            graphLock.Release();
            return(bytes);
        }
Ejemplo n.º 6
0
        /** Main serializer function.
         * Serializes all graphs to a byte array
         * A similar function exists in the AstarPathEditor.cs script to save additional info */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings, out uint checksum)
        {
            var graphLock = AssertSafe();
            var sr        = new Pathfinding.Serialization.AstarSerializer(this, settings);

            sr.OpenSerialize();
            sr.SerializeGraphs(graphs);
            sr.SerializeExtraInfo();
            byte[] bytes = sr.CloseSerialize();
            checksum = sr.GetChecksum();
#if ASTARDEBUG
            Debug.Log("Got a whole bunch of data, " + bytes.Length + " bytes");
#endif
            graphLock.Release();
            return(bytes);
        }
Ejemplo n.º 7
0
        /** Serializes all graphs settings and optionally node data to a byte array.
         * \see DeserializeGraphs(byte[])
         * \see Pathfinding.Serialization.SerializeSettings
         */
        public byte[] SerializeGraphs(Pathfinding.Serialization.SerializeSettings settings)
        {
            uint checksum;

            return(SerializeGraphs(settings, out checksum));
        }
Ejemplo n.º 8
0
 public void SaveCacheData(Pathfinding.Serialization.SerializeSettings settings)
 {
     data_cachedStartup = SerializeGraphs(settings);
     cacheStartup       = true;
 }
Ejemplo n.º 9
0
        public void exportMethod()
        {
#if UNITY_EDITOR
            var astar = AstarPath.active;
            if (astar == null)
            {
                astar = GameObject.FindObjectOfType <AstarPath>();
            }
            string path = EditorUtility.SaveFilePanel("Save Graphs", "", "graph" + Convert.ToString(mapId) + ".zip", "zip");
            if (path != "")
            {
                if (EditorUtility.DisplayDialog("Scan before saving?", "Do you want to scan the graphs before saving" +
                                                "\nNot scanning can cause node data to be omitted from the file if Save Node Data is enabled", "Scan", "Don't scan"))
                {
                    astar.Scan();
                }


                //uint checksum;
                Pathfinding.Serialization.SerializeSettings settings = Pathfinding.Serialization.SerializeSettings.All;


                byte[] bytes = null;
                //uint ch = 0;
                astar.AddWorkItem(new AstarPath.AstarWorkItem(delegate(bool force) {
                    Pathfinding.Serialization.AstarSerializer sr = new Pathfinding.Serialization.AstarSerializer(astar.astarData, settings);
                    sr.OpenSerialize();
                    astar.astarData.SerializeGraphsPart(sr);
                    //sr.SerializeEditorSettings (graphEditors);
                    var start = GameObject.Find("PlayerStart").transform.position;
                    var grid  = Util.CoordToGrid(start.x, start.z);
                    var yOff  = Util.IntYOffset(start.y);

                    SimpleJSON.JSONClass jc = new SimpleJSON.JSONClass();
                    var arr = jc["playerStart"] = new SimpleJSON.JSONArray();

                    arr[-1].AsInt = (int)(grid.x);
                    arr[-1].AsInt = yOff;
                    arr[-1].AsInt = (int)(grid.y);

                    /*
                     * System.IO.MemoryStream stream = new System.IO.MemoryStream();
                     * BinaryWriter outfile = new BinaryWriter(stream);
                     * jc.Serialize(outfile);
                     */
                    Debug.Log("Export " + jc.ToString());
                    var graph = astar.graphs[0] as Pathfinding.GridGraph;
                    var js    = new SimpleJSON.JSONClass();
                    js["unclampedSize"]["x"].AsInt = graph.width;
                    js["unclampedSize"]["y"].AsInt = graph.depth;
                    js["center"]["x"].AsFloat      = graph.center.x;
                    js["center"]["y"].AsFloat      = graph.center.y;
                    js["center"]["z"].AsFloat      = graph.center.z;
                    sr.zip.AddEntry("playerStart" + Convert.ToString(mapId) + ".json", System.Text.Encoding.UTF8.GetBytes(jc.ToString()));
                    sr.zip.AddEntry("graph0.json", System.Text.Encoding.UTF8.GetBytes(js.ToString()));
                    bytes = sr.CloseSerialize();
                    //ch = sr.GetChecksum ();
                    return(true);
                }));

                Pathfinding.Serialization.AstarSerializer.SaveToFile(path, bytes);
                EditorUtility.DisplayDialog("Done Saving", "Done saving graph data.", "Ok");
            }
#endif
        }