<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
	<title type="html"><![CDATA[Infinity Code Forum — Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
	<link rel="self" href="https://forum.infinity-code.com/extern.php?action=feed&amp;tid=2281&amp;type=atom" />
	<updated>2024-06-12T12:40:20Z</updated>
	<generator>PunBB</generator>
	<id>https://forum.infinity-code.com/viewtopic.php?id=2281</id>
		<entry>
			<title type="html"><![CDATA[Re: Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9564#p9564" />
			<content type="html"><![CDATA[<p>That&#039;s great!<br />Thank you</p>]]></content>
			<author>
				<name><![CDATA[savvas_6]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1113</uri>
			</author>
			<updated>2024-06-12T12:40:20Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9564#p9564</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Re: Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9562#p9562" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[Alex Vertax]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=2</uri>
			</author>
			<updated>2024-06-12T10:02:48Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9562#p9562</id>
		</entry>
		<entry>
			<title type="html"><![CDATA[Save Playerprefs OnlineMapsDrawPoly shapes in XML and load on startup]]></title>
			<link rel="alternate" href="https://forum.infinity-code.com/viewtopic.php?pid=9559#p9559" />
			<content type="html"><![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>]]></content>
			<author>
				<name><![CDATA[savvas_6]]></name>
				<uri>https://forum.infinity-code.com/profile.php?id=1113</uri>
			</author>
			<updated>2024-06-11T18:57:39Z</updated>
			<id>https://forum.infinity-code.com/viewtopic.php?pid=9559#p9559</id>
		</entry>
</feed>
