コード例 #1
0
    private void Save()
    {
        //BinaryFormatter bf = new BinaryFormatter();
        XmlSerializer serializer = new XmlSerializer(typeof(SaveData));
        FileStream    file       = File.Open(Constants.SaveDataFilePath, FileMode.Create);
        //XmlWriterSettings settings = new System.Xml.XmlWriterSettings();
        //settings.Encoding = new System.Text.ASCIIEncoding();
        StreamWriter writer = new StreamWriter(file, Encoding.ASCII);

//#if NETFX_CORE
//        XmlWriter writer = (WinRTLegacy.Xml.XmlWriter)XmlWriter.Create(file, settings);
//#else
//        XmlWriter writer = XmlWriter.Create(file, settings);
//#endif

        SaveData data = new SaveData
        {
            HighScores = highScores,
            Diamonds   = diamonds
        };

        //bf.Serialize(file, data);
        //serializer.Serialize(writer, data);
        serializer.Serialize(writer, data);
        //writer.Close();
        writer.Dispose();
        file.Dispose();
    }
コード例 #2
0
        /// <summary>
        /// As we progress through a task sequence, store the partial data value to file.
        /// </summary>
        /// <param name="seqVal">Current Sequence index value.</param>
        public virtual void SaveCurrentTaskSequenceValue(int seqVal)
        {
            var writer = new StreamWriter(Path.Combine(MmTaskUserData.DirPath, PartialDataFile),
                                          false, Encoding.Unicode);

            writer.WriteLine("Current Sequence ID," + seqVal);
            //TODO: Check if UserSequence is the right variable to write

            writer.Close();
        }
コード例 #3
0
 public static void Save(Tile[] tiles, int score)
 {
     if (tiles != null)
     {
         try
         {
             TilesCollection TS = new TilesCollection();
             TS.tsd = new TileSaveData[tiles.Length];
             for (int i = 0; i < tiles.Length; i++)
             {
                 TS.tsd[i]       = new TileSaveData();
                 TS.tsd[i].i     = i;
                 TS.tsd[i].value = tiles[i].Value;
             }
             TS.score = score;
             HighScoreData hsd = new HighScoreData();
             hsd.highScore = score > highScore ? score : highScore;
             string saveJSON = UnityEngine.JsonUtility.ToJson(TS, true);
             string highJSON = UnityEngine.JsonUtility.ToJson(hsd);
             if (!File.Exists(Application.persistentDataPath + "/save.json"))
             {
                 File.Create(Application.persistentDataPath + "/save.json");
             }
             if (!File.Exists(Application.persistentDataPath + "/score.json"))
             {
                 File.Create(Application.persistentDataPath + "/score.json");
             }
             StreamWriter sr;
             if (score > highScore)
             {
                 sr = new StreamWriter(Application.persistentDataPath + "/score.json");
                 sr.Write(highJSON);
                 sr.Close();
             }
             sr = new StreamWriter(Application.persistentDataPath + "/save.json");
             sr.Write(saveJSON);
             sr.Close();
         }
         catch
         {
             return;
         }
     }
     else
     {
         try
         {
             File.Delete(Application.persistentDataPath + "/save.json");
         }
         catch
         {
         }
     }
 }
コード例 #4
0
        /// <summary>
        /// Number the vertices and write them to a .node file.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="filename"></param>
        public void WriteNodes(Mesh mesh, string filename)
        {
#if NETFX_CORE
            using (var writer = new WinRTLegacy.IO.StreamWriter(filename))
            {
                WriteNodes(writer, mesh);
            }
#else
            using (var writer = new StreamWriter(filename))
            {
                WriteNodes(writer, mesh);
            }
#endif
        }
コード例 #5
0
        /// <summary>
        /// Write the triangles to an .ele file.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="filename"></param>
        public void WriteElements(Mesh mesh, string filename)
        {
            Otri   tri = default(Otri);
            Vertex p1, p2, p3;
            bool   regions = mesh.behavior.useRegions;

            int j = 0;

            tri.orient = 0;

            using (
#if NETFX_CORE
                var writer = new WinRTLegacy.IO.StreamWriter(filename)
#else
                var writer = new StreamWriter(filename)
#endif
                )
            {
                // Number of triangles, vertices per triangle, attributes per triangle.
                writer.WriteLine("{0} 3 {1}", mesh.triangles.Count, regions ? 1 : 0);

                foreach (var item in mesh.triangles)
                {
                    tri.tri = item;

                    p1 = tri.Org();
                    p2 = tri.Dest();
                    p3 = tri.Apex();

                    // Triangle number, indices for three vertices.
                    writer.Write("{0} {1} {2} {3}", j, p1.id, p2.id, p3.id);

                    if (regions)
                    {
                        writer.Write(" {0}", tri.tri.label);
                    }

                    writer.WriteLine();

                    // Number elements
                    item.id = j++;
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Write the triangle neighbors to a .neigh file.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="filename"></param>
        /// <remarks>WARNING: Be sure WriteElements has been called before,
        /// so the elements are numbered right!</remarks>
        public void WriteNeighbors(Mesh mesh, string filename)
        {
            Otri tri = default(Otri), trisym = default(Otri);
            int  n1, n2, n3;
            int  i = 0;

            using (
#if NETFX_CORE
                var writer = new WinRTLegacy.IO.StreamWriter(filename)
#else
                var writer = new StreamWriter(filename)
#endif
                )
            {
                // Number of triangles, three neighbors per triangle.
                writer.WriteLine("{0} 3", mesh.triangles.Count);

                foreach (var item in mesh.triangles)
                {
                    tri.tri = item;

                    tri.orient = 1;
                    tri.Sym(ref trisym);
                    n1 = trisym.tri.id;

                    tri.orient = 2;
                    tri.Sym(ref trisym);
                    n2 = trisym.tri.id;

                    tri.orient = 0;
                    tri.Sym(ref trisym);
                    n3 = trisym.tri.id;

                    // Triangle number, neighboring triangle numbers.
                    writer.WriteLine("{0} {1} {2} {3}", i++, n1, n2, n3);
                }
            }
        }
コード例 #7
0
        /// <summary>
        /// Write the edges to an .edge file.
        /// </summary>
        /// <param name="mesh"></param>
        /// <param name="filename"></param>
        public void WriteEdges(Mesh mesh, string filename)
        {
            Otri   tri = default(Otri), trisym = default(Otri);
            Osub   checkmark = default(Osub);
            Vertex p1, p2;

            Behavior behavior = mesh.behavior;

            using (
#if NETFX_CORE
                var writer = new WinRTLegacy.IO.StreamWriter(filename)
#else
                var writer = new StreamWriter(filename)
#endif
                )
            {
                // Number of edges, number of boundary markers (zero or one).
                writer.WriteLine("{0} {1}", mesh.NumberOfEdges, behavior.UseBoundaryMarkers ? "1" : "0");

                long index = 0;
                // To loop over the set of edges, loop over all triangles, and look at
                // the three edges of each triangle.  If there isn't another triangle
                // adjacent to the edge, operate on the edge.  If there is another
                // adjacent triangle, operate on the edge only if the current triangle
                // has a smaller pointer than its neighbor.  This way, each edge is
                // considered only once.
                foreach (var item in mesh.triangles)
                {
                    tri.tri = item;

                    for (tri.orient = 0; tri.orient < 3; tri.orient++)
                    {
                        tri.Sym(ref trisym);
                        if ((tri.tri.id < trisym.tri.id) || (trisym.tri.id == Mesh.DUMMY))
                        {
                            p1 = tri.Org();
                            p2 = tri.Dest();

                            if (behavior.UseBoundaryMarkers)
                            {
                                // Edge number, indices of two endpoints, and a boundary marker.
                                // If there's no subsegment, the boundary marker is zero.
                                if (behavior.useSegments)
                                {
                                    tri.Pivot(ref checkmark);

                                    if (checkmark.seg.hash == Mesh.DUMMY)
                                    {
                                        writer.WriteLine("{0} {1} {2} {3}", index, p1.id, p2.id, 0);
                                    }
                                    else
                                    {
                                        writer.WriteLine("{0} {1} {2} {3}", index, p1.id, p2.id,
                                                         checkmark.seg.boundary);
                                    }
                                }
                                else
                                {
                                    writer.WriteLine("{0} {1} {2} {3}", index, p1.id, p2.id,
                                                     trisym.tri.id == Mesh.DUMMY ? "1" : "0");
                                }
                            }
                            else
                            {
                                // Edge number, indices of two endpoints.
                                writer.WriteLine("{0} {1} {2}", index, p1.id, p2.id);
                            }

                            index++;
                        }
                    }
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Write the segments and holes to a .poly file.
        /// </summary>
        /// <param name="mesh">Data source.</param>
        /// <param name="filename">File name.</param>
        /// <param name="writeNodes">Write nodes into this file.</param>
        /// <remarks>If the nodes should not be written into this file,
        /// make sure a .node file was written before, so that the nodes
        /// are numbered right.</remarks>
        public void WritePoly(Mesh mesh, string filename, bool writeNodes)
        {
            Osub   subseg = default(Osub);
            Vertex pt1, pt2;

            bool useBoundaryMarkers = mesh.behavior.UseBoundaryMarkers;

            using (
#if NETFX_CORE
                var writer = new WinRTLegacy.IO.StreamWriter(filename)
#else
                var writer = new StreamWriter(filename)
#endif
                )
            {
                if (writeNodes)
                {
                    // Write nodes to this file.
                    WriteNodes(writer, mesh);
                }
                else
                {
                    // The zero indicates that the vertices are in a separate .node file.
                    // Followed by number of dimensions, number of vertex attributes,
                    // and number of boundary markers (zero or one).
                    writer.WriteLine("0 {0} {1} {2}", mesh.mesh_dim, mesh.nextras,
                                     useBoundaryMarkers ? "1" : "0");
                }

                // Number of segments, number of boundary markers (zero or one).
                writer.WriteLine("{0} {1}", mesh.subsegs.Count,
                                 useBoundaryMarkers ? "1" : "0");

                subseg.orient = 0;

                int j = 0;
                foreach (var item in mesh.subsegs.Values)
                {
                    subseg.seg = item;

                    pt1 = subseg.Org();
                    pt2 = subseg.Dest();

                    // Segment number, indices of its two endpoints, and possibly a marker.
                    if (useBoundaryMarkers)
                    {
                        writer.WriteLine("{0} {1} {2} {3}", j, pt1.id, pt2.id, subseg.seg.boundary);
                    }
                    else
                    {
                        writer.WriteLine("{0} {1} {2}", j, pt1.id, pt2.id);
                    }

                    j++;
                }

                // Holes
                j = 0;
                writer.WriteLine("{0}", mesh.holes.Count);
                foreach (var hole in mesh.holes)
                {
                    writer.WriteLine("{0} {1} {2}", j++, hole.X.ToString(nfi), hole.Y.ToString(nfi));
                }

                // Regions
                if (mesh.regions.Count > 0)
                {
                    j = 0;
                    writer.WriteLine("{0}", mesh.regions.Count);
                    foreach (var region in mesh.regions)
                    {
                        writer.WriteLine("{0} {1} {2} {3}", j, region.point.X.ToString(nfi),
                                         region.point.Y.ToString(nfi), region.id);

                        j++;
                    }
                }
            }
        }
コード例 #9
0
        /// <summary>
        /// Write the segments and holes to a .poly file.
        /// </summary>
        /// <param name="polygon">Data source.</param>
        /// <param name="filename">File name.</param>
        /// <param name="writeNodes">Write nodes into this file.</param>
        /// <remarks>If the nodes should not be written into this file,
        /// make sure a .node file was written before, so that the nodes
        /// are numbered right.</remarks>
        public void WritePoly(IPolygon polygon, string filename)
        {
            bool hasMarkers = polygon.HasSegmentMarkers;

            using (
#if NETFX_CORE
                var writer = new WinRTLegacy.IO.StreamWriter(filename)
#else
                var writer = new StreamWriter(filename)
#endif
                )
            {
                // TODO: write vertex attributes

                writer.WriteLine("{0} 2 0 {1}", polygon.Points.Count, polygon.HasPointMarkers ? "1" : "0");

                // Write nodes to this file.
                WriteNodes(writer, polygon.Points, polygon.HasPointMarkers, 0, false);

                // Number of segments, number of boundary markers (zero or one).
                writer.WriteLine("{0} {1}", polygon.Segments.Count, hasMarkers ? "1" : "0");

                Vertex p, q;

                int j = 0;
                foreach (var seg in polygon.Segments)
                {
                    p = seg.GetVertex(0);
                    q = seg.GetVertex(1);

                    // Segment number, indices of its two endpoints, and possibly a marker.
                    if (hasMarkers)
                    {
                        writer.WriteLine("{0} {1} {2} {3}", j, p.ID, q.ID, seg.Label);
                    }
                    else
                    {
                        writer.WriteLine("{0} {1} {2}", j, p.ID, q.ID);
                    }

                    j++;
                }

                // Holes
                j = 0;
                writer.WriteLine("{0}", polygon.Holes.Count);
                foreach (var hole in polygon.Holes)
                {
                    writer.WriteLine("{0} {1} {2}", j++, hole.X.ToString(nfi), hole.Y.ToString(nfi));
                }

                // Regions
                if (polygon.Regions.Count > 0)
                {
                    j = 0;
                    writer.WriteLine("{0}", polygon.Regions.Count);
                    foreach (var region in polygon.Regions)
                    {
                        writer.WriteLine("{0} {1} {2} {3}", j, region.point.X.ToString(nfi),
                                         region.point.Y.ToString(nfi), region.id);

                        j++;
                    }
                }
            }
        }