-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComment.cs
More file actions
77 lines (60 loc) · 1.65 KB
/
Comment.cs
File metadata and controls
77 lines (60 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// Copyright 2025 U.S. Federal Government (in countries where recognized)
// Copyright 2025 Dakota Crouchelli dakota.h.crouchelli.civ@us.navy.mil
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
namespace CREATIVE.Utility
{
/**
A monobehaviour script for adding a text field to an object
Useful for explaining an object with a lot of UnityEvent calls
*/
public class Comment: MonoBehaviour
{
[TextArea]
[field: SerializeField]
private string CommentText;
[field: SerializeField]
[field: HideInInspector]
private bool editMode;
#if UNITY_EDITOR
[CustomEditor(typeof(Comment))]
public class Editor : UnityEditor.Editor
{
public override void OnInspectorGUI()
{
serializedObject.Update();
SerializedProperty commentProperty = serializedObject.FindProperty(nameof(Comment.CommentText));
SerializedProperty editModeProperty = serializedObject.FindProperty(nameof(Comment.editMode));
if (editModeProperty.boolValue)
{
EditorGUILayout.PropertyField
(
commentProperty,
GUIContent.none,
GUILayout.Height(100)
);
EditorGUILayout.Space(20);
if (GUILayout.Button("Save"))
editModeProperty.boolValue = false;
}
else
{
GUIStyle labelStyle = EditorStyles.label;
labelStyle.wordWrap = true;
EditorGUILayout.LabelField
(
commentProperty.stringValue,
labelStyle
);
EditorGUILayout.Space(20);
if (GUILayout.Button("Edit"))
editModeProperty.boolValue = true;
}
serializedObject.ApplyModifiedProperties();
}
}
#endif
}
}