From 094160d1af0605fbd54d13aa1f1a713200ae21c3 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 28 Sep 2023 17:08:50 -0700 Subject: [PATCH 1/4] Added the ability to show the note in the Inspector by adding a simple ShowEditorNote type Updated the readme --- .../Scripts/Editor/ShowEditorNoteInspector.cs | 43 +++++++++++++++++++ .../Editor/ShowEditorNoteInspector.cs.meta | 11 +++++ Assets/EdNotes/Scripts/ShowEditorNote.cs | 5 +++ Assets/EdNotes/Scripts/ShowEditorNote.cs.meta | 11 +++++ README.md | 12 +++++- 5 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs create mode 100644 Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs.meta create mode 100644 Assets/EdNotes/Scripts/ShowEditorNote.cs create mode 100644 Assets/EdNotes/Scripts/ShowEditorNote.cs.meta diff --git a/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs new file mode 100644 index 0000000..57dbef3 --- /dev/null +++ b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs @@ -0,0 +1,43 @@ +#if UNITY_EDITOR + +using System; +using System.Collections.Generic; +using System.Reflection; +using EdNotes; +using UnityEditor; + +[CustomEditor(typeof(ShowEditorNote))] +public class ShowEditorNoteInspector : Editor +{ + private void Awake() + { + // thanks to SisusCo... + // https://forum.unity.com/threads/modifying-component-inspector-headers-for-component-folders.504247/ + + // Change our ShowEditorNote inspector headers to just show "Editor Note" + Type inspectorTitlesType = typeof(ObjectNames).GetNestedType("InspectorTitles", BindingFlags.Static | BindingFlags.NonPublic); + var inspectorTitlesField = inspectorTitlesType.GetField("s_InspectorTitles", BindingFlags.Static | BindingFlags.NonPublic); + var cache = (Dictionary)inspectorTitlesField.GetValue(null); + cache[typeof(ShowEditorNote)] = "Editor Note"; + } + + public override void OnInspectorGUI() + { + ShowEditorNote targetScript = (ShowEditorNote)target; + var instanceId = targetScript.gameObject.GetInstanceID(); + + NotesContainer c = EditorNotes.GetContainer(targetScript.gameObject.scene); + var inCache = c.Cache.ContainsKey(instanceId); + if( inCache ) + { + c.Cache.TryGetValue(instanceId, out Note note); + EditorGUILayout.LabelField($"{note.text}", EditorStyles.whiteLargeLabel); + } + else + EditorGUILayout.LabelField($"No Note has been saved for this GameObject, use Window > Notes", EditorStyles.boldLabel); + } +} + + + +#endif diff --git a/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs.meta b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs.meta new file mode 100644 index 0000000..505e466 --- /dev/null +++ b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c1d500737c68e304e846d0c511b38b18 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/EdNotes/Scripts/ShowEditorNote.cs b/Assets/EdNotes/Scripts/ShowEditorNote.cs new file mode 100644 index 0000000..041b05f --- /dev/null +++ b/Assets/EdNotes/Scripts/ShowEditorNote.cs @@ -0,0 +1,5 @@ +using UnityEngine; + +public class ShowEditorNote : MonoBehaviour +{ +} diff --git a/Assets/EdNotes/Scripts/ShowEditorNote.cs.meta b/Assets/EdNotes/Scripts/ShowEditorNote.cs.meta new file mode 100644 index 0000000..5d490cb --- /dev/null +++ b/Assets/EdNotes/Scripts/ShowEditorNote.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1e31692a69cbe364998b22a77ab117c7 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/README.md b/README.md index b67210b..f593a6d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Unity Editor Notes -A simple tool to add notes to GameObject in the Hierarchy or Objects in the Project panel. The notes data in the scene are kept in a hidden object tagged as `EditorOnly` so the data will not end up in your final builds. The data concerning project objects are kept in an asset next to the this tool's scripts by default. +A simple tool to add notes to GameObject in the **Hierarchy** or Objects in the **Project** panel. The notes data in the scene are kept in a hidden object tagged as `EditorOnly` so the data will not end up in your final builds. The data concerning project objects are kept in an asset next to the this tool's scripts by default. Open the Note panel via menu: `Window > Notes`. Enter some text and press [Save]. @@ -16,5 +16,15 @@ Click on the gear icon to show the Editor Notes settings where you can change th +## Display Note in Inspector + +To display the note in the Inspector pane when you click on a game object in the Hierarchy, Add Component of type `ShowEditorNote`. + +## Installation + +- Click on Code > Download Zip + +- Copy the folder : `Assets\EdNotes` to your `Assets` folder + From fc1b8070742ddf06ff297803d3e46bc195d38d4b Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 28 Sep 2023 17:23:05 -0700 Subject: [PATCH 2/4] Update READMEwith Inspector screen shot --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f593a6d..230adcb 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,9 @@ Click on the gear icon to show the Editor Notes settings where you can change th To display the note in the Inspector pane when you click on a game object in the Hierarchy, Add Component of type `ShowEditorNote`. +![editor_screenshot](https://github.com/mhardy/EdNotes/assets/115857/3acffcce-3f9b-4781-8bd7-f5aad04f80f2) + + ## Installation - Click on Code > Download Zip From 221111d425c427ae8c71273a8eae072b311c8575 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 28 Sep 2023 22:48:17 -0700 Subject: [PATCH 3/4] Fixed an issue where cache is not null but doesn't contain scene Fixed a null ref when scene closed --- Assets/EdNotes/Scripts/Editor/EditorNotes.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Assets/EdNotes/Scripts/Editor/EditorNotes.cs b/Assets/EdNotes/Scripts/Editor/EditorNotes.cs index f437cf5..04d8be4 100644 --- a/Assets/EdNotes/Scripts/Editor/EditorNotes.cs +++ b/Assets/EdNotes/Scripts/Editor/EditorNotes.cs @@ -29,7 +29,7 @@ static EditorNotes() public static NotesContainer GetContainer(Scene scene) { - if (cache == null) + if (cache == null || !cache.ContainsKey(scene)) { cache = new Dictionary(); UpdateSceneCache(); @@ -56,6 +56,7 @@ private static void SceneOpened(Scene scene, OpenSceneMode mode) private static void SceneClosed(Scene scene) { + if( cache == null ) return; if (cache.ContainsKey(scene)) cache.Remove(scene); } From 3fdd5ac0f61c18860215d3e703834a21994decb6 Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 28 Sep 2023 23:12:39 -0700 Subject: [PATCH 4/4] Changed ShowEditorNote to use TextArea so can see entire note. --- Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs index 57dbef3..e63c3d0 100644 --- a/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs +++ b/Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs @@ -31,7 +31,7 @@ public override void OnInspectorGUI() if( inCache ) { c.Cache.TryGetValue(instanceId, out Note note); - EditorGUILayout.LabelField($"{note.text}", EditorStyles.whiteLargeLabel); + EditorGUILayout.TextArea($"{note.text}", EditorStyles.whiteLargeLabel); } else EditorGUILayout.LabelField($"No Note has been saved for this GameObject, use Window > Notes", EditorStyles.boldLabel);