Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to show Note in Inspector #2

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Assets/EdNotes/Scripts/Editor/EditorNotes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static EditorNotes()

public static NotesContainer GetContainer(Scene scene)
{
if (cache == null)
if (cache == null || !cache.ContainsKey(scene))
{
cache = new Dictionary<Scene, NotesContainer>();
UpdateSceneCache();
Expand All @@ -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);
}

Expand Down
43 changes: 43 additions & 0 deletions Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs
Original file line number Diff line number Diff line change
@@ -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<Type, string>)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.TextArea($"{note.text}", EditorStyles.whiteLargeLabel);
}
else
EditorGUILayout.LabelField($"No Note has been saved for this GameObject, use Window > Notes", EditorStyles.boldLabel);
}
}



#endif
11 changes: 11 additions & 0 deletions Assets/EdNotes/Scripts/Editor/ShowEditorNoteInspector.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions Assets/EdNotes/Scripts/ShowEditorNote.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
using UnityEngine;

public class ShowEditorNote : MonoBehaviour
{
}
11 changes: 11 additions & 0 deletions Assets/EdNotes/Scripts/ShowEditorNote.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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].

Expand All @@ -16,5 +16,18 @@ 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`.

![editor_screenshot](https://github.com/mhardy/EdNotes/assets/115857/3acffcce-3f9b-4781-8bd7-f5aad04f80f2)


## Installation

- Click on Code > Download Zip

- Copy the folder : `Assets\EdNotes` to your `Assets` folder