-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
using UnityEditor; | ||
using UnityEditor.SceneManagement; | ||
using UnityEngine; | ||
|
||
namespace EditorNotes.Editor | ||
{ | ||
[CustomEditor(typeof(Transform))] | ||
public class EditorNoteInspector : UnityEditor.Editor | ||
{ | ||
private static bool _showNotes; | ||
|
||
private bool _isGettingDeleted; | ||
|
||
private Note _note; | ||
|
||
private GUIStyle _guiStyle; | ||
|
||
private void OnEnable() | ||
{ | ||
_showNotes = EditorPrefs.GetBool("showEditorNotes", true); | ||
} | ||
|
||
public override void OnInspectorGUI() | ||
{ | ||
InitializeGUIStyle(); | ||
CheckNotes(); | ||
|
||
base.OnInspectorGUI(); | ||
|
||
if (_note != null) | ||
{ | ||
DrawTextArea(); | ||
} | ||
else | ||
{ | ||
if (GUILayout.Button("Create Notes", GUILayout.Height(50f))) | ||
{ | ||
CreateNote(); | ||
_note.content = "Start typing your notes here"; | ||
SaveNote(); | ||
} | ||
} | ||
} | ||
|
||
private void InitializeGUIStyle() | ||
{ | ||
if (_guiStyle != null) | ||
{ | ||
return; | ||
} | ||
|
||
_guiStyle = new GUIStyle | ||
{ | ||
fontSize = 18, | ||
richText = true | ||
}; | ||
} | ||
|
||
private void DrawTextArea() | ||
{ | ||
_showNotes = EditorGUILayout.BeginFoldoutHeaderGroup(_showNotes, "Notes"); | ||
if (!_showNotes) | ||
{ | ||
return; | ||
} | ||
|
||
EditorGUILayout.BeginVertical("window"); | ||
|
||
EditorGUILayout.BeginHorizontal(); | ||
|
||
EditorGUILayout.LabelField( | ||
$"<color=green><b>Notes for</b></color> <color=yellow><i>{target.name}</i></color>", _guiStyle); | ||
|
||
if (GUILayout.Button("Delete")) | ||
{ | ||
DeleteNote(); | ||
} | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
|
||
EditorGUILayout.Space(); | ||
|
||
_note.content = | ||
EditorGUILayout.TextArea(_note.content, GUILayout.MinHeight(50f)); | ||
|
||
EditorGUILayout.EndVertical(); | ||
EditorGUILayout.EndFoldoutHeaderGroup(); | ||
|
||
EditorUtility.SetDirty(target); | ||
} | ||
|
||
private void DeleteNote() | ||
{ | ||
_isGettingDeleted = true; | ||
EditorNoteContainer.DeleteNote(GetTargetGameObject()); | ||
|
||
SaveScene(); | ||
} | ||
|
||
private void CheckNotes() | ||
{ | ||
_note = EditorNoteContainer.GetNote(GetTargetObjectUniqueId()); | ||
} | ||
|
||
private void CreateNote() | ||
{ | ||
_note = EditorNoteContainer.AddNote(GetTargetGameObject()); | ||
|
||
SaveScene(); | ||
} | ||
|
||
private static void SaveScene() | ||
{ | ||
EditorSceneManager.SaveOpenScenes(); | ||
} | ||
|
||
private GameObject GetTargetGameObject() | ||
{ | ||
return ((Transform)target).gameObject; | ||
} | ||
|
||
private string GetTargetObjectUniqueId() | ||
{ | ||
return GetTargetGameObject().TryGetComponent(out EditorNoteUniqueIdLinker uniqueIdLinker) | ||
? uniqueIdLinker.Id | ||
: string.Empty; | ||
} | ||
|
||
private void SaveNote() | ||
{ | ||
if (_isGettingDeleted) | ||
{ | ||
return; | ||
} | ||
_note?.Save(); | ||
} | ||
|
||
private void OnDisable() | ||
{ | ||
SaveNote(); | ||
|
||
EditorPrefs.SetBool("showEditorNotes", _showNotes); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System.Linq; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace EditorNotes.Editor | ||
{ | ||
public class EditorNotesWindow : EditorWindow | ||
{ | ||
private GUIStyle _guiStyle; | ||
|
||
private GameObject[] _objectsWithNotes; | ||
|
||
[MenuItem("EditorNotes/Notes In Scene")] | ||
public static void Display() | ||
{ | ||
EditorNotesWindow window = GetWindow<EditorNotesWindow>(); | ||
window.titleContent = new GUIContent("Notes In Scene"); | ||
window.Show(); | ||
} | ||
|
||
private void OnGUI() | ||
{ | ||
if (_guiStyle == null) | ||
{ | ||
InitializeGUIStyle(); | ||
} | ||
|
||
if (_objectsWithNotes == null) | ||
{ | ||
LoadObjectsWithNotes(); | ||
} | ||
|
||
DrawObjectsWithNotes(); | ||
|
||
if (GUILayout.Button("Refresh")) | ||
{ | ||
LoadObjectsWithNotes(); | ||
} | ||
} | ||
|
||
private void InitializeGUIStyle() | ||
{ | ||
if (_guiStyle != null) | ||
{ | ||
return; | ||
} | ||
|
||
_guiStyle = new GUIStyle | ||
{ | ||
fontSize = 14, | ||
richText = true, | ||
alignment = TextAnchor.MiddleCenter | ||
}; | ||
} | ||
|
||
private void DrawObjectsWithNotes() | ||
{ | ||
EditorGUILayout.BeginVertical("window"); | ||
|
||
for (int index = 0; index < _objectsWithNotes?.Length; index++) | ||
{ | ||
GameObject gameObjectsWithNote = _objectsWithNotes[index]; | ||
|
||
DrawGameObjectWithNoteItem(gameObjectsWithNote); | ||
} | ||
|
||
EditorGUILayout.EndVertical(); | ||
} | ||
|
||
private void DrawGameObjectWithNoteItem(GameObject gameObjectsWithNote) | ||
{ | ||
Rect buttonRect = EditorGUILayout.BeginHorizontal("Button"); | ||
|
||
if (GUI.Button(buttonRect, GUIContent.none)) | ||
{ | ||
Selection.activeObject = gameObjectsWithNote; | ||
} | ||
|
||
GUILayout.Label($"<color=yellow>{gameObjectsWithNote.name}</color>", _guiStyle); | ||
|
||
EditorGUILayout.EndHorizontal(); | ||
} | ||
|
||
private void LoadObjectsWithNotes() => | ||
_objectsWithNotes = FindObjectsOfType<EditorNoteUniqueIdLinker>() | ||
.Where(u => !string.IsNullOrEmpty(u.Id)) | ||
.Select(u => u.gameObject) | ||
.ToArray(); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.