private GameObject CreateOneAreaRoof(Transform parent, HouseCreatorCollection collection) { GameObject Roof = new GameObject("roof"); Roof.transform.position = parent.transform.position; List <GridPoint> PointsToSpawn = new List <GridPoint>(); // 0-----1 // | | // | | // 2-----3 Vector3 Offset; if (Dir == new Vector3(1, 0, 0)) { Offset = new Vector3(0, 0, 1); } else { Offset = new Vector3(1, 0, 0); } GridPoint gp0 = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Dir * 0.5f); gp0.Dir = Dir; gp0.ForcedScale = new Vector3(-1, 1, 1); PointsToSpawn.Add(gp0); GridPoint gp1 = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Dir * 0.5f); gp1.Dir = Dir; PointsToSpawn.Add(gp1); GridPoint gp2 = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Offset + Dir * 0.5f); gp2.Dir = Dir * -1; PointsToSpawn.Add(gp2); GridPoint gp3 = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Offset + Dir * 0.5f); gp3.Dir = Dir * -1; gp3.ForcedScale = new Vector3(-1, 1, 1); PointsToSpawn.Add(gp3); foreach (GridPoint gp in PointsToSpawn) { if (Upstairs) { gp.IsTop = true; } gp.CreateGridObject(Roof.transform, collection, false); } Roof.transform.SetParent(parent); return(Roof); }
public void CreateSidePices(Transform parent, HouseCreatorCollection collection) { float width = GetWidth(); width -= 1f; Vector3 ScaleDir; if (Dir == new Vector3(1, 0, 0)) { ScaleDir = new Vector3(0, 0, 1); } else { ScaleDir = new Vector3(1, 0, 0); } List <GridPoint> pointsToSpawn = new List <GridPoint>(); float LoopRunning = width; if (width % 1 != 0) { LoopRunning -= 1f; } for (int i = 0; i < LoopRunning; i++) { //Front GridPoint newGP = new GridPoint(HouseCreatorBase.PointType.RoofStopper, Origin + (ScaleDir * .5f) + (ScaleDir * i)); newGP.Dir = ScaleDir; newGP.ForcedScale = new Vector3(1, 1, -1f); pointsToSpawn.Add(newGP); //back newGP = new GridPoint(HouseCreatorBase.PointType.RoofStopper, Origin + (ScaleDir * 0.5f) + (ScaleDir * i) + (Dir * GetLength())); newGP.Dir = ScaleDir; pointsToSpawn.Add(newGP); } if (width % 1 != 0 && width > 0) { //Front GridPoint newGP = new GridPoint(HouseCreatorBase.PointType.HalfRoofStopper, Origin + (ScaleDir * 1f) + (ScaleDir * (width - 1f))); newGP.Dir = ScaleDir; newGP.ForcedScale = new Vector3(1, 1, -1f); pointsToSpawn.Add(newGP); //Back newGP = new GridPoint(HouseCreatorBase.PointType.HalfRoofStopper, Origin + (ScaleDir * 1) + (ScaleDir * (width - 1f)) + (Dir * GetLength())); newGP.Dir = ScaleDir; pointsToSpawn.Add(newGP); } foreach (GridPoint gp in pointsToSpawn) { gp.CreateGridObject(parent.transform, collection, false); } }
void OnGUI() { m_houseCreatorCollection = (HouseCreatorCollection)EditorGUILayout.ObjectField(m_houseCreatorCollection, typeof(HouseCreatorCollection), true); if (GUILayout.Button("Create House From Selection")) { if (m_houseCreatorCollection == null) { ErrorMessage = "Select a House Creator Collection"; return; } else { ErrorMessage = ""; } GameObject[] CurrentSelection = Selection.gameObjects; if (CurrentSelection.Length != 0) { List <MeshFilter> allSelectedRenders = new List <MeshFilter>(); foreach (GameObject go in CurrentSelection) { if (go.GetComponent <Renderer>() != null) { allSelectedRenders.Add(go.GetComponent <MeshFilter>()); } go.SetActive(false); } if (allSelectedRenders.Count > 0) { GameObject CombinedMeshes = CombineMeshes(allSelectedRenders); HouseCreatorBase HCB = CombinedMeshes.AddComponent <HouseCreatorBase>(); HCB.GenerateHouse(m_houseCreatorCollection); } else { Debug.Log("Select Something with a rendere"); } } else { ErrorMessage = "You need to select something"; } } GUILayout.Label(""); if (ErrorMessage != "") { GUILayout.Label("Error:"); GUILayout.Label(ErrorMessage); } }
//TODO: Do this public GameObject CreateCornerObject(Transform parent, HouseCreatorCollection selectedCollection, Transform GridObject) { GameObject CornerObject = new GameObject("Corner Pillar"); CornerObject.transform.position = Location + parent.position; CornerObject.transform.SetParent(GridObject, true); MeshFilter mf = CornerObject.AddComponent <MeshFilter>(); MeshRenderer mr = CornerObject.AddComponent <MeshRenderer>(); Mesh m = selectedCollection.GetRandomCorner(); mf.mesh = m; mr.sharedMaterial = selectedCollection.DefaultMat; return(CornerObject); }
public void CreateUpstairsRoofPlain(Transform parent, HouseCreatorCollection collection) { if (GetWidth() > 1f) { Vector3 ScaleDir; if (Dir == new Vector3(1, 0, 0)) { ScaleDir = new Vector3(0, 0, 1); } else { ScaleDir = new Vector3(1, 0, 0); } //TODO: Magic number deciding Roof height Vector3 NewOrigin = Origin + ScaleDir * .5f + Vector3.up * .75f; Vector3 NewSize = Size - ScaleDir; RoofPlane newRoofPlane = new RoofPlane(NewOrigin, NewSize, true); newRoofPlane.CreateRoof(parent, collection); } }
public GameObject CreateGridObject(Transform parent, HouseCreatorCollection selectedCollection, bool IgnoreRoof = true) { if (!IsPointValid()) { return(null); } //TODO: FIX ROOF if (IgnoreRoof && IsRoofType()) { return(null); } GameObject GridObject = new GameObject("GridObject"); MeshFilter mf = GridObject.AddComponent <MeshFilter>(); MeshRenderer mr = GridObject.AddComponent <MeshRenderer>(); GridObject.transform.position = Location + parent.position; GridObject.transform.SetParent(parent); GridObject.transform.localRotation = Quaternion.LookRotation(Dir); GridObject.transform.Rotate(new Vector3(0, -90f, 0)); GridObject.transform.localScale = ForcedScale; Mesh m = selectedCollection.GetMeshBasedOnPointType(Type, IsTop, IsSmall); mf.mesh = m; mr.sharedMaterial = selectedCollection.DefaultMat; if (IsCorner && !IsRoofType()) { GameObject cornerObject = CreateCornerObject(parent, selectedCollection, GridObject.transform); cornerObject.transform.SetParent(GridObject.transform); } return(GridObject); }
public void GenerateHouse(HouseCreatorCollection collection) { HouseCollection = collection; CreateGrid(); SpawnArt(); }
public GameObject CreateRoof(Transform parent, HouseCreatorCollection collection) { //Outlier in case the roof is one 1x1 if (GetArea() == 1) { return(CreateOneAreaRoof(parent, collection)); } GameObject Roof = new GameObject("roof"); Roof.transform.position = parent.transform.position; List <GridPoint> PointsToSpawn = new List <GridPoint>(); float TestSize; Vector3 NonTestedSize; Vector3 FlipScale = new Vector3(-1, 1, 1); //Takes care of X Directed Roofs if (Dir == new Vector3(1, 0, 0)) { TestSize = Size.x; NonTestedSize = new Vector3(0, 0, Size.z); FlipScale = new Vector3(-1, 1, 1); } else { TestSize = Size.z; NonTestedSize = new Vector3(Size.x, 0, 0); Dir *= -1; if (Upstairs == false) { Origin = Origin + new Vector3(0, 0, Size.z); } } //Generating Roofs on one side for (int i = 0; i <= TestSize - 1f; i++) { HouseCreatorBase.PointType Type = HouseCreatorBase.PointType.Roof; if (i == 0 || i == TestSize - 1) { Type = HouseCreatorBase.PointType.RoofEnd; } GridPoint gp; if (i == 0) { gp = new GridPoint(Type, Origin + Dir * 1f); gp.ForcedScale = FlipScale; } else { gp = new GridPoint(Type, Origin + Dir * i); } gp.Dir = Dir; PointsToSpawn.Add(gp); } if (PointsToSpawn.Count != TestSize) { GridPoint gp = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Dir * TestSize - Dir * .5f); gp.Dir = Dir; PointsToSpawn.Add(gp); } if (GetWidth() >= 1f) { //Generating Roofs on the other side for (int i = (int)Mathf.Floor(TestSize); i > 0; i--) { HouseCreatorBase.PointType Type = HouseCreatorBase.PointType.Roof; if (i == 1 || (i == Mathf.Floor(TestSize) && Mathf.Floor(TestSize) == TestSize)) { Type = HouseCreatorBase.PointType.RoofEnd; } GridPoint gp; if ((i == Mathf.Floor(TestSize) && Mathf.Floor(TestSize) == TestSize)) { gp = new GridPoint(Type, Origin + NonTestedSize + Dir * (i - 1)); gp.ForcedScale = FlipScale; } else { gp = new GridPoint(Type, Origin + NonTestedSize + Dir * i); } gp.Dir = Dir * -1f; PointsToSpawn.Add(gp); } if (Mathf.Floor(TestSize) != TestSize) { GridPoint gp = new GridPoint(HouseCreatorBase.PointType.HalfRoofEnd, Origin + Dir * TestSize + NonTestedSize - Dir * 0.5f); gp.ForcedScale = FlipScale; gp.Dir = Dir * -1f; PointsToSpawn.Add(gp); } } foreach (GridPoint gp in PointsToSpawn) { if (Upstairs) { gp.IsTop = true; } if (GetWidth() < 1) { gp.IsSmall = true; } gp.CreateGridObject(Roof.transform, collection, false); } CreateSidePices(Roof.transform, collection); CreateUpstairsRoofPlain(Roof.transform, collection); Roof.transform.SetParent(parent); return(Roof); }