Tanoda
CommentEditor.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10using UnityEditor;
11
12namespace Leap.Unity {
13
14 [CustomEditor(typeof(Comment))]
15 public class CommentEditor : CustomEditorBase<Comment> {
16
17 private SerializedProperty _isEditing;
18 private GUIStyle _editStyle;
19 private GUIStyle _displayStyle;
20
21 protected override void OnEnable() {
22 base.OnEnable();
23
24 _isEditing = serializedObject.FindProperty("_isEditing");
25
27
28 specifyCustomDrawer("_comment", drawComment);
29 }
30
31 private void drawComment(SerializedProperty commentProp) {
32 string text = commentProp.stringValue;
33
34 if (_editStyle == null) {
35 _editStyle = new GUIStyle(EditorStyles.textArea);
36 _editStyle.wordWrap = true;
37 }
38
39 if (_displayStyle == null) {
40 _displayStyle = new GUIStyle(EditorStyles.label);
41 _displayStyle.wordWrap = true;
42 _displayStyle.richText = true;
43 }
44
45 if (string.IsNullOrEmpty(text)) {
46 _isEditing.boolValue = true;
47 }
48
49 if (_isEditing.boolValue) {
50 if (GUILayout.Button("Finish")) {
51 _isEditing.boolValue = false;
52 }
53
54 commentProp.stringValue = EditorGUILayout.TextArea(text, _editStyle);
55 } else {
56 EditorGUILayout.Space();
57 var rect = GUILayoutUtility.GetRect(new GUIContent(text), _displayStyle);
58 EditorGUI.SelectableLabel(rect, text, _displayStyle);
59 }
60 }
61
62 }
63}
override void OnEnable()
void specifyCustomDrawer(string propertyName, Action< SerializedProperty > propertyDrawer)
Specify a callback to be used to draw a specific named property. Should be called in OnEnable.