|
| 1 | +using UnityEngine; |
| 2 | +using UnityEditor; |
| 3 | + |
| 4 | +namespace Sentry.Unity |
| 5 | +{ |
| 6 | + [CustomEditor(typeof(SentryUserFeedback))] |
| 7 | + public class SentryUserFeedbackEditor : UnityEditor.Editor |
| 8 | + { |
| 9 | + private SerializedProperty _openFeedbackButton; |
| 10 | + private SerializedProperty _feedbackForm; |
| 11 | + private SerializedProperty _sendFeedbackButton; |
| 12 | + private SerializedProperty _name; |
| 13 | + private SerializedProperty _email; |
| 14 | + private SerializedProperty _description; |
| 15 | + private SerializedProperty _addScreenshot; |
| 16 | + |
| 17 | + private void OnEnable() |
| 18 | + { |
| 19 | + _feedbackForm = serializedObject.FindProperty("_feedbackForm"); |
| 20 | + |
| 21 | + _openFeedbackButton = serializedObject.FindProperty("_openFeedbackButton"); |
| 22 | + _sendFeedbackButton = serializedObject.FindProperty("_sendFeedbackButton"); |
| 23 | + |
| 24 | + _name = serializedObject.FindProperty("_name"); |
| 25 | + _email = serializedObject.FindProperty("_email"); |
| 26 | + _description = serializedObject.FindProperty("_description"); |
| 27 | + _addScreenshot = serializedObject.FindProperty("_addScreenshot"); |
| 28 | + } |
| 29 | + |
| 30 | + public override void OnInspectorGUI() |
| 31 | + { |
| 32 | + serializedObject.Update(); |
| 33 | + |
| 34 | + EditorGUILayout.LabelField("Form", EditorStyles.boldLabel); |
| 35 | + |
| 36 | + DrawPropertyField(_feedbackForm, "Feedback Form", true); |
| 37 | + |
| 38 | + EditorGUILayout.Space(); |
| 39 | + |
| 40 | + EditorGUILayout.LabelField("Buttons", EditorStyles.boldLabel); |
| 41 | + |
| 42 | + DrawPropertyField(_openFeedbackButton, "Open Feedback Form Button", true); |
| 43 | + DrawPropertyField(_sendFeedbackButton, "Send Feedback Button", true); |
| 44 | + |
| 45 | + EditorGUILayout.Space(); |
| 46 | + |
| 47 | + EditorGUILayout.LabelField("Input Fields", EditorStyles.boldLabel); |
| 48 | + |
| 49 | + DrawPropertyField(_name, "Name Input Field", false); |
| 50 | + DrawPropertyField(_email, "Email Input Field", false); |
| 51 | + DrawPropertyField(_description, "Description Input Field", true); |
| 52 | + DrawPropertyField(_addScreenshot, "Add Screenshot Toggle", false); |
| 53 | + |
| 54 | + serializedObject.ApplyModifiedProperties(); |
| 55 | + } |
| 56 | + |
| 57 | + private static void DrawPropertyField(SerializedProperty property, string displayName, bool isRequired) |
| 58 | + { |
| 59 | + if (property.objectReferenceValue) |
| 60 | + { |
| 61 | + EditorGUILayout.PropertyField(property, new GUIContent(displayName)); |
| 62 | + } |
| 63 | + else |
| 64 | + { |
| 65 | + GUI.backgroundColor = isRequired ? Color.red : Color.yellow; |
| 66 | + EditorGUILayout.PropertyField(property, new GUIContent(displayName)); |
| 67 | + GUI.backgroundColor = Color.white; |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | +} |
0 commit comments