public void Create() { //Create a quad and give the position and w/h if (IsLeaf()) { m_quad = m_assetFabric.GetRandomRoom(m_width, m_height, m_center); m_quad.transform.SetParent(transform); BSPDungeon dungeon = GameObject.FindObjectOfType <BSPDungeon>(); dungeon.AddLeaf(this); foreach (Door d in m_doors) { //Create a door GameObject door; if (d.position == 'u' || d.position == 'd') { door = m_assetFabric.GetDoor(d.center, d.size, false); } else { door = m_assetFabric.GetDoor(d.center, d.size, true); } if (door != null) { door.transform.SetParent(transform); } } } else { m_lChild.GetComponent <Room>().Create(); m_rChild.GetComponent <Room>().Create(); } }
void CreateChild(Vector3 center, float w, float h, bool left) { Room component = null; if (left) { if (m_lChild == null) { m_lChild = new GameObject("LChild"); m_lChild.transform.SetParent(transform); component = m_lChild.AddComponent <Room>(); } } else { if (m_rChild == null) { m_rChild = new GameObject("RChild"); m_rChild.transform.SetParent(transform); component = m_rChild.AddComponent <Room>(); } } if (component) { component.Init(); component.SetParent(gameObject); component.SetCenter(center); component.SetWidth(w); component.SetHeight(h); } BSPDungeon dungeon = GameObject.FindObjectOfType <BSPDungeon>(); dungeon.AddLeaf(component); }