<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<title><![CDATA[Infinity Code Forum — Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
		<link>https://forum.infinity-code.com/viewtopic.php?id=2281</link>
		<atom:link href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2281&amp;type=rss" rel="self" type="application/rss+xml" />
		<description><![CDATA[The most recent posts in Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup.]]></description>
		<lastBuildDate>Wed, 12 Jun 2024 12:40:20 +0000</lastBuildDate>
		<generator>PunBB</generator>
		<item>
			<title><![CDATA[Re: Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9564#p9564</link>
			<description><![CDATA[<p>That&#039;s great!<br />Thank you</p>]]></description>
			<author><![CDATA[null@example.com (savvas_6)]]></author>
			<pubDate>Wed, 12 Jun 2024 12:40:20 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9564#p9564</guid>
		</item>
		<item>
			<title><![CDATA[Re: Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9562#p9562</link>
			<description><![CDATA[<p>Hi. </p><p>Yes, do the following:<br />1. Use OnlineMapsVector2d instead of Vector2, everywhere when working with polygon points.<br />2. Use double.Parse instead of float.Parse, when reading points from xml.</p>]]></description>
			<author><![CDATA[null@example.com (Alex Vertax)]]></author>
			<pubDate>Wed, 12 Jun 2024 10:02:48 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9562#p9562</guid>
		</item>
		<item>
			<title><![CDATA[Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link>https://forum.infinity-code.com/viewtopic.php?pid=9559#p9559</link>
			<description><![CDATA[<p>Hi, im trying to save and load polygons.<br />When I load saved polygons I realise that are not in the exact position.<br />Is there any other way to store points of each polygon to double values? <br />It will be more accurate with double values instead float.</p><div class="codebox"><pre><code> 
         // Save Polygons to Playerprefs
        foreach (OnlineMapsDrawingPoly shape in SavedPolys)
        {
            OnlineMapsXML shapeNode = xml.Create(&quot;Poly&quot;);

            shapeNode.Create(&quot;Name&quot;, shape.name);
            shapeNode.Create(&quot;Color&quot;, shape.borderColor);
            shapeNode.Create(&quot;Width&quot;, shape.borderWidth);

            List&lt;string&gt; points = new List&lt;string&gt;();

            foreach (Vector2 r in shape.points)
            {
                points.Add(r.ToString());
            }

            shapeNode.Create(&quot;Points&quot;, string.Join(&quot;,&quot;, points));
        }

        PlayerPrefs.SetString(&quot;Shapes&quot;, xml.outerXml);
        PlayerPrefs.Save();



       // Load Polygons  from Playerprefs
        if (!PlayerPrefs.HasKey(&quot;Shapes&quot;)) return;

        string xmlContent = PlayerPrefs.GetString(&quot;Shapes&quot;);
        OnlineMapsXML xml = OnlineMapsXML.Load(xmlContent);

        if (xml != null) {

            foreach (OnlineMapsXML shapeNode in xml)
            {
               if (shapeNode.name == &quot;Poly&quot;)
                {

                    string pointsStr = shapeNode.Get&lt;string&gt;(&quot;Points&quot;);

                    pointsStr = pointsStr.Replace(&quot;)&quot;, &quot;&quot;);
                    pointsStr = pointsStr.Replace(&quot;(&quot;, &quot;&quot;);

                    string[] pointsArray = pointsStr.Split(&#039;,&#039;);

                    List&lt;Vector2&gt; points = new List&lt;Vector2&gt;();
                    for (int i = 0; i &lt; pointsArray.Length; i += 2)
                    {
                        float x = float.Parse(pointsArray[i]);
                        float y = float.Parse(pointsArray[i + 1]);
                        points.Add(new Vector2(x, y));
                    }

                    OnlineMapsDrawingPoly shape = new OnlineMapsDrawingPoly(points);

                    shape.name = shapeNode.Get&lt;string&gt;(&quot;Name&quot;);
                    shape.borderColor = shapeNode.Get&lt;Color&gt;(&quot;Color&quot;);
                    shape.borderWidth = shapeNode.Get&lt;float&gt;(&quot;Width&quot;);

                    OnlineMapsDrawingElementManager.AddItem(shape);

                    SavedPolys.Add(shape);
                }
        }</code></pre></div>]]></description>
			<author><![CDATA[null@example.com (savvas_6)]]></author>
			<pubDate>Tue, 11 Jun 2024 18:57:39 +0000</pubDate>
			<guid>https://forum.infinity-code.com/viewtopic.php?pid=9559#p9559</guid>
		</item>
	</channel>
</rss>
