Commit d5824a4c by Alisa Jung

added scale to xml level editor

parent 8d7d8d47
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
<Developer StartLevel="0" /> <Developer StartLevel="0" />
<Level> <Level>
<Item prefab="Ground" x="3.72" y="-0.81" /> <Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="Trap" x="-1.66" y="-0.57" rot="90" /> <Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
<Item prefab="Turret" x="5.11" y="4.23" rot="180" />
</Level> </Level>
<Level> <Level>
<Item prefab="PlayerStartPosition" x="5.11" y="-0.92" /> <Item prefab="PlayerStartPosition" x="5.11" y="-0.92" />
......
<?xml version="1.0" encoding="Windows-1252"?> <?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"> <Levels xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Level> <Level>
<Item prefab="Ground" x="3.72" y="-0.81" /> <Item prefab="Trap" x="-2.2" y="-0.1" rot="90" />
<Item prefab="Trap" x="-1.66" y="-0.57" rot="90" /> <Item prefab="ground" x="9.3" y="-0.7" scalex="200" />
<Item prefab="Turret" x="5.11" y="4.23" rot="180" />
</Level> </Level>
</Levels> </Levels>
\ No newline at end of file
...@@ -44,6 +44,12 @@ public class DeserializedLevels ...@@ -44,6 +44,12 @@ public class DeserializedLevels
[XmlAttribute ("rot")] [XmlAttribute ("rot")]
public string rot; public string rot;
[XmlAttribute("scalex")]
public string scalex;
[XmlAttribute("scaley")]
public string scaley;
} }
} }
...@@ -20,12 +20,8 @@ public class DeserializedLevelsLoader ...@@ -20,12 +20,8 @@ public class DeserializedLevelsLoader
public float x; public float x;
public float y; public float y;
public float rot; public float rot;
} public float scalex;
public float scaley;
struct PlayerStartPositionStruct
{
public float x;
public float y;
} }
// Cache prefabs in prefabDict // Cache prefabs in prefabDict
...@@ -88,6 +84,8 @@ public class DeserializedLevelsLoader ...@@ -88,6 +84,8 @@ public class DeserializedLevelsLoader
item.x = toFloatZeroIfNull(deserializedItem.x); item.x = toFloatZeroIfNull(deserializedItem.x);
item.y = toFloatZeroIfNull(deserializedItem.y); item.y = toFloatZeroIfNull(deserializedItem.y);
item.rot = toFloatZeroIfNull(deserializedItem.rot); item.rot = toFloatZeroIfNull(deserializedItem.rot);
item.scalex = toFloatOneIfNull(deserializedItem.scalex);
item.scaley = toFloatOneIfNull(deserializedItem.scaley);
sceneItemsList.Add(item); sceneItemsList.Add(item);
} }
...@@ -105,6 +103,8 @@ public class DeserializedLevelsLoader ...@@ -105,6 +103,8 @@ public class DeserializedLevelsLoader
// set rotation // set rotation
setRot2D(newGameObject, item.rot); setRot2D(newGameObject, item.rot);
setScale2D(newGameObject, item.scalex, item.scaley);
// set parent // set parent
newGameObject.transform.parent = parentOfXmlItems; newGameObject.transform.parent = parentOfXmlItems;
} }
...@@ -119,19 +119,22 @@ public class DeserializedLevelsLoader ...@@ -119,19 +119,22 @@ public class DeserializedLevelsLoader
void setPos2D(GameObject g, Vector2 pos) void setPos2D(GameObject g, Vector2 pos)
{ {
g.transform.position = new Vector3 ( g.transform.position = new Vector2 (
pos.x, pos.x,
pos.y, pos.y
g.transform.position.z
); );
} }
void setRot2D(GameObject g, float rot) 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; Quaternion rotation = Quaternion.identity;
rotation.eulerAngles = new Vector3(0, 0, rot); rotation.eulerAngles = new Vector3(0, 0, rot);
g.transform.localRotation = rotation; 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 ...@@ -45,6 +45,8 @@ public class DeserializedLevelsSaver
levelXml.items[i].x = toStringNullIfZero(item.transform.position.x); levelXml.items[i].x = toStringNullIfZero(item.transform.position.x);
levelXml.items[i].y = toStringNullIfZero(item.transform.position.y); levelXml.items[i].y = toStringNullIfZero(item.transform.position.y);
levelXml.items[i].rot = toStringNullIfZero(item.localRotation.eulerAngles.z); 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 // increase i for the next cycle
i++; 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