Commit d5824a4c by Alisa Jung

added scale to xml level editor

parent 8d7d8d47
......@@ -4,9 +4,8 @@
<Developer StartLevel="0" />
<Level>
<Item prefab="Ground" x="3.72" y="-0.81" />
<Item prefab="Trap" x="-1.66" y="-0.57" rot="90" />
<Item prefab="Turret" x="5.11" y="4.23" rot="180" />
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
</Level>
<Level>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
......
<?xml version="1.0" encoding="Windows-1252"?>
<Levels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Level>
<Item prefab="Ground" x="3.72" y="-0.81" />
<Item prefab="Trap" x="-1.66" y="-0.57" rot="90" />
<Item prefab="Turret" x="5.11" y="4.23" rot="180" />
<Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
</Level>
</Levels>
\ No newline at end of file
......@@ -44,6 +44,12 @@ public class DeserializedLevels
[XmlAttribute ("rot")]
public string rot;
[XmlAttribute("scalex")]
public string scalex;
[XmlAttribute("scaley")]
public string scaley;
}
}
......@@ -20,12 +20,8 @@ public class DeserializedLevelsLoader
public float x;
public float y;
public float rot;
}
struct PlayerStartPositionStruct
{
public float x;
public float y;
public float scalex;
public float scaley;
}
// Cache prefabs in prefabDict
......@@ -88,6 +84,8 @@ public class DeserializedLevelsLoader
item.x = toFloatZeroIfNull(deserializedItem.x);
item.y = toFloatZeroIfNull(deserializedItem.y);
item.rot = toFloatZeroIfNull(deserializedItem.rot);
item.scalex = toFloatOneIfNull(deserializedItem.scalex);
item.scaley = toFloatOneIfNull(deserializedItem.scaley);
sceneItemsList.Add(item);
}
......@@ -105,6 +103,8 @@ public class DeserializedLevelsLoader
// set rotation
setRot2D(newGameObject, item.rot);
setScale2D(newGameObject, item.scalex, item.scaley);
// set parent
newGameObject.transform.parent = parentOfXmlItems;
}
......@@ -119,19 +119,22 @@ public class DeserializedLevelsLoader
void setPos2D(GameObject g, Vector2 pos)
{
g.transform.position = new Vector3 (
g.transform.position = new Vector2 (
pos.x,
pos.y,
g.transform.position.z
pos.y
);
}
void setRot2D(GameObject g, float rot)
{
Debug.Log("Set rotation of " + g.name + " to " + rot);
//Debug.Log("Set rotation of " + g.name + " to " + rot);
Quaternion rotation = Quaternion.identity;
rotation.eulerAngles = new Vector3(0, 0, rot);
g.transform.localRotation = rotation;
}
void setScale2D(GameObject g, float scaleX, float scaleY)
{
g.transform.localScale = new Vector2(scaleX, scaleY);
}
}
......@@ -45,6 +45,8 @@ public class DeserializedLevelsSaver
levelXml.items[i].x = toStringNullIfZero(item.transform.position.x);
levelXml.items[i].y = toStringNullIfZero(item.transform.position.y);
levelXml.items[i].rot = toStringNullIfZero(item.localRotation.eulerAngles.z);
levelXml.items[i].scalex = toStringNullIfOne(item.localScale.x);
levelXml.items[i].scaley = toStringNullIfOne(item.localScale.y);
// increase i for the next cycle
i++;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment