public ABLevel EncodeSymmetricalLevel() { float platformMiddlePoint = 0; ABLevel level = new ABLevel(); level.width = LevelList.Instance.GetCurrentLevel().width; level.camera = LevelList.Instance.GetCurrentLevel().camera; level.slingshot = LevelList.Instance.GetCurrentLevel().slingshot; level.birds = LevelList.Instance.GetCurrentLevel().birds; level.platforms = LevelList.Instance.GetCurrentLevel().platforms; level.horizontal = LevelList.Instance.GetCurrentLevel().horizontal; foreach (Transform child in GameObject.Find("Platforms").transform) { PlatData obj = new PlatData(); obj.type = child.name; obj.x = child.transform.position.x; obj.y = child.transform.position.y; obj.rotation = child.transform.rotation.eulerAngles.z; obj.scaleX = child.transform.localScale.x; obj.scaleY = child.transform.localScale.y; platformMiddlePoint += child.transform.position.x; // level.platforms.Add(obj); } platformMiddlePoint /= level.platforms.Count; PlatformMiddle = platformMiddlePoint; foreach (Transform child in GameObject.Find("Blocks").transform) { string type = child.name; float x = 2 * platformMiddlePoint; x = x - child.transform.position.x; float y = child.transform.position.y; float rotation = child.transform.rotation.eulerAngles.z; if (child.GetComponent <ABPig>() != null) { level.pigs.Add(new OBjData(type, rotation, x, y)); } else if (child.GetComponent <ABBlock>() != null) { string material = child.GetComponent <ABBlock>()._material.ToString(); level.blocks.Add(new BlockData(type, rotation, x, y, material)); } else if (child.GetComponent <ABTNT>() != null) { level.tnts.Add(new OBjData(type, rotation, x, y)); } } return(level); }
public ABLevel EncodeLevel() { ABLevel level = new ABLevel(); level.birds = new List <BirdData>(); level.pigs = new List <OBjData>(); level.blocks = new List <BlockData>(); level.platforms = new List <PlatData>(); foreach (Transform child in GameObject.Find("Birds").transform) { string type = child.name; level.birds.Add(new BirdData(type)); } foreach (Transform child in GameObject.Find("Blocks").transform) { string type = child.name; float x = child.transform.position.x; float y = child.transform.position.y; float rotation = child.transform.rotation.eulerAngles.z; if (child.GetComponent <ABPig> () != null) { level.pigs.Add(new OBjData(type, rotation, x, y)); } else if (child.GetComponent <ABBlock> () != null) { string material = child.GetComponent <ABBlock> ()._material.ToString(); level.blocks.Add(new BlockData(type, rotation, x, y, material)); } } foreach (Transform child in GameObject.Find("Platforms").transform) { PlatData obj = new PlatData(); obj.type = child.name; obj.x = child.transform.position.x; obj.y = child.transform.position.y; obj.rotation = child.transform.rotation.eulerAngles.z; obj.scaleX = child.transform.localScale.x; obj.scaleY = child.transform.localScale.y; level.platforms.Add(obj); } return(level); }