/// <summary> /// Computes a room room template from a given room template game object. /// </summary> /// <param name="roomTemplatePrefab"></param> /// <param name="roomTemplate"></param> /// <param name="result"></param> /// <returns></returns> public static bool TryGetRoomTemplate(GameObject roomTemplatePrefab, out RoomTemplateGrid2D roomTemplate, out ActionResult result) { roomTemplate = null; // Check that the room template has all the required components var requiredComponentsResult = RoomTemplateDiagnostics.CheckComponents(roomTemplatePrefab); if (requiredComponentsResult.HasErrors) { result = requiredComponentsResult; return(false); } PolygonGrid2D polygon = null; // TODO: improve try { polygon = GetPolygonFromRoomTemplate(roomTemplatePrefab); } catch (ArgumentException) { /* empty */ } // Check that the outline of the room template is valid if (polygon == null) { result = new ActionResult(); result.AddError("The outline of the room template is not valid. Please consult the documentation."); return(false); } var allowedTransformations = new List <TransformationGrid2D> { TransformationGrid2D.Identity }; var roomTemplateComponent = roomTemplatePrefab.GetComponent <RoomTemplateSettings>(); var repeatMode = roomTemplateComponent?.RepeatMode ?? RoomTemplateRepeatMode.AllowRepeat; var doors = roomTemplatePrefab.GetComponent <Doors>(); var doorMode = doors.GetDoorMode(); // Check that the doors are valid var doorsCheck = RoomTemplateDiagnostics.CheckDoors(polygon, doorMode); if (doorsCheck.HasErrors) { result = doorsCheck; return(false); } roomTemplate = new RoomTemplateGrid2D(polygon, doorMode, roomTemplatePrefab.name, repeatMode, allowedTransformations); result = new ActionResult(); return(true); }
public void NoDoors() { var roomTemplate = GameObject.Find("NoDoors"); Assert.That(roomTemplate, Is.Not.Null); var resultAll = RoomTemplateDiagnostics.CheckAll(roomTemplate); Assert.That(resultAll.HasErrors, Is.True); var resultComponents = RoomTemplateDiagnostics.CheckComponents(roomTemplate); Assert.That(resultComponents.HasErrors, Is.True); }
public void InvalidOutline() { var roomTemplate = GameObject.Find("InvalidOutline"); Assert.That(roomTemplate, Is.Not.Null); var resultAll = RoomTemplateDiagnostics.CheckAll(roomTemplate); Assert.That(resultAll.HasErrors, Is.True); var resultComponents = RoomTemplateDiagnostics.CheckComponents(roomTemplate); Assert.That(resultComponents.HasErrors, Is.False); }
public void HybridDoorsDuplicate() { var roomTemplate = GameObject.Find("HybridDoorsDuplicate"); Assert.That(roomTemplate, Is.Not.Null); var resultAll = RoomTemplateDiagnostics.CheckAll(roomTemplate); Assert.That(resultAll.HasErrors, Is.True); var resultComponents = RoomTemplateDiagnostics.CheckComponents(roomTemplate); Assert.That(resultComponents.HasErrors, Is.False); var resultDoors = RoomTemplateDiagnostics.CheckDoors(roomTemplate); Assert.That(resultDoors.HasErrors, Is.True); }