Ejemplo n.º 1
0
    /// <summary>
    /// Write marker list to an xml file stored in application storage.
    /// </summary>
    private void _SaveMarkerToDisk()
    {
        // Compose a XML data list.
        List <MarkerData> xmlDataList = new List <MarkerData> ();
        List <WallXML>    xmlWallList = new List <WallXML> ();

        foreach (GameObject obj in m_markerList)
        {
            // Add marks data to the list, we intentionally didn't add the timestamp, because the timestamp will not be
            // useful when the next time Tango Service is connected. The timestamp is only used for loop closure pose
            // correction in current Tango connection.
            MarkerData temp = new MarkerData();
            temp.m_type        = obj.GetComponent <ARMarker> ().m_type;
            temp.m_position    = obj.transform.position;
            temp.m_orientation = obj.transform.rotation;
            temp.m_id          = obj.GetInstanceID();
            // The name is useful only for destinations.
            temp.m_name = obj.name;
            xmlDataList.Add(temp);
        }

        // Create also an XML in order to keep track of the existing walls.
        foreach (Wall w in walls)
        {
            WallXML tmp = new WallXML();
            tmp.m_startCornerID = w.fromCorner.point.GetInstanceID();
            tmp.m_endCornerID   = w.toCorner.point.GetInstanceID();
            xmlWallList.Add(tmp);
        }

        string path       = Application.persistentDataPath + "/" + m_curAreaDescription.m_uuid + "Marker.xml";
        var    serializer = new XmlSerializer(typeof(List <MarkerData>));

        using (var stream = new FileStream(path, FileMode.Create)) {
            serializer.Serialize(stream, xmlDataList);
        }

        path       = Application.persistentDataPath + "/" + m_curAreaDescription.m_uuid + "Wall.xml";
        serializer = new XmlSerializer(typeof(List <WallXML>));
        using (var stream = new FileStream(path, FileMode.Create)) {
            serializer.Serialize(stream, xmlWallList);
        }
    }
Ejemplo n.º 2
0
 /// <summary>
 /// Saves the file in XML format to the given Stream.
 /// </summary>
 /// <param name="saveFile">Stream to pass in, usually from a SaveFileDialog, to which to save the file.</param>
 public void saveLevelXML(Stream saveFile)
 {
     FileStream fileStream = (FileStream)saveFile;//new FileStream(filepath, FileMode.OpenOrCreate);
     XmlSerializer xml = new XmlSerializer(typeof(LevelXML));
     LevelXML levelXML = new LevelXML();
     levelXML.Name = LevelName;
     levelXML.sizeX = simpleLevelGrid.SizeX;
     levelXML.sizeY = simpleLevelGrid.SizeY;
     for (int i = 0; i < levelXML.sizeX; ++i)
     {
         RowXML newRow = new RowXML();
         newRow.index = i;
         for (int j = 0; j < levelXML.sizeY; ++j)
         {
             ColumnXML newCol = new ColumnXML();
             newCol.index = j;
             newCol.type = simpleLevelGrid.GridSpaces[i, j].SpaceType;
             newCol.elevation = simpleLevelGrid.GridSpaces[i,j].Elevation;
             if (simpleLevelGrid.GridSpaces[i, j].IsOccupied)
             {
                 Actor temp = simpleLevelGrid.GridSpaces[i,j].CurrentActor;
                 if (temp is Hero)
                 {
                     Hero tempH = (Hero) temp;
                     newCol.hero = new HeroXML();
                     newCol.hero.name = tempH.Name;
                     newCol.hero.moveSpeed = tempH.MoveSpeed;
                     newCol.hero.currentEnergy = tempH.Energy;
                     newCol.hero.currentHP = tempH.Health;
                     newCol.hero.maxEnergy = tempH.MaxEnergy;
                     newCol.hero.maxHP = tempH.MaximumHealth;
                     newCol.hero.team = tempH.TeamIndex;
                     newCol.hero.classNum = tempH.ClassIndex;
                     newCol.hero.level = tempH.Level;
                 }
                 else if (temp is Person)
                 {
                     Person tempP = (Person)temp;
                     newCol.person = new PersonXML();
                     newCol.person.name = tempP.Name;
                     newCol.person.moveSpeed = tempP.MoveSpeed;
                     newCol.person.currentEnergy = tempP.Energy;
                     newCol.person.currentHP = tempP.Health;
                     newCol.person.maxEnergy = tempP.MaxEnergy;
                     newCol.person.maxHP = tempP.MaximumHealth;
                 }
                 else
                 {
                     newCol.actor = new ActorXML();
                     newCol.actor.name = temp.Name;
                 }
                 newCol.costNorth = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                 newCol.costNorthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                 newCol.costNorthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                 newCol.costSouth = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                 newCol.costSouthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                 newCol.costSouthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                 for (int k = 0; k < 3; ++k)
                 {
                     WallXML newWall = new WallXML();
                     newWall.direction = k;
                     newWall.type = simpleLevelGrid.GridSpaces[i, j].Walls[k].WallType;
                     newCol.walls.Add(newWall);
                 }
             }
             newRow.columns.Add(newCol);
         }
         levelXML.rows.Add(newRow);
     }
     xml.Serialize(fileStream, levelXML);
     fileStream.Close();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Saves the file in XML format to the given Stream.
        /// </summary>
        /// <param name="saveFile">Stream to pass in, usually from a SaveFileDialog, to which to save the file.</param>
        public void saveLevelXML(Stream saveFile)
        {
            FileStream    fileStream = (FileStream)saveFile;//new FileStream(filepath, FileMode.OpenOrCreate);
            XmlSerializer xml        = new XmlSerializer(typeof(LevelXML));
            LevelXML      levelXML   = new LevelXML();

            levelXML.Name  = LevelName;
            levelXML.sizeX = simpleLevelGrid.SizeX;
            levelXML.sizeY = simpleLevelGrid.SizeY;
            for (int i = 0; i < levelXML.sizeX; ++i)
            {
                RowXML newRow = new RowXML();
                newRow.index = i;
                for (int j = 0; j < levelXML.sizeY; ++j)
                {
                    ColumnXML newCol = new ColumnXML();
                    newCol.index     = j;
                    newCol.type      = simpleLevelGrid.GridSpaces[i, j].SpaceType;
                    newCol.elevation = simpleLevelGrid.GridSpaces[i, j].Elevation;
                    if (simpleLevelGrid.GridSpaces[i, j].IsOccupied)
                    {
                        Actor temp = simpleLevelGrid.GridSpaces[i, j].CurrentActor;
                        if (temp is Hero)
                        {
                            Hero tempH = (Hero)temp;
                            newCol.hero               = new HeroXML();
                            newCol.hero.name          = tempH.Name;
                            newCol.hero.moveSpeed     = tempH.MoveSpeed;
                            newCol.hero.currentEnergy = tempH.Energy;
                            newCol.hero.currentHP     = tempH.Health;
                            newCol.hero.maxEnergy     = tempH.MaxEnergy;
                            newCol.hero.maxHP         = tempH.MaximumHealth;
                            newCol.hero.team          = tempH.TeamIndex;
                            newCol.hero.classNum      = tempH.ClassIndex;
                            newCol.hero.level         = tempH.Level;
                        }
                        else if (temp is Person)
                        {
                            Person tempP = (Person)temp;
                            newCol.person               = new PersonXML();
                            newCol.person.name          = tempP.Name;
                            newCol.person.moveSpeed     = tempP.MoveSpeed;
                            newCol.person.currentEnergy = tempP.Energy;
                            newCol.person.currentHP     = tempP.Health;
                            newCol.person.maxEnergy     = tempP.MaxEnergy;
                            newCol.person.maxHP         = tempP.MaximumHealth;
                        }
                        else
                        {
                            newCol.actor      = new ActorXML();
                            newCol.actor.name = temp.Name;
                        }
                        newCol.costNorth     = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                        newCol.costNorthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                        newCol.costNorthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? -1 : 0)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? -1 : 0)] : 0;
                        newCol.costSouth     = simpleLevelGrid.withinGrid(i, j - 1) ? simpleLevelGrid.MoveCosts[i, j, i, j - 1] : 0;
                        newCol.costSouthEast = simpleLevelGrid.withinGrid(i + 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i + 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                        newCol.costSouthWest = simpleLevelGrid.withinGrid(i - 1, j + (i % 2 == 0 ? 0 : 1)) ? simpleLevelGrid.MoveCosts[i, j, i - 1, j + (i % 2 == 0 ? 0 : 1)] : 0;
                        for (int k = 0; k < 3; ++k)
                        {
                            WallXML newWall = new WallXML();
                            newWall.direction = k;
                            newWall.type      = simpleLevelGrid.GridSpaces[i, j].Walls[k].WallType;
                            newCol.walls.Add(newWall);
                        }
                    }
                    newRow.columns.Add(newCol);
                }
                levelXML.rows.Add(newRow);
            }
            xml.Serialize(fileStream, levelXML);
            fileStream.Close();
        }