Topic: iOS Drawing API
Hi,
I came across an issue while loading Shapes on iOS device using the Drawing API.
In Unity Editor I save and load Shapes without any issue.
On iOS device when loading shapes I get vertical lines from North to South poles of the earth.
I attach an image to see the issue on the device.
Below is my code for loading and saving shapes:
// Function to load shapes from PlayerPrefs
public void LoadShapes()
{
if (!PlayerPrefs.HasKey("Shapes")) return;
string xmlContent = PlayerPrefs.GetString("Shapes");
OnlineMapsXML xml = OnlineMapsXML.Load(xmlContent);
if (xml != null) {
foreach (OnlineMapsXML shapeNode in xml)
{
if (shapeNode.name == "Line") {
string pointsStr = shapeNode.Get<string>("Points");
//Debug.Log(pointsStr);
pointsStr = pointsStr.Replace("[", "");
pointsStr = pointsStr.Replace("]", "");
string[] pointsArray = pointsStr.Split(",");
List<OnlineMapsVector2d> points = new List<OnlineMapsVector2d>();
for (int i = 0; i < pointsArray.Length-1; i += 2)
{
double x = double.Parse(pointsArray[i]);
double y = double.Parse(pointsArray[i + 1]);
points.Add(new OnlineMapsVector2d(x, y));
}
OnlineMapsDrawingLine shape = new OnlineMapsDrawingLine(points);
shape.name = shapeNode.Get<string>("Name");
shape.color = shapeNode.Get<Color>("Color");
shape.width = shapeNode.Get<float>("Width");
OnlineMapsDrawingElementManager.AddItem(shape);
SavedLines.Add(shape);
}
if (shapeNode.name == "Poly")
{
string pointsStr = shapeNode.Get<string>("Points");
// Debug.Log(pointsStr);
pointsStr = pointsStr.Replace("]", "");
pointsStr = pointsStr.Replace("[", "");
string[] pointsArray = pointsStr.Split(",");
List<OnlineMapsVector2d> points = new List<OnlineMapsVector2d>();
for (int i = 0; i < pointsArray.Length; i += 2)
{
double x = double.Parse(pointsArray[i]);
double y = double.Parse(pointsArray[i + 1]);
points.Add(new OnlineMapsVector2d(x, y));
}
OnlineMapsDrawingPoly shape = new OnlineMapsDrawingPoly(points);
shape.name = shapeNode.Get<string>("Name");
shape.borderColor = shapeNode.Get<Color>("Color");
shape.borderWidth = shapeNode.Get<float>("Width");
OnlineMapsDrawingElementManager.AddItem(shape);
SavedPolys.Add(shape);
}
if (shapeNode.name == "Rect")
{
string tmp9 = shapeNode.Get<string>("BottomLeft");
string tmp8 = shapeNode.Get<string>("TopRight");
tmp9 = tmp9.Replace("><", ",");
tmp9 = tmp9.Replace(">", "");
tmp9 = tmp9.Replace("<", "");
tmp9 = tmp9.Replace("X", "");
tmp9 = tmp9.Replace("Y", "");
tmp9 = tmp9.Replace("/", "");
tmp8 = tmp8.Replace("><", ",");
tmp8 = tmp8.Replace(">", "");
tmp8 = tmp8.Replace("<", "");
tmp8 = tmp8.Replace("X", "");
tmp8 = tmp8.Replace("Y", "");
tmp8 = tmp8.Replace("/", "");
string[] pointsArrayBotLeft = tmp9.Split(",");
string[] pointsArrayTopRight = tmp8.Split(",");
OnlineMapsVector2d botLeft = new OnlineMapsVector2d(double.Parse(pointsArrayBotLeft[0]), double.Parse(pointsArrayBotLeft[1]));
OnlineMapsVector2d TopRight = new OnlineMapsVector2d(double.Parse(pointsArrayTopRight[0]), double.Parse(pointsArrayTopRight[1]));
OnlineMapsDrawingRect shape = new OnlineMapsDrawingRect(Vector2.zero, Vector2.zero);
shape.name = shapeNode.Get<string>("Name");
string l = shapeNode.Get<string>("Color");
string l2 = shapeNode.Get<string>("BackgroundColor");
l = l.Replace(")", "");
l = l.Replace("RGBA(", "");
l2 = l2.Replace(")", "");
l2 = l2.Replace("RGBA(", "");
string[] rgba = l.Split(",");
Color color1 = new Color(float.Parse(rgba[0]), float.Parse(rgba[1]), float.Parse(rgba[2]), float.Parse(rgba[3]));
string[] rgba2 = l2.Split(",");
Color color2 = new Color(float.Parse(rgba2[0]), float.Parse(rgba2[1]), float.Parse(rgba2[2]), float.Parse(rgba2[3]));
shape.borderColor = color1;
shape.backgroundColor = color2; //shapeNode.Get<Color>("BackgroundColor");
shape.borderWidth = shapeNode.Get<float>("Width");
shape.bottomLeft = botLeft;
shape.topRight = TopRight;
OnlineMapsDrawingElementManager.AddItem(shape);
SavedRects.Add(shape);
}
}
OnlineMaps.instance.Redraw();
// Build Shape List
CreateIndexingPagesPinakasShapes();
}
}
public void SaveShapes()
{
OnlineMapsXML xml = new OnlineMapsXML("Shapes");
// Lines
foreach (OnlineMapsDrawingLine shape in SavedLines)
{
OnlineMapsXML shapeNode = xml.Create("Line");
shapeNode.Create("Name", shape.name);
shapeNode.Create("Color", shape.color);
shapeNode.Create("Width", shape.width);
List<string> points = new List<string>();
foreach (OnlineMapsVector2d r in shape.points)
{
points.Add(r.ToString());
}
shapeNode.Create("Points", string.Join(",", points));
}
// Polygons
foreach (OnlineMapsDrawingPoly shape in SavedPolys)
{
OnlineMapsXML shapeNode = xml.Create("Poly");
shapeNode.Create("Name", shape.name);
shapeNode.Create("Color", shape.borderColor);
shapeNode.Create("Width", shape.borderWidth);
List<string> points = new List<string>();
foreach (OnlineMapsVector2d r in shape.points)
{
points.Add(r.ToString());
}
shapeNode.Create("Points", string.Join(",", points));
}
// Rectangles
foreach (OnlineMapsDrawingRect shape in SavedRects)
{
OnlineMapsXML shapeNode = xml.Create("Rect");
shapeNode.Create("Name", shape.name);
shapeNode.Create("Color", shape.borderColor.ToString());
shapeNode.Create("Width", shape.borderWidth);
shapeNode.Create("BackgroundColor", shape.backgroundColor.ToString());
//Debug.Log(shape.backgroundColor.ToString());
shapeNode.Create("BottomLeft", shape.bottomLeft);
shapeNode.Create("TopRight", shape.topRight);
}
PlayerPrefs.SetString("Shapes", xml.outerXml);
PlayerPrefs.Save();
// Build Shapes List
CreateIndexingPagesPinakasShapes();
}