public void DrawComment(Comment comment, bool requireEdit = false) { if (requireEdit) { editMessagePath = rootMessage.propertyPath; requireEdit = false; } using (new GUILayout.HorizontalScope()) { TypeLabel(comment.computedType); StateLabel(comment.computedState); PriorityLabel(comment.computedPriority); GUILayout.FlexibleSpace(); EditorGUI.BeginChangeCheck(); EditorGUI.BeginDisabledGroup(comment.message.from != CommentsWindow.user); bool editRoot = DrawEditButton(this.editRoot); EditorGUI.EndDisabledGroup(); if (EditorGUI.EndChangeCheck()) { if (editRoot) { editMessagePath = rootMessage.propertyPath; } else { editMessagePath = string.Empty; } } } GUILayout.Space(6); if (editRoot) { serializedObject.Update(); EditorGUILayout.PropertyField(title); using (new GUILayout.HorizontalScope()) { EditorGUILayout.PropertyField(focus); if (!m_IsAsset && GUILayout.Button("Align to SceneView", GUILayout.ExpandWidth(true))) { focus.boolValue = true; if (SceneView.lastActiveSceneView != null) { SceneComment c = serializedObject.targetObject as SceneComment; c.gameObject.transform.position = SceneView.lastActiveSceneView.camera.transform.position; c.gameObject.transform.rotation = SceneView.lastActiveSceneView.camera.transform.rotation; } } } serializedObject.ApplyModifiedProperties(); CommentsWindow.RequestRefresh(); } else { GUILayout.Space(8); using (new GUILayout.HorizontalScope()) { GUILayout.Label(CommentEditor.GetPriorityContent(" " + title.stringValue, comment.computedPriority), Styles.title); GUILayout.FlexibleSpace(); } } GUILayout.Space(6); DrawMessage(rootMessage, -1); int replyCount = replies.arraySize; using (new GUILayout.HorizontalScope()) { GUILayout.Space(16); using (new GUILayout.VerticalScope()) { for (int i = 0; i < replyCount; i++) { DrawMessage(replies.GetArrayElementAtIndex(i), i); } } } }
void DrawMessage(SerializedProperty message, int replyIndex) { using (new EditorGUILayout.VerticalScope(Styles.message)) { SerializedProperty body = message.FindPropertyRelative("body"); SerializedProperty URL = message.FindPropertyRelative("URL"); SerializedProperty from = message.FindPropertyRelative("from"); SerializedProperty targets = message.FindPropertyRelative("attachedObjects"); SerializedProperty changeType = message.FindPropertyRelative("changeType"); SerializedProperty changeState = message.FindPropertyRelative("changeState"); SerializedProperty changePriority = message.FindPropertyRelative("changePriority"); SerializedProperty type = message.FindPropertyRelative("type"); SerializedProperty state = message.FindPropertyRelative("state"); SerializedProperty priority = message.FindPropertyRelative("priority"); if (editMessagePath == message.propertyPath) { message.serializedObject.Update(); EditorGUILayout.LabelField("Edit Message", EditorStyles.boldLabel); EditorGUILayout.PropertyField(body); EditorGUILayout.PropertyField(URL); EditorGUILayout.PropertyField(from); using (new EditorGUI.IndentLevelScope(1)) { EditorGUILayout.PropertyField(targets); } if (replyIndex >= 0) { EditorGUILayout.PropertyField(changeType); EditorGUILayout.PropertyField(changeState); EditorGUILayout.PropertyField(changePriority); } if (changeType.boolValue || replyIndex == -1) { EditorGUILayout.PropertyField(type); } if (changeState.boolValue || replyIndex == -1) { EditorGUILayout.PropertyField(state); } if (changePriority.boolValue || replyIndex == -1) { EditorGUILayout.PropertyField(priority); } using (new GUILayout.HorizontalScope()) { GUILayout.FlexibleSpace(); if (editMessagePath == message.propertyPath && GUILayout.Button("Apply", Styles.miniButton)) { editMessagePath = string.Empty; } if (replyIndex == replies.arraySize - 1 && from.stringValue == CommentsWindow.user && GUILayout.Button("Delete", Styles.miniButton)) { replies.serializedObject.Update(); replies.DeleteArrayElementAtIndex(replyIndex); replies.serializedObject.ApplyModifiedProperties(); CommentsWindow.RequestRefresh(); } } GUILayout.Space(2); message.serializedObject.ApplyModifiedProperties(); CommentsWindow.RequestRefresh(); } else // Display Message { using (new GUILayout.HorizontalScope()) { GUILayout.Label($"<b>From:</b> <color={(from.stringValue == CommentsWindow.user ? "lime" : "white")}><b>{from.stringValue}</b></color>", Styles.from); GUILayout.FlexibleSpace(); if (replyIndex > -1 && from.stringValue == CommentsWindow.user && GUILayout.Button(Styles.edit, Styles.miniButton, GUILayout.Width(32))) { editMessagePath = message.propertyPath; } if (GUILayout.Button(Styles.reply, Styles.miniButton, GUILayout.Width(32))) { replies.serializedObject.Update(); int index = replies.arraySize; replies.InsertArrayElementAtIndex(index); var reply = replies.GetArrayElementAtIndex(index); editMessagePath = reply.propertyPath; reply.FindPropertyRelative("body").stringValue = string.Empty; reply.FindPropertyRelative("URL").stringValue = string.Empty; reply.FindPropertyRelative("from").stringValue = CommentsWindow.user; reply.FindPropertyRelative("attachedObjects").ClearArray(); replies.serializedObject.ApplyModifiedProperties(); CommentsWindow.RequestRefresh(); } } EditorGUILayout.Space(); EditorGUILayout.LabelField(body.stringValue, Styles.multiline); if (!string.IsNullOrEmpty(URL.stringValue)) { GUILayout.Space(12); GUILayout.Label("URL:", EditorStyles.boldLabel, GUILayout.Width(32)); Color b = GUI.backgroundColor; GUI.backgroundColor = new Color(0, 0, 0, 0.2f); if (GUILayout.Button($"<color=#44AAFFFF>{URL.stringValue}</color>", Styles.link)) { Application.OpenURL(URL.stringValue); } GUI.backgroundColor = b; } if (targets.arraySize > 0) { GUILayout.Space(12); EditorGUILayout.LabelField("Attached Objects:", EditorStyles.boldLabel); EditorGUI.BeginDisabledGroup(true); for (int i = 0; i < targets.arraySize; i++) { EditorGUILayout.ObjectField(targets.GetArrayElementAtIndex(i)); } EditorGUI.EndDisabledGroup(); } if (replyIndex == -1 || changeType.boolValue || changeState.boolValue || changePriority.boolValue) { GUILayout.Space(12); using (new GUILayout.HorizontalScope()) { GUILayout.Label("<b>Set Properties :</b>", Styles.multiline); if (replyIndex == -1 || changeType.boolValue) { TypeLabel((CommentType)type.intValue); } if (replyIndex == -1 || changeState.boolValue) { StateLabel((CommentState)state.intValue); } if (replyIndex == -1 || changePriority.boolValue) { PriorityLabel((CommentPriority)priority.intValue); } GUILayout.FlexibleSpace(); } } } } GUI.contentColor = Color.white; }