Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
erkerkiii committed Oct 23, 2021
1 parent 29bf82e commit 8f94b0f
Show file tree
Hide file tree
Showing 51 changed files with 3,212 additions and 0 deletions.
1 change: 1 addition & 0 deletions .idea/.idea.Assembly-CSharp-Editor.dir/.idea/.name

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

4 changes: 4 additions & 0 deletions .idea/.idea.Assembly-CSharp-Editor.dir/.idea/encodings.xml

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

8 changes: 8 additions & 0 deletions .idea/.idea.Assembly-CSharp-Editor.dir/.idea/indexLayout.xml

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.

54 changes: 54 additions & 0 deletions .idea/.idea.Assembly-CSharp-Editor.dir/.idea/workspace.xml

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

13 changes: 13 additions & 0 deletions .idea/.idea.EditorNotes/.idea/.gitignore

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

4 changes: 4 additions & 0 deletions .idea/.idea.EditorNotes/.idea/encodings.xml

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

8 changes: 8 additions & 0 deletions .idea/.idea.EditorNotes/.idea/indexLayout.xml

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

8 changes: 8 additions & 0 deletions Assets/EditorNotes.meta

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

8 changes: 8 additions & 0 deletions Assets/EditorNotes/Editor.meta

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

145 changes: 145 additions & 0 deletions Assets/EditorNotes/Editor/EditorNoteInspector.cs
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);
}
}
}
11 changes: 11 additions & 0 deletions Assets/EditorNotes/Editor/EditorNoteInspector.cs.meta

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

90 changes: 90 additions & 0 deletions Assets/EditorNotes/Editor/EditorNotesWindow.cs
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();
}
}
11 changes: 11 additions & 0 deletions Assets/EditorNotes/Editor/EditorNotesWindow.cs.meta

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

Loading

0 comments on commit 8f94b0f

Please sign in to comment.