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;
        }
Example #2
0
        public void WrongManualDoors()
        {
            var roomTemplate = GameObject.Find("WrongManualDoors");

            Assert.That(roomTemplate, Is.Not.Null);

            var resultAll = RoomTemplateDiagnostics.CheckAll(roomTemplate);

            Assert.That(resultAll.HasErrors, Is.False);

            var resultComponents = RoomTemplateDiagnostics.CheckWrongManualDoors(roomTemplate, out var _);

            Assert.That(resultComponents.HasErrors, Is.True);
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            DrawDefaultInspector();

            var roomTemplate  = (RoomTemplateSettings)target;
            var validityCheck = RoomTemplateDiagnostics.CheckAll(roomTemplate.gameObject);

            if (!validityCheck.HasErrors)
            {
                EditorGUILayout.HelpBox("The room template is valid.", MessageType.Info);

                var wrongManualDoorsCheck =
                    RoomTemplateDiagnostics.CheckWrongManualDoors(roomTemplate.gameObject, out var _);

                if (wrongManualDoorsCheck.HasErrors)
                {
                    EditorGUILayout.HelpBox(string.Join("\n", wrongManualDoorsCheck.Errors).Trim(), MessageType.Warning);
                }
            }
            else
            {
                var sb = new StringBuilder();
                sb.AppendLine("There are some problems with the room template:");

                var errors = string.Join("\n", validityCheck.Errors);
                sb.Append(errors);

                EditorGUILayout.HelpBox(sb.ToString(), MessageType.Error);
            }

            var hasOutlineOverride = roomTemplate.HasOutlineOverride();

            EditorGUILayout.HelpBox($"Using outline override: {hasOutlineOverride}", MessageType.None);

            if (hasOutlineOverride)
            {
                if (GUILayout.Button("Remove outline override", EditorStyles.miniButton))
                {
                    roomTemplate.RemoveOutlineOverride();
                }
            }
            else
            {
                if (GUILayout.Button("Add outline override", EditorStyles.miniButton))
                {
                    roomTemplate.AddOutlineOverride();
                }
            }

            var boundingBoxOutlineHandler = roomTemplate.GetComponent <BoundingBoxOutlineHandler>();
            var boundingBoxRemoved        = false;

            if (boundingBoxOutlineHandler == null)
            {
                if (GUILayout.Button("Add bounding box outline handler", EditorStyles.miniButton))
                {
                    roomTemplate.gameObject.AddComponent <BoundingBoxOutlineHandler>();
                    EditorUtility.SetDirty(roomTemplate);
                }
            }
            else
            {
                if (GUILayout.Button("Remove bounding box outline handler", EditorStyles.miniButton))
                {
                    DestroyImmediate(boundingBoxOutlineHandler, true);
                    boundingBoxRemoved = true;
                    EditorUtility.SetDirty(roomTemplate);
                }
            }

            serializedObject.ApplyModifiedProperties();

            if (boundingBoxRemoved)
            {
                GUIUtility.ExitGUI();
            }
        }