private Ground BuildFromMap(GroundMap groundMap) { Ground ground = GameObjectsFactory.getInstance().Create <Ground>(); ground.BuildFromMap(groundMap); ground.transform.parent = transform; return(ground); }
public void BuildFromMap(GroundMap map) { foreach (GroundBlockMap blockMap in map) { GroundBlock newBlock = GameObjectsFactory.getInstance().Create <GroundBlock>(); newBlock.BuildFromMap(blockMap); AddBlock(newBlock); } }
public static GameObjectsFactory getInstance() { if (instance == null) { instance = FindObjectOfType <GameObjectsFactory>(); if (instance == null) { instance = new GameObject("GameObjectFactory").AddComponent <GameObjectsFactory>(); } } return(instance); }
public void BuildFromMap(GroundBlockMap map) { snowSprite = transform.Find("Snow"); snowSprite.localScale = new Vector3(map.size.x, map.size.y, 0); transform.localPosition = new Vector3(map.position.x + ((float)map.size.x) / 2, -map.position.y - ((float)map.size.y) / 2, 0); //borders bool[] borders = map.GetBorders(); for (int d = 0; d < BorderDirections.count; d++) { if (borders[d]) { BlockBorder border = GameObjectsFactory.getInstance().Create <BlockBorder>(); border.name = "Border"; border.transform.parent = transform; switch ((BorderDirction)d) { case BorderDirction.North: border.transform.localPosition = new Vector3(0, ((float)map.size.y) / 2, 0); border.transform.localScale = new Vector3(map.size.x, borderWidth, 0); break; case BorderDirction.South: border.transform.localPosition = new Vector3(0, -((float)map.size.y) / 2 - southBorderWidth / 2, 0); border.transform.localScale = new Vector3(map.size.x, southBorderWidth, 0); border.GetComponent <SpriteRenderer>().sortingOrder = -1; break; case BorderDirction.East: border.transform.localPosition = new Vector3(-((float)map.size.x) / 2 + borderWidth / 2, 0, 0); border.transform.localScale = new Vector3(borderWidth, map.size.y, 0); border.GetComponent <SpriteRenderer>().sortingOrder = 1; break; case BorderDirction.West: border.transform.localPosition = new Vector3(((float)map.size.x) / 2 - borderWidth / 2, 0, 0); border.transform.localScale = new Vector3(borderWidth, map.size.y, 0); border.GetComponent <SpriteRenderer>().sortingOrder = 1; break; } } } //spots System.Collections.Generic.List <IntVector2> spots = map.GetSpots(); foreach (IntVector2 s in spots) { Spot spot = GameObjectsFactory.getInstance().Create <Spot>(); spot.name = "Spot"; spot.transform.parent = transform; spot.transform.localPosition = new Vector3(-((float)map.size.x) / 2 + s.x + 0.5f, ((float)map.size.y) / 2 - s.y - 0.5f, 0); spot.GetComponent <SpriteRenderer>().sortingOrder = 1; } //gameObjects gameObjects = new System.Collections.Generic.List <GameObject>(); System.Collections.Generic.List <IntVector2> mapPines = map.GetPines(); int flip = Random.Range(0, 2); foreach (IntVector2 p in mapPines) { Pine pine = GameObjectsFactory.getInstance().Create <Pine>(); pine.name = "Pine"; pine.transform.parent = transform; pine.transform.localPosition = new Vector3(-((float)map.size.x) / 2 + p.x + 0.5f, ((float)map.size.y) / 2 - p.y - 0.5f, 0); if (flip > 0) { pine.GetComponent <SpriteRenderer>().flipX = true; } gameObjects.Add(pine.gameObject); } //bar IntVector2 b = map.GetBar(); if (b != null) { Bar bar = GameObjectsFactory.getInstance().Create <Bar>(); bar.name = "Bar"; bar.transform.parent = transform; bar.transform.localPosition = new Vector3(-((float)map.size.x) / 2 + b.x + 0.5f, ((float)map.size.y) / 2 - b.y - 0.5f, 0); gameObjects.Add(bar.gameObject); } //depth SetDepth(map.GetDepth()); }