Commit e2ec477c by Alisa Jung

turrets are now loaded correctly from xml files.

parent e6b65d75
...@@ -122,6 +122,7 @@ public class DeserializedLevelsLoader ...@@ -122,6 +122,7 @@ public class DeserializedLevelsLoader
item.children[k].rot = toFloatZeroIfNull(child.rot); item.children[k].rot = toFloatZeroIfNull(child.rot);
item.children[k].scalex = toFloatOneIfNull(child.scalex); item.children[k].scalex = toFloatOneIfNull(child.scalex);
item.children[k].scaley = toFloatOneIfNull(child.scaley); item.children[k].scaley = toFloatOneIfNull(child.scaley);
k++;
} }
sceneItemsList.Add(item); sceneItemsList.Add(item);
...@@ -133,7 +134,6 @@ public class DeserializedLevelsLoader ...@@ -133,7 +134,6 @@ public class DeserializedLevelsLoader
// TODO load height coordinate from a directory // TODO load height coordinate from a directory
GameObject newGameObject = MonoBehaviour.Instantiate(item.prefab) as GameObject; GameObject newGameObject = MonoBehaviour.Instantiate(item.prefab) as GameObject;
// set position // set position
setPos2D(newGameObject, new Vector2(item.x, item.y)); setPos2D(newGameObject, new Vector2(item.x, item.y));
...@@ -144,18 +144,20 @@ public class DeserializedLevelsLoader ...@@ -144,18 +144,20 @@ public class DeserializedLevelsLoader
foreach (Transform t in newGameObject.GetComponentsInChildren<Transform>()) foreach (Transform t in newGameObject.GetComponentsInChildren<Transform>())
{ {
if (!(t.parent == null) && (t.parent.name.Equals(item.prefab))) if ((!(t.parent == null)) && (t.parent == newGameObject.transform))
{ {
bool found = false;
foreach (ItemChildStruct child in item.children) //Ja das ist wahrscheinlich Laufzeitmig nicht ideal, aber die Arrays haben eh nur eine Hand viele Elemente 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) if (t.name == child.name)
{ {
Debug.Log("Set child " + child.name); found = true;
setPos2D(t.gameObject, new Vector2(child.x, child.y)); setPos2D(t.gameObject, new Vector2(child.x, child.y));
setRot2D(t.gameObject, child.rot); setRot2D(t.gameObject, child.rot);
setScale2D(t.gameObject, child.scalex, child.scaley); setScale2D(t.gameObject, child.scalex, child.scaley);
} }
} }
if (!found) Debug.LogWarning("No matching xml element found for " + t.name);
} }
} }
// set parent // set parent
......
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