private void ShowStatus() { var roomTemplate = (RoomTemplateSettings)target; var originalBackground = GUI.backgroundColor; Handles.BeginGUI(); GUILayout.BeginArea(new Rect(10, 10, 180, 100)); GUILayout.BeginVertical(EditorStyles.helpBox); GUILayout.Label("Room template status", EditorStyles.boldLabel); var isOutlineValid = roomTemplate.GetOutline() != null; var outlineText = isOutlineValid ? "valid" : "<color=#870526ff>invalid</color>"; var areDoorsValid = false; var doorsText = "N/A"; if (isOutlineValid) { var doorsCheck = RoomTemplateDiagnostics.CheckDoors(roomTemplate.gameObject); areDoorsValid = !doorsCheck.HasErrors; doorsText = !doorsCheck.HasErrors ? "valid" : "<color=#870526ff>invalid</color>"; if (areDoorsValid) { var wrongManualDoorsCheck = RoomTemplateDiagnostics.CheckWrongManualDoors(roomTemplate.gameObject, out var _); if (wrongManualDoorsCheck.HasErrors) { areDoorsValid = false; doorsText += $" <size=9><color=orange>(with warning)</color></size>"; } } } GUILayout.Label($"Outline: <b>{outlineText}</b>", new GUIStyle(EditorStyles.label) { richText = true }); GUILayout.Label($"Doors: <b>{doorsText}</b>", new GUIStyle(EditorStyles.label) { richText = true }); if (!isOutlineValid || !areDoorsValid) { GUILayout.Label($"<size=9>See the Room template settings component for details</size>", new GUIStyle(EditorStyles.label) { richText = true, wordWrap = true }); } GUILayout.EndVertical(); GUILayout.EndArea(); Handles.EndGUI(); GUI.backgroundColor = originalBackground; }
/// <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 ManualDoorsNotOnOutline() { var roomTemplate = GameObject.Find("ManualDoorsNotOnOutline"); 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); }
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); }