Commit 44aeacae by Alisa Jung

xml level editor can now handle children for prefabs. Also, added level.

For each prefab, each child has to have its unique name.
parent 769aa1ef
......@@ -12,6 +12,31 @@
<Item prefab="ground" x="4.69" y="-2.71" scalex="22.78" />
<Item prefab="ground" x="-4.7" y="-2.7" scalex="22.78" />
<Item prefab="ground" y="-4" scalex="60" />
<Item prefab="Turret" y="-0.59">
<children prefab="TurretBase" y="3.11" rot="180" />
<children prefab="Cannon" y="3.07" rot="180" scaley="4.02" />
<children prefab="TurretButton" x="0.1" y="-3.61" />
</Item>
<Item prefab="ground" x="-6.2" y="1.15" scalex="10" />
<Item prefab="ground" x="6.2" y="1.15" scalex="10" />
<Item prefab="PortableFire" x="-6.84" y="1.96" scalex="0.2" scaley="0.2">
<children prefab="flame_a_0005" x="-6.84" y="1.96" scalex="2" scaley="2" />
</Item>
<Item prefab="PortableFire" x="6.84" y="1.83" scalex="0.2" scaley="0.2">
<children prefab="flame_a_0005" x="6.84" y="1.83" scalex="2" scaley="2" />
</Item>
</Level>
<Level>
<Item prefab="Start_Position" x="5" />
<Item prefab="Start_Position" x="-5" />
<Item prefab="Start_Position" x="-2.5" />
<Item prefab="Start_Position" x="2.5" />
<Item prefab="ground" y="-1.5" scalex="22.78" />
<Item prefab="ground" x="-7.5" y="-0.38" rot="90" scalex="30" />
<Item prefab="ground" x="7.5" y="-0.38" rot="90" scalex="30" />
<Item prefab="ground" x="4.69" y="-2.71" scalex="22.78" />
<Item prefab="ground" x="-4.7" y="-2.7" scalex="22.78" />
<Item prefab="ground" y="-4" scalex="60" />
</Level>
<Level>
<Item prefab="Start_Position" x="5" />
......
fileFormatVersion: 2
guid: 35b793df4d97b407088a52900b7b2e30
timeCreated: 1433525392
licenseType: Free
TextScriptImporter:
userData:
assetBundleName:
assetBundleVariant:
......@@ -22,20 +22,14 @@ public class DeserializedLevels
public Item[] items;
}
public class PlayerStartPosition
{
[XmlAttribute("x")]
public string x;
[XmlAttribute("y")]
public string y;
}
public class Item
{
[XmlAttribute ("prefab")]
public string prefab;
[XmlElement("children")]
public Item[] children;
[XmlAttribute ("x")]
public string x;
......
......@@ -19,8 +19,20 @@ public class DeserializedLevelsLoader
public float rot;
public float scalex;
public float scaley;
public ItemChildStruct[] children;
}
struct ItemChildStruct
{
public string name;
public float x;
public float y;
public float rot;
public float scalex;
public float scaley;
}
// Cache prefabs in prefabDict
Dictionary<string,GameObject> prefabPool;
......@@ -96,6 +108,22 @@ public class DeserializedLevelsLoader
item.scalex = toFloatOneIfNull(deserializedItem.scalex);
item.scaley = toFloatOneIfNull(deserializedItem.scaley);
DeserializedLevels.Item[] children;
if (deserializedItem.children == null) children = new DeserializedLevels.Item[0];
else children = deserializedItem.children;
item.children = new ItemChildStruct[children.Length];
int k = 0;
foreach (DeserializedLevels.Item child in children)
{
item.children[k].name = child.prefab;
item.children[k].x = toFloatZeroIfNull(child.x);
item.children[k].y = toFloatZeroIfNull(child.y);
item.children[k].rot = toFloatZeroIfNull(child.rot);
item.children[k].scalex = toFloatOneIfNull(child.scalex);
item.children[k].scaley = toFloatOneIfNull(child.scaley);
}
sceneItemsList.Add(item);
}
......@@ -114,6 +142,22 @@ public class DeserializedLevelsLoader
setScale2D(newGameObject, item.scalex, item.scaley);
foreach (Transform t in newGameObject.GetComponentsInChildren<Transform>())
{
if (!(t.parent == null) && (!t.parent.name.Equals("XmlItems")))
{
foreach (ItemChildStruct child in item.children) //Ja das ist wahrscheinlich Laufzeitmig nicht ideal, aber die Arrays haben eh nur eine Hand viele Elemente
{
if (t.name == child.name)
{
Debug.Log("Set child " + child.name);
setPos2D(t.gameObject, new Vector2(child.x, child.y));
setRot2D(t.gameObject, child.rot);
setScale2D(t.gameObject, child.scalex, child.scaley);
}
}
}
}
// set parent
newGameObject.transform.parent = parentOfXmlItems;
}
......
......@@ -48,7 +48,32 @@ public class DeserializedLevelsSaver
levelXml.items[i].scalex = toStringNullIfOne(item.localScale.x);
levelXml.items[i].scaley = toStringNullIfOne(item.localScale.y);
// increase i for the next cycle
DeserializedLevels.Item[] children = new DeserializedLevels.Item[item.childCount];
Debug.Log("Child count for " + item.name + ": " + item.childCount);
int k = 0;
foreach (Transform t in item.GetComponentsInChildren<Transform>())
{
if (!t.parent.name.Equals("XmlItemsToExport"))
{
//GetComponentsInChildren gibt auch die Komponente aus dem Parent (also dem Objekt selbst) zurck
DeserializedLevels.Item child = new DeserializedLevels.Item();
Debug.Log("Add child " + t.name);
child.prefab = t.name;
child.x = toStringNullIfZero(t.position.x);
child.y = toStringNullIfZero(t.position.y);
child.rot = toStringNullIfZero(t.rotation.eulerAngles.z);
child.scalex = toStringNullIfOne(t.localScale.x);
child.scaley = toStringNullIfOne(t.localScale.y);
children[k] = child;
k++;
}
}
levelXml.items[i].children = (item.childCount > 0) ? children : null;
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