Skip to content

Commit 8f94b0f

Browse files
committed
initial commit
1 parent 29bf82e commit 8f94b0f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+3212
-0
lines changed

.idea/.idea.Assembly-CSharp-Editor.dir/.idea/.name

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Assembly-CSharp-Editor.dir/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Assembly-CSharp-Editor.dir/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Assembly-CSharp-Editor.dir/.idea/projectSettingsUpdater.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.Assembly-CSharp-Editor.dir/.idea/workspace.xml

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.EditorNotes/.idea/.gitignore

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.EditorNotes/.idea/encodings.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/.idea.EditorNotes/.idea/indexLayout.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/EditorNotes.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/EditorNotes/Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
using UnityEditor;
2+
using UnityEditor.SceneManagement;
3+
using UnityEngine;
4+
5+
namespace EditorNotes.Editor
6+
{
7+
[CustomEditor(typeof(Transform))]
8+
public class EditorNoteInspector : UnityEditor.Editor
9+
{
10+
private static bool _showNotes;
11+
12+
private bool _isGettingDeleted;
13+
14+
private Note _note;
15+
16+
private GUIStyle _guiStyle;
17+
18+
private void OnEnable()
19+
{
20+
_showNotes = EditorPrefs.GetBool("showEditorNotes", true);
21+
}
22+
23+
public override void OnInspectorGUI()
24+
{
25+
InitializeGUIStyle();
26+
CheckNotes();
27+
28+
base.OnInspectorGUI();
29+
30+
if (_note != null)
31+
{
32+
DrawTextArea();
33+
}
34+
else
35+
{
36+
if (GUILayout.Button("Create Notes", GUILayout.Height(50f)))
37+
{
38+
CreateNote();
39+
_note.content = "Start typing your notes here";
40+
SaveNote();
41+
}
42+
}
43+
}
44+
45+
private void InitializeGUIStyle()
46+
{
47+
if (_guiStyle != null)
48+
{
49+
return;
50+
}
51+
52+
_guiStyle = new GUIStyle
53+
{
54+
fontSize = 18,
55+
richText = true
56+
};
57+
}
58+
59+
private void DrawTextArea()
60+
{
61+
_showNotes = EditorGUILayout.BeginFoldoutHeaderGroup(_showNotes, "Notes");
62+
if (!_showNotes)
63+
{
64+
return;
65+
}
66+
67+
EditorGUILayout.BeginVertical("window");
68+
69+
EditorGUILayout.BeginHorizontal();
70+
71+
EditorGUILayout.LabelField(
72+
$"<color=green><b>Notes for</b></color> <color=yellow><i>{target.name}</i></color>", _guiStyle);
73+
74+
if (GUILayout.Button("Delete"))
75+
{
76+
DeleteNote();
77+
}
78+
79+
EditorGUILayout.EndHorizontal();
80+
81+
EditorGUILayout.Space();
82+
83+
_note.content =
84+
EditorGUILayout.TextArea(_note.content, GUILayout.MinHeight(50f));
85+
86+
EditorGUILayout.EndVertical();
87+
EditorGUILayout.EndFoldoutHeaderGroup();
88+
89+
EditorUtility.SetDirty(target);
90+
}
91+
92+
private void DeleteNote()
93+
{
94+
_isGettingDeleted = true;
95+
EditorNoteContainer.DeleteNote(GetTargetGameObject());
96+
97+
SaveScene();
98+
}
99+
100+
private void CheckNotes()
101+
{
102+
_note = EditorNoteContainer.GetNote(GetTargetObjectUniqueId());
103+
}
104+
105+
private void CreateNote()
106+
{
107+
_note = EditorNoteContainer.AddNote(GetTargetGameObject());
108+
109+
SaveScene();
110+
}
111+
112+
private static void SaveScene()
113+
{
114+
EditorSceneManager.SaveOpenScenes();
115+
}
116+
117+
private GameObject GetTargetGameObject()
118+
{
119+
return ((Transform)target).gameObject;
120+
}
121+
122+
private string GetTargetObjectUniqueId()
123+
{
124+
return GetTargetGameObject().TryGetComponent(out EditorNoteUniqueIdLinker uniqueIdLinker)
125+
? uniqueIdLinker.Id
126+
: string.Empty;
127+
}
128+
129+
private void SaveNote()
130+
{
131+
if (_isGettingDeleted)
132+
{
133+
return;
134+
}
135+
_note?.Save();
136+
}
137+
138+
private void OnDisable()
139+
{
140+
SaveNote();
141+
142+
EditorPrefs.SetBool("showEditorNotes", _showNotes);
143+
}
144+
}
145+
}

Assets/EditorNotes/Editor/EditorNoteInspector.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
using System.Linq;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace EditorNotes.Editor
6+
{
7+
public class EditorNotesWindow : EditorWindow
8+
{
9+
private GUIStyle _guiStyle;
10+
11+
private GameObject[] _objectsWithNotes;
12+
13+
[MenuItem("EditorNotes/Notes In Scene")]
14+
public static void Display()
15+
{
16+
EditorNotesWindow window = GetWindow<EditorNotesWindow>();
17+
window.titleContent = new GUIContent("Notes In Scene");
18+
window.Show();
19+
}
20+
21+
private void OnGUI()
22+
{
23+
if (_guiStyle == null)
24+
{
25+
InitializeGUIStyle();
26+
}
27+
28+
if (_objectsWithNotes == null)
29+
{
30+
LoadObjectsWithNotes();
31+
}
32+
33+
DrawObjectsWithNotes();
34+
35+
if (GUILayout.Button("Refresh"))
36+
{
37+
LoadObjectsWithNotes();
38+
}
39+
}
40+
41+
private void InitializeGUIStyle()
42+
{
43+
if (_guiStyle != null)
44+
{
45+
return;
46+
}
47+
48+
_guiStyle = new GUIStyle
49+
{
50+
fontSize = 14,
51+
richText = true,
52+
alignment = TextAnchor.MiddleCenter
53+
};
54+
}
55+
56+
private void DrawObjectsWithNotes()
57+
{
58+
EditorGUILayout.BeginVertical("window");
59+
60+
for (int index = 0; index < _objectsWithNotes?.Length; index++)
61+
{
62+
GameObject gameObjectsWithNote = _objectsWithNotes[index];
63+
64+
DrawGameObjectWithNoteItem(gameObjectsWithNote);
65+
}
66+
67+
EditorGUILayout.EndVertical();
68+
}
69+
70+
private void DrawGameObjectWithNoteItem(GameObject gameObjectsWithNote)
71+
{
72+
Rect buttonRect = EditorGUILayout.BeginHorizontal("Button");
73+
74+
if (GUI.Button(buttonRect, GUIContent.none))
75+
{
76+
Selection.activeObject = gameObjectsWithNote;
77+
}
78+
79+
GUILayout.Label($"<color=yellow>{gameObjectsWithNote.name}</color>", _guiStyle);
80+
81+
EditorGUILayout.EndHorizontal();
82+
}
83+
84+
private void LoadObjectsWithNotes() =>
85+
_objectsWithNotes = FindObjectsOfType<EditorNoteUniqueIdLinker>()
86+
.Where(u => !string.IsNullOrEmpty(u.Id))
87+
.Select(u => u.gameObject)
88+
.ToArray();
89+
}
90+
}

Assets/EditorNotes/Editor/EditorNotesWindow.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)