Skip to content

Instantly share code, notes, and snippets.

@jminor
Created September 13, 2020 07:49
Show Gist options
  • Save jminor/a0b9a40d322266e9ed13b800082d41fd to your computer and use it in GitHub Desktop.
Save jminor/a0b9a40d322266e9ed13b800082d41fd to your computer and use it in GitHub Desktop.
// This adds a simple text area for you to add comments
// to your GameObjects in the Unity inspector.
// Comments are saved with your scene, just like any other
// component on a GameObject.
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
#endif
public class Comment : MonoBehaviour
{
public string comment = "";
}
#if UNITY_EDITOR
[CustomEditor(typeof(Comment))]
public class CommentEditor : Editor
{
public override void OnInspectorGUI()
{
Comment _target = (Comment)target;
EditorGUI.BeginChangeCheck();
string newValue = GUILayout.TextArea(_target.comment);
if (EditorGUI.EndChangeCheck())
{
Undo.RecordObject(target, "Changed Comment");
_target.comment = newValue;
}
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment