├── Documents~ └── imgs │ ├── projectnotes_main_window.png │ ├── projectnotes_toolbar_entry.gif │ └── projectnotes_note_editing_window.png ├── LICENSE.meta ├── README.md.meta ├── README_CN.md.meta ├── package.json.meta ├── Editor.meta ├── Editor ├── CategoryInfo.cs ├── GBG.ProjectNotes.Editor.asmdef.meta ├── NoteEntry.cs.meta ├── NoteKey.cs.meta ├── Picker.cs.meta ├── Utility.cs.meta ├── CategoryInfo.cs.meta ├── NoteEditWindow.cs.meta ├── NoteHistory.cs.meta ├── CategoryEntryToggle.cs.meta ├── EditorToggleGroup.cs.meta ├── NoteContentView.cs.meta ├── ProjectNotesWindow.cs.meta ├── NoteListViewItemLabel.cs.meta ├── ProjectNotesLocalCache.cs.meta ├── ProjectNotesSettings.cs.meta ├── ProjectNotesWindow.GUI.cs.meta ├── ProjectNotesSettingsEditor.cs.meta ├── NoteHistory.cs ├── GBG.ProjectNotes.Editor.asmdef ├── ProjectNotesSettingsEditor.cs ├── NoteKey.cs ├── CategoryEntryToggle.cs ├── EditorToggleGroup.cs ├── NoteEntry.cs ├── NoteListViewItemLabel.cs ├── ProjectNotesLocalCache.cs ├── ProjectNotesSettings.cs ├── Utility.cs ├── ProjectNotesWindow.cs ├── Picker.cs ├── NoteContentView.cs ├── NoteEditWindow.cs └── ProjectNotesWindow.GUI.cs ├── package.json ├── LICENSE ├── .gitignore ├── README_CN.md └── README.md /Documents~/imgs/projectnotes_main_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolarianZ/UnityProjectNotes/HEAD/Documents~/imgs/projectnotes_main_window.png -------------------------------------------------------------------------------- /Documents~/imgs/projectnotes_toolbar_entry.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolarianZ/UnityProjectNotes/HEAD/Documents~/imgs/projectnotes_toolbar_entry.gif -------------------------------------------------------------------------------- /Documents~/imgs/projectnotes_note_editing_window.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SolarianZ/UnityProjectNotes/HEAD/Documents~/imgs/projectnotes_note_editing_window.png -------------------------------------------------------------------------------- /LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f60c8521174094646a55f1aff9440cf0 3 | DefaultImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1ad18c2ef16ba934d8100771d5fd55ce 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /README_CN.md.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 59cbc0235a958e240b6e14cbd1f02620 3 | TextScriptImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /package.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4017ffb61121f634ea783eb9f0896fd0 3 | PackageManifestImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2c911cb83761e42489b862d62ab06481 3 | folderAsset: yes 4 | DefaultImporter: 5 | externalObjects: {} 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Editor/CategoryInfo.cs: -------------------------------------------------------------------------------- 1 | namespace GBG.ProjectNotes.Editor 2 | { 3 | public struct CategoryInfo 4 | { 5 | public string category; 6 | public int maxPriority; 7 | public bool hasUnreadNotes; 8 | } 9 | } -------------------------------------------------------------------------------- /Editor/GBG.ProjectNotes.Editor.asmdef.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1eb1750d028517c498c04064b42e5db8 3 | AssemblyDefinitionImporter: 4 | externalObjects: {} 5 | userData: 6 | assetBundleName: 7 | assetBundleVariant: 8 | -------------------------------------------------------------------------------- /Editor/NoteEntry.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 09f913c201a0750479984dbbbb2c0afb 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteKey.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ca82a7ff62eb90e45b0f570dc67ec494 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Picker.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f83e0460be9ad534abc98a321f95936b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/Utility.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2810136dc97d02244b147cd78c65f803 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CategoryInfo.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a379b152a5358224f9a440b5a27e080d 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteEditWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7d4b93df990704b449893e8ed12fc8ac 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteHistory.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e6517b3630ccd645b3ea5f52801a471 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/CategoryEntryToggle.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1499c1992bdd4544287bd8cbedb3e71f 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/EditorToggleGroup.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 125aed3a2e1bd134fa81085208996783 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteContentView.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3c14d4bb7c00a9e4796c8d8891a12eb0 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ProjectNotesWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 39ae2b6dbc554324bbedbecfc8817a27 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteListViewItemLabel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9dcb6bd0a9ad96a4883348f455754b9a 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ProjectNotesLocalCache.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cdaded3cbe1f80040a759226b820623b 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ProjectNotesSettings.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 926306c537b96574ca711625ba3d3fec 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ProjectNotesWindow.GUI.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b3980d294c2e76d418500e0daaf48542 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/ProjectNotesSettingsEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24a9c0144f270074881a143206f3c8a1 3 | MonoImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | defaultReferences: [] 7 | executionOrder: 0 8 | icon: {instanceID: 0} 9 | userData: 10 | assetBundleName: 11 | assetBundleVariant: 12 | -------------------------------------------------------------------------------- /Editor/NoteHistory.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GBG.ProjectNotes.Editor 4 | { 5 | [Serializable] 6 | public class NoteHistory 7 | { 8 | public long timestamp; 9 | public string content; 10 | 11 | public NoteHistory(long timestamp, string content) 12 | { 13 | this.timestamp = timestamp; 14 | this.content = content; 15 | } 16 | } 17 | } -------------------------------------------------------------------------------- /Editor/GBG.ProjectNotes.Editor.asmdef: -------------------------------------------------------------------------------- 1 | { 2 | "name": "GBG.ProjectNotes.Editor", 3 | "rootNamespace": "GBG.ProjectNotes.Editor", 4 | "references": [], 5 | "includePlatforms": [ 6 | "Editor" 7 | ], 8 | "excludePlatforms": [], 9 | "allowUnsafeCode": true, 10 | "overrideReferences": false, 11 | "precompiledReferences": [], 12 | "autoReferenced": true, 13 | "defineConstraints": [], 14 | "versionDefines": [], 15 | "noEngineReferences": false 16 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "com.greenbamboogames.projectnotes", 3 | "version": "1.0.1", 4 | "displayName": "Project Notes!", 5 | "description": "A small tool in Unity Editor to display notes, which can be used to share must-read information within a team.", 6 | "unity": "2021.3", 7 | "documentationUrl": "https://github.com/SolarianZ/UnityProjectNotes", 8 | "changelogUrl": "https://github.com/SolarianZ/UnityProjectNotes/releases", 9 | "licensesUrl": "https://github.com/SolarianZ/UnityProjectNotes/blob/main/LICENSE", 10 | "keywords": [ 11 | "Note", 12 | "Memo", 13 | "Tips", 14 | "Reminder", 15 | "Hint", 16 | "Must Read", 17 | "Share", 18 | "Team" 19 | ], 20 | "author": { 21 | "name": "ZQY", 22 | "email": "vdergow@hotmail.com", 23 | "url": "https://github.com/SolarianZ" 24 | }, 25 | "type": "tool", 26 | "hideInEditor": false 27 | } -------------------------------------------------------------------------------- /Editor/ProjectNotesSettingsEditor.cs: -------------------------------------------------------------------------------- 1 | #if !GBG_PROJECTNOTES_DEV 2 | using UnityEditor; 3 | using UnityEditor.UIElements; 4 | using UnityEngine.UIElements; 5 | 6 | namespace GBG.ProjectNotes.Editor 7 | { 8 | [CustomEditor(typeof(ProjectNotesSettings))] 9 | public class ProjectNotesSettingsEditor : UnityEditor.Editor 10 | { 11 | // TODO FIXME: ObjectDisposedException thrown on reset asset: 12 | // ObjectDisposedException: SerializedProperty _notes.Array.data[0].content has disappeared! 13 | public override VisualElement CreateInspectorGUI() 14 | { 15 | VisualElement container = new VisualElement(); 16 | InspectorElement.FillDefaultInspector(container, serializedObject, this); 17 | container.SetEnabled(false); 18 | return container; 19 | } 20 | 21 | public override void OnInspectorGUI() 22 | { 23 | using (new EditorGUI.DisabledScope(true)) 24 | { 25 | base.OnInspectorGUI(); 26 | } 27 | } 28 | } 29 | } 30 | #endif -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 ZQY 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Editor/NoteKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace GBG.ProjectNotes.Editor 4 | { 5 | [Serializable] 6 | public struct NoteKey : IEquatable 7 | { 8 | public string guid; 9 | public long timestamp; 10 | 11 | public NoteKey(string guid, long timestamp) 12 | { 13 | this.guid = guid; 14 | this.timestamp = timestamp; 15 | } 16 | 17 | public override string ToString() 18 | { 19 | return $"{guid}&{timestamp}"; 20 | } 21 | 22 | public string ToStringFormat(string format = null) 23 | { 24 | format ??= Utility.DateTimeFormat; 25 | return $"{guid}&{new DateTime(timestamp).ToString(format)}"; 26 | } 27 | 28 | public override int GetHashCode() 29 | { 30 | return HashCode.Combine(guid, timestamp); 31 | } 32 | 33 | public override bool Equals(object obj) 34 | { 35 | return obj is NoteKey key && Equals(key); 36 | } 37 | 38 | public bool Equals(NoteKey other) 39 | { 40 | return guid == other.guid && timestamp == other.timestamp; 41 | } 42 | 43 | public static bool operator ==(NoteKey left, NoteKey right) 44 | { 45 | return left.Equals(right); 46 | } 47 | 48 | public static bool operator !=(NoteKey left, NoteKey right) 49 | { 50 | return !left.Equals(right); 51 | } 52 | } 53 | } -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # This .gitignore file should be placed at the root of your Unity project directory 2 | # 3 | # Get latest from https://github.com/github/gitignore/blob/main/Unity.gitignore 4 | # 5 | /[Ll]ibrary/ 6 | /[Tt]emp/ 7 | /[Oo]bj/ 8 | /[Bb]uild/ 9 | /[Bb]uilds/ 10 | /[Ll]ogs/ 11 | /[Uu]ser[Ss]ettings/ 12 | 13 | # MemoryCaptures can get excessive in size. 14 | # They also could contain extremely sensitive data 15 | /[Mm]emoryCaptures/ 16 | 17 | # Recordings can get excessive in size 18 | /[Rr]ecordings/ 19 | 20 | # Uncomment this line if you wish to ignore the asset store tools plugin 21 | # /[Aa]ssets/AssetStoreTools* 22 | 23 | # Autogenerated Jetbrains Rider plugin 24 | /[Aa]ssets/Plugins/Editor/JetBrains* 25 | 26 | # Visual Studio cache directory 27 | .vs/ 28 | 29 | # Gradle cache directory 30 | .gradle/ 31 | 32 | # Autogenerated VS/MD/Consulo solution and project files 33 | ExportedObj/ 34 | .consulo/ 35 | *.csproj 36 | *.unityproj 37 | *.sln 38 | *.suo 39 | *.tmp 40 | *.user 41 | *.userprefs 42 | *.pidb 43 | *.booproj 44 | *.svd 45 | *.pdb 46 | *.mdb 47 | *.opendb 48 | *.VC.db 49 | 50 | # Unity3D generated meta files 51 | *.pidb.meta 52 | *.pdb.meta 53 | *.mdb.meta 54 | 55 | # Unity3D generated file on crash reports 56 | sysinfo.txt 57 | 58 | # Builds 59 | *.apk 60 | *.aab 61 | *.unitypackage 62 | *.app 63 | 64 | # Crashlytics generated file 65 | crashlytics-build.properties 66 | 67 | # Packed Addressables 68 | /[Aa]ssets/[Aa]ddressable[Aa]ssets[Dd]ata/*/*.bin* 69 | 70 | # Temporary auto-generated Android Assets 71 | /[Aa]ssets/[Ss]treamingAssets/aa.meta 72 | /[Aa]ssets/[Ss]treamingAssets/aa/* 73 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # Unity项目备忘录 2 | 3 | [English](./README.md) 4 | 5 | 在Unity Editor中显示备忘录的小工具,可用于在团队间分享信息。 6 | 7 | > 有没有因为被同事频繁问同一个问题而烦恼过?试试这个。 8 | 9 | ![Toolbar Entry](./Documents~/imgs/projectnotes_toolbar_entry.gif) 10 | 11 | ![Main Window](./Documents~/imgs/projectnotes_main_window.png) 12 | 13 | ![Note Editing Window](./Documents~/imgs/projectnotes_note_editing_window.png) 14 | 15 | 16 | ## 功能 17 | 18 | - 在独立的EditorWindow中显示备忘内容 19 | - 备忘录条目支持富文本、历史版本和类别 20 | - 支持添加、修改、删除备忘录条目 21 | - 支持按标题、内容和作者查找备忘录条目 22 | - 将本地配置文件上传到版本控制系统后,即可在团队中分享备忘录 23 | - 备忘录配置中有新增条目时,在Editor工具栏中显示醒目提示 ![Toolbar Entry](./Documents~/imgs/projectnotes_toolbar_entry.gif) 24 | 25 | 26 | ## 支持的Unity版本 27 | 28 | Unity 2021.3或更高版本。 29 | 30 | 部分功能在Unity 2022之前的版本中不能使用,例如: 31 | - 无法使用鼠标选择备忘内容文本。 32 | - 不支持部分富文本标签(例如超链接) 33 | 34 | 35 | ## 安装 36 | 37 | [![openupm](https://img.shields.io/npm/v/com.greenbamboogames.projectnotes?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.greenbamboogames.projectnotes/) 38 | 39 | 从 [OpenUPM](https://openupm.com/packages/com.greenbamboogames.projectnotes) 安装,或者直接将此仓库克隆到项目的Packages文件夹下。 40 | 41 | 42 | ## 如何使用 43 | 44 | 点击Editor工具栏的入口按钮,或者菜单项“Tools/Bamboo/Project Notes”,打开Project Notes窗口。 45 | 46 | 点击Project Notes窗口右上角的“+”按钮,添加新的备忘录条目。 47 | 48 | 使用Project Notes窗口顶部的搜索栏,搜索备忘录条目。 49 | 50 | 使用Project Notes窗口右下角的按钮和下拉按钮,标记、编辑或删除备忘录条目。 51 | 52 | 53 | ## 已知问题 54 | 55 | **更改Unity Editor的布局(Layout)后,Editor工具栏中的入口按钮会消失。** 56 | 57 | 解决方案(任一即可): 58 | 59 | - 在Project Notes窗口的上下文菜单中,选择“Create Toolbar Entry Button”选项,重新创建入口按钮。 60 | - 修改任意代码,触发Unity的域重载。 61 | - 重启Unity Editor。 62 | -------------------------------------------------------------------------------- /Editor/CategoryEntryToggle.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEditor.UIElements; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | 6 | namespace GBG.ProjectNotes.Editor 7 | { 8 | public class CategoryEntryToggle : ToolbarToggle 9 | { 10 | private Image _redDotIcon; 11 | 12 | public bool redDotIconVisible 13 | { 14 | get 15 | { 16 | return _redDotIcon != null 17 | ? _redDotIcon.style.display == DisplayStyle.Flex 18 | : false; 19 | } 20 | set 21 | { 22 | if (value) 23 | { 24 | if (_redDotIcon == null) 25 | { 26 | CreateRedDotIcon(); 27 | } 28 | 29 | _redDotIcon.style.display = DisplayStyle.Flex; 30 | } 31 | else if (_redDotIcon != null) 32 | { 33 | _redDotIcon.style.display = DisplayStyle.None; 34 | } 35 | } 36 | } 37 | 38 | 39 | public CategoryEntryToggle(string text = null) 40 | { 41 | this.text = text; 42 | } 43 | 44 | private void CreateRedDotIcon() 45 | { 46 | _redDotIcon = new Image 47 | { 48 | image = EditorGUIUtility.Load(Utility.RedDotIconName) as Texture, 49 | style = 50 | { 51 | width = 8, 52 | height = 8, 53 | } 54 | }; 55 | Add(_redDotIcon); 56 | } 57 | } 58 | } -------------------------------------------------------------------------------- /Editor/EditorToggleGroup.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine.UIElements; 4 | 5 | namespace GBG.ProjectNotes.Editor 6 | { 7 | public class EditorToggleGroup : GroupBox 8 | { 9 | private readonly List _toggles = new List(); 10 | private Toggle _activeToggle; 11 | 12 | public event Action activeToggleChanged; 13 | 14 | 15 | public new void Add(VisualElement child) 16 | { 17 | if (child is Toggle toggle && !_toggles.Contains(toggle)) 18 | { 19 | _toggles.Add(toggle); 20 | toggle.RegisterValueChangedCallback(OnToggleValueChanged); 21 | } 22 | 23 | base.Add(child); 24 | } 25 | 26 | public new void Remove(VisualElement child) 27 | { 28 | if (child is Toggle toggle) 29 | { 30 | _toggles.Remove(toggle); 31 | toggle.UnregisterValueChangedCallback(OnToggleValueChanged); 32 | } 33 | 34 | base.Remove(child); 35 | } 36 | 37 | public new void Clear() 38 | { 39 | foreach (Toggle toggle in _toggles) 40 | { 41 | toggle.UnregisterValueChangedCallback(OnToggleValueChanged); 42 | } 43 | _toggles.Clear(); 44 | 45 | base.Clear(); 46 | } 47 | 48 | 49 | private void OnToggleValueChanged(ChangeEvent evt) 50 | { 51 | if (!evt.newValue) 52 | { 53 | if (evt.target == _activeToggle) 54 | { 55 | _activeToggle.SetValueWithoutNotify(true); 56 | } 57 | 58 | return; 59 | } 60 | 61 | _activeToggle = evt.target as Toggle; 62 | foreach (Toggle toggle in _toggles) 63 | { 64 | if (toggle != _activeToggle) 65 | { 66 | toggle.SetValueWithoutNotify(false); 67 | } 68 | } 69 | 70 | activeToggleChanged?.Invoke(_activeToggle); 71 | } 72 | } 73 | } -------------------------------------------------------------------------------- /Editor/NoteEntry.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Assertions; 5 | 6 | namespace GBG.ProjectNotes.Editor 7 | { 8 | [Serializable] 9 | public class NoteEntry 10 | { 11 | public static int MaxHistoryLength = 8; 12 | 13 | public string guid = Utility.NewGuid(); 14 | public long timestamp = Utility.NewTimestamp(); 15 | public string category; 16 | public string author; 17 | public bool isDraft; 18 | //[HideInInspector] 19 | //public string password; 20 | public int priority; 21 | public string title; 22 | [TextArea(3, 20)] 23 | public string content; 24 | public List contentHistory = new List(); 25 | 26 | public string categoryTrimmed => category?.Trim(); 27 | public long displayPriority { get; set; } 28 | 29 | 30 | // Allow to clear remote read status 31 | public void UpdateGuid() 32 | { 33 | timestamp = Utility.NewTimestamp(); 34 | } 35 | 36 | public void Update(NoteEntry srcNote, bool addOldContentToHistory = true) 37 | { 38 | Assert.IsTrue(srcNote.guid == guid); 39 | 40 | if (addOldContentToHistory && contentHistory.Count < MaxHistoryLength) 41 | { 42 | contentHistory.Add(new NoteHistory(timestamp, content)); 43 | } 44 | 45 | timestamp = srcNote.timestamp; 46 | category = srcNote.category; 47 | author = srcNote.author; 48 | isDraft = srcNote.isDraft; 49 | priority = srcNote.priority; 50 | title = srcNote.title; 51 | content = srcNote.content; 52 | } 53 | 54 | public void CopyFrom(NoteEntry srcNote) 55 | { 56 | guid = srcNote.guid; 57 | timestamp = srcNote.timestamp; 58 | category = srcNote.category; 59 | author = srcNote.author; 60 | isDraft = srcNote.isDraft; 61 | priority = srcNote.priority; 62 | title = srcNote.title; 63 | content = srcNote.content; 64 | contentHistory ??= new List(); 65 | contentHistory.Clear(); 66 | contentHistory.AddRange(srcNote.contentHistory); 67 | } 68 | 69 | public NoteKey GetKey() 70 | { 71 | return new NoteKey(guid, timestamp); 72 | } 73 | } 74 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityProjectNotes 2 | 3 | [中文](./README_CN.md) 4 | 5 | A small utility within the Unity Editor to display notes, which can be used to share information across the team. 6 | 7 | > Have you ever been frustrated by your teammates frequently asking you the same questions? Try this. 8 | 9 | ![Toolbar Entry](./Documents~/imgs/projectnotes_toolbar_entry.gif) 10 | 11 | ![Main Window](./Documents~/imgs/projectnotes_main_window.png) 12 | 13 | ![Note Editing Window](./Documents~/imgs/projectnotes_note_editing_window.png) 14 | 15 | 16 | ## Features 17 | 18 | - Displays notes in a standalone EditorWindow 19 | - Note entries support rich text, version history, and categories 20 | - Supports adding, editing, and deleting note entries 21 | - Supports searching note entries by title, content, and author 22 | - Can share notes with the team by uploading the local settings file to a version control system 23 | - Prominently displays a notification in the Editor toolbar when new entries are added to the note settings ![Toolbar Entry](./Documents~/imgs/projectnotes_toolbar_entry.gif) 24 | 25 | 26 | ## Supported Unity Versions 27 | 28 | Unity 2021.3 or higher. 29 | 30 | Certain features are not available in versions of Unity prior to 2022, for example: 31 | - Unable to select the contents of a note 32 | - Certain rich text tags (such as hyperlinks ) are not supported 33 | 34 | 35 | ## Installation 36 | 37 | [![openupm](https://img.shields.io/npm/v/com.greenbamboogames.projectnotes?label=openupm®istry_uri=https://package.openupm.com)](https://openupm.com/packages/com.greenbamboogames.projectnotes/) 38 | 39 | Install this package via [OpenUPM](https://openupm.com/packages/com.greenbamboogames.projectnotes), or clone this repository directly into the Packages folder of your project. 40 | 41 | 42 | ## How to Use 43 | 44 | Click the entry button in the Editor toolbar, or the menu item "Tools/Bamboo/Project Notes" to open the Project Notes window. 45 | 46 | Click the "+" button in the top right corner of the Project Notes window to add a new note entry. 47 | 48 | Use the search bar at the top of the Project Notes window to search for note entries. 49 | 50 | Use the buttons and dropdown buttons in the bottom right corner of the Project Notes window to mark, edit, or delete note entries. 51 | 52 | 53 | ## Known Issues 54 | 55 | **Changing the Unity Editor layout causes the entry button in the Editor toolbar to disappear.** 56 | 57 | Solutions (any one of the following): 58 | 59 | - In the context menu of the Project Notes window, select the "Create Toolbar Entry Button" option to recreate the entry button. 60 | - Modify any code to trigger a domain reload in Unity. 61 | - Restart the Unity Editor. -------------------------------------------------------------------------------- /Editor/NoteListViewItemLabel.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | using UnityEngine.UIElements; 4 | 5 | namespace GBG.ProjectNotes.Editor 6 | { 7 | public class NoteListViewItemLabel : Label 8 | { 9 | public NoteEntry Note { get; private set; } 10 | private Image _redDotIcon; 11 | 12 | public bool redDotIconVisible 13 | { 14 | get 15 | { 16 | return _redDotIcon != null 17 | ? _redDotIcon.style.display == DisplayStyle.Flex 18 | : false; 19 | } 20 | set 21 | { 22 | if (value) 23 | { 24 | if (_redDotIcon == null) 25 | { 26 | CreateRedDotIcon(); 27 | } 28 | 29 | _redDotIcon.style.display = DisplayStyle.Flex; 30 | } 31 | else if (_redDotIcon != null) 32 | { 33 | _redDotIcon.style.display = DisplayStyle.None; 34 | } 35 | } 36 | } 37 | 38 | 39 | public NoteListViewItemLabel() 40 | { 41 | style.paddingLeft = 4; 42 | style.paddingRight = 4; 43 | style.unityTextAlign = TextAnchor.MiddleLeft; 44 | } 45 | 46 | private void CreateRedDotIcon() 47 | { 48 | _redDotIcon = new Image 49 | { 50 | image = EditorGUIUtility.Load(Utility.RedDotIconName) as Texture, 51 | style = 52 | { 53 | alignSelf = Align.FlexEnd, 54 | marginTop = 2, 55 | width = 8, 56 | height = 8, 57 | } 58 | }; 59 | Add(_redDotIcon); 60 | } 61 | 62 | public void Bind(NoteEntry note) 63 | { 64 | Note = note; 65 | UpdateView(); 66 | } 67 | 68 | public void Unbind() 69 | { 70 | Note = null; 71 | UpdateView(); 72 | } 73 | 74 | public void UpdateView() 75 | { 76 | if (Note == null) 77 | { 78 | text = null; 79 | redDotIconVisible = false; 80 | } 81 | else 82 | { 83 | text = Note.title; 84 | bool unread = ProjectNotesLocalCache.instance.IsUnread(Note.GetKey()); 85 | redDotIconVisible = unread; 86 | } 87 | } 88 | 89 | 90 | public static VisualElement MakeItem() 91 | { 92 | NoteListViewItemLabel itemView = new NoteListViewItemLabel(); 93 | return itemView; 94 | } 95 | } 96 | } -------------------------------------------------------------------------------- /Editor/ProjectNotesLocalCache.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | 5 | namespace GBG.ProjectNotes.Editor 6 | { 7 | [FilePath("Library/com.greenbamboogames.projectnotes/LocalCache.asset", 8 | FilePathAttribute.Location.ProjectFolder)] 9 | internal class ProjectNotesLocalCache : ScriptableSingleton 10 | { 11 | #region Category 12 | 13 | [SerializeField] 14 | private string _selectedCategory = ProjectNotesSettings.CategoryAll; 15 | 16 | public string SelectedCategory 17 | { 18 | get => _selectedCategory; 19 | set 20 | { 21 | if (_selectedCategory != value) 22 | { 23 | _selectedCategory = value; 24 | ForceSave(); 25 | } 26 | } 27 | } 28 | 29 | #endregion 30 | 31 | 32 | #region Note Status 33 | 34 | [SerializeField] 35 | private List _readNoteKeys = new List(); 36 | 37 | 38 | public bool HasUnreadNotes(IEnumerable notes) 39 | { 40 | foreach (NoteEntry note in notes) 41 | { 42 | if (IsUnread(note.GetKey())) 43 | { 44 | return true; 45 | } 46 | } 47 | 48 | return false; 49 | } 50 | 51 | public bool IsUnread(NoteKey key) 52 | { 53 | bool isUnread = !_readNoteKeys.Contains(key); 54 | return isUnread; 55 | } 56 | 57 | public void MarkAsRead(NoteKey key) 58 | { 59 | if (!_readNoteKeys.Contains(key)) 60 | { 61 | _readNoteKeys.Add(key); 62 | Save(true); 63 | } 64 | } 65 | 66 | public void MarkAsUnread(NoteKey key) 67 | { 68 | if (_readNoteKeys.Remove(key)) 69 | { 70 | Save(true); 71 | } 72 | } 73 | 74 | public void ClearReadNotes() 75 | { 76 | _readNoteKeys.Clear(); 77 | Save(true); 78 | } 79 | 80 | public void RemoveInvalidGuids(IEnumerable notes) 81 | { 82 | if (notes == null) 83 | { 84 | _readNoteKeys.Clear(); 85 | return; 86 | } 87 | 88 | for (int i = _readNoteKeys.Count - 1; i >= 0; i--) 89 | { 90 | bool invalid = true; 91 | foreach (NoteEntry note in notes) 92 | { 93 | if (note.GetKey() == _readNoteKeys[i]) 94 | { 95 | invalid = false; 96 | break; 97 | } 98 | } 99 | 100 | if (invalid) 101 | { 102 | _readNoteKeys.RemoveAt(i); 103 | } 104 | } 105 | 106 | Save(true); 107 | } 108 | 109 | #endregion 110 | 111 | 112 | [ContextMenu("Force Save")] 113 | public void ForceSave() 114 | { 115 | Save(true); 116 | } 117 | } 118 | } -------------------------------------------------------------------------------- /Editor/ProjectNotesSettings.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using UDebug = UnityEngine.Debug; 5 | 6 | namespace GBG.ProjectNotes.Editor 7 | { 8 | public class ProjectNotesSettings : ScriptableObject 9 | { 10 | #region Static 11 | 12 | public const string CategoryAll = "All"; 13 | 14 | private static ProjectNotesSettings _instance; 15 | public static ProjectNotesSettings instance 16 | { 17 | get 18 | { 19 | if (!_instance) 20 | { 21 | // "Resources.FindObjectsOfTypeAll" can not find assets that have not been loaded. 22 | string[] guids = AssetDatabase.FindAssets($"t:{nameof(ProjectNotesSettings)}"); 23 | if (guids.Length == 0) 24 | { 25 | return null; 26 | } 27 | 28 | _instance = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guids[0])); 29 | if (guids.Length > 1) 30 | { 31 | UDebug.LogError($"[Project Notes] Multiple {nameof(ProjectNotesSettings)} instances found, using the first one. Please remove duplicates.", _instance); 32 | } 33 | } 34 | 35 | return _instance; 36 | } 37 | } 38 | 39 | internal static void CreateNewInstance() 40 | { 41 | string savePath = EditorUtility.SaveFilePanelInProject("Save Project Notes Settings", 42 | "ProjectNotesSettings", "asset", "Save Project Notes Settings"); 43 | if (string.IsNullOrEmpty(savePath)) 44 | { 45 | return; 46 | } 47 | 48 | ProjectNotesSettings instance = CreateInstance(); 49 | AssetDatabase.CreateAsset(instance, savePath); 50 | EditorGUIUtility.PingObject(instance); 51 | UDebug.Log($"[Project Notes] Created new {nameof(ProjectNotesSettings)} asset at {savePath}.", instance); 52 | } 53 | 54 | #endregion 55 | 56 | 57 | public long VersionTimestamp => _versionTimestamp; 58 | public List Notes => _notes; 59 | 60 | [SerializeField] 61 | private long _versionTimestamp = Utility.NewTimestamp(); 62 | [SerializeField] 63 | private List _notes = new List 64 | { 65 | new NoteEntry 66 | { 67 | category = "Sample", 68 | author = "ZQY", 69 | priority = int.MaxValue, 70 | title = "Sample Note / 示例信息", 71 | content = "This is a sample note.\r\n这是一个示例信息。\r\n\r\n" + 72 | "You can input some information here and then upload this asset to a version control system to share the information within your team.\r\n" + 73 | "可以在这里输入一些信息,然后将此资产上传到版本控制系统,来在团队中分享信息。\r\n\r\n" + 74 | "The information content supports rich text, see reference:\r\n" + 75 | "信息内容支持富文本,参考:\r\n\r\n" + 76 | #if UNITY_2022_3_OR_NEWER 77 | " Supported rich text tags", 78 | #else 79 | " https://docs.unity3d.com/Manual/UIE-supported-tags.html", 80 | #endif 81 | contentHistory = { 82 | new NoteHistory(638523554912390682, "This is a historical version sample.\r\n这是一个历史版本示例。") 83 | }, 84 | } 85 | }; 86 | 87 | 88 | [ContextMenu("Force Save", false, 0)] 89 | internal void ForceSave() 90 | { 91 | EditorUtility.SetDirty(this); 92 | #if !UNITY_6000_0_OR_NEWER 93 | // MEMO Unity Bug: https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-66169 94 | // Fixed in 2022.3.29f1, 6000.0.0b16 95 | AssetDatabase.MakeEditable(AssetDatabase.GetAssetPath(this)); 96 | #endif 97 | AssetDatabase.SaveAssetIfDirty(this); 98 | } 99 | 100 | [ContextMenu("[Debug] Generate New Guid to Clipboard", false, 100)] 101 | public void GenerateNewGuidToClipboard() 102 | { 103 | GUIUtility.systemCopyBuffer = Utility.NewGuid(); 104 | } 105 | 106 | [ContextMenu("[Debug] Generate New Timestamp to Clipboard", false, 101)] 107 | public void GenerateNewTimestampToClipboard() 108 | { 109 | GUIUtility.systemCopyBuffer = Utility.NewTimestamp().ToString(); 110 | } 111 | } 112 | } -------------------------------------------------------------------------------- /Editor/Utility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | 4 | namespace GBG.ProjectNotes.Editor 5 | { 6 | public static class Utility 7 | { 8 | public static string NewGuid() => Guid.NewGuid().ToString(); 9 | public static long NewTimestamp() => DateTime.Now.Ticks; 10 | 11 | 12 | public static string DateTimeFormat = "yyyy-MM-dd HH:mm:ss:fff"; 13 | public static float ButtonBorderRadius = 2; 14 | 15 | public static string FormatTimestamp(long timestamp) 16 | { 17 | return new DateTime(timestamp).ToString(DateTimeFormat); 18 | } 19 | 20 | public static void CollectHistoryTimestamps(this NoteEntry note, List timestamps) 21 | { 22 | timestamps.Clear(); 23 | if (note == null) 24 | { 25 | //timestamps.Add(0); 26 | return; 27 | } 28 | 29 | timestamps.Add(note.timestamp); 30 | foreach (NoteHistory history in note.contentHistory) 31 | { 32 | timestamps.Add(history.timestamp); 33 | } 34 | } 35 | 36 | public static bool HasUnreadNotesInCategory(string category) 37 | { 38 | ProjectNotesSettings settings = ProjectNotesSettings.instance; 39 | if (!settings) 40 | { 41 | return false; 42 | } 43 | 44 | category = category?.Trim(); 45 | if (category == ProjectNotesSettings.CategoryAll) 46 | { 47 | foreach (NoteEntry note in settings.Notes) 48 | { 49 | if (ProjectNotesLocalCache.instance.IsUnread(note.GetKey())) 50 | { 51 | return true; 52 | } 53 | } 54 | } 55 | 56 | foreach (NoteEntry note in settings.Notes) 57 | { 58 | if (note.categoryTrimmed == category && 59 | ProjectNotesLocalCache.instance.IsUnread(note.GetKey())) 60 | { 61 | return true; 62 | } 63 | } 64 | 65 | return false; 66 | } 67 | 68 | public static List CollectCategoriesOrderByMaxPriority(this ProjectNotesSettings settings, bool addCategoryAll = true) 69 | { 70 | Dictionary categoryInfoDict = new Dictionary(); 71 | bool hasUnreadNotes = false; 72 | foreach (NoteEntry note in settings.Notes) 73 | { 74 | string category = note.categoryTrimmed; 75 | if (category == ProjectNotesSettings.CategoryAll || string.IsNullOrEmpty(category)) 76 | { 77 | if (!hasUnreadNotes && addCategoryAll) 78 | { 79 | hasUnreadNotes = ProjectNotesLocalCache.instance.IsUnread(note.GetKey()); 80 | } 81 | continue; 82 | } 83 | 84 | if (!categoryInfoDict.TryGetValue(category, out CategoryInfo categoryInfo)) 85 | { 86 | bool noteUnread = ProjectNotesLocalCache.instance.IsUnread(note.GetKey()); 87 | hasUnreadNotes |= noteUnread; 88 | categoryInfo = new CategoryInfo 89 | { 90 | category = category, 91 | maxPriority = note.priority, 92 | hasUnreadNotes = noteUnread, 93 | }; 94 | categoryInfoDict[category] = categoryInfo; 95 | 96 | continue; 97 | } 98 | 99 | bool infoChanged = false; 100 | if (categoryInfo.maxPriority < note.priority) 101 | { 102 | categoryInfo.maxPriority = note.priority; 103 | infoChanged = true; 104 | } 105 | if (!categoryInfo.hasUnreadNotes && ProjectNotesLocalCache.instance.IsUnread(note.GetKey())) 106 | { 107 | categoryInfo.hasUnreadNotes = true; 108 | infoChanged = true; 109 | } 110 | if (infoChanged) 111 | { 112 | categoryInfoDict[category] = categoryInfo; 113 | } 114 | } 115 | 116 | List categoryInfos = new List(categoryInfoDict.Count + 1); 117 | if (addCategoryAll) 118 | { 119 | categoryInfos.Add(new CategoryInfo 120 | { 121 | category = ProjectNotesSettings.CategoryAll, 122 | maxPriority = int.MaxValue, 123 | hasUnreadNotes = hasUnreadNotes, 124 | }); 125 | } 126 | 127 | foreach (CategoryInfo newCategoryInfo in categoryInfoDict.Values) 128 | { 129 | bool added = false; 130 | for (int i = categoryInfos.Count - 1; i >= 0; i--) 131 | { 132 | CategoryInfo categoryInfo = categoryInfos[i]; 133 | if (categoryInfo.maxPriority >= newCategoryInfo.maxPriority) 134 | { 135 | categoryInfos.Insert(i + 1, newCategoryInfo); 136 | added = true; 137 | break; 138 | } 139 | } 140 | 141 | if (!added) 142 | { 143 | categoryInfos.Insert(0, newCategoryInfo); 144 | } 145 | } 146 | 147 | return categoryInfos; 148 | } 149 | 150 | public static HashSet CollectCategories(this ProjectNotesSettings settings, bool addCategoryAll) 151 | { 152 | HashSet categories = new HashSet(); 153 | 154 | if (addCategoryAll) 155 | { 156 | categories.Add(ProjectNotesSettings.CategoryAll); 157 | } 158 | 159 | foreach (NoteEntry note in settings.Notes) 160 | { 161 | categories.Add(note.categoryTrimmed); 162 | } 163 | 164 | return categories; 165 | } 166 | 167 | 168 | public static int MinTitleLength = 4; 169 | public static int MinContentLength = 12; 170 | 171 | public static bool IsNiceTitle(string title, out string alert) 172 | { 173 | if (title.Length < MinTitleLength) 174 | { 175 | alert = $"Short title may lack recognizability."; 176 | return false; 177 | } 178 | 179 | alert = null; 180 | return true; 181 | } 182 | 183 | public static bool IsNiceContent(string content, out string alert) 184 | { 185 | if (content.Length < MinContentLength) 186 | { 187 | alert = $"Short content may be difficult to understand."; 188 | return false; 189 | } 190 | 191 | alert = null; 192 | return true; 193 | } 194 | 195 | 196 | public const string RedDotIconName = "redLight"; // "winbtn_mac_close" 197 | } 198 | } -------------------------------------------------------------------------------- /Editor/ProjectNotesWindow.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using UnityEditor; 3 | using UnityEngine; 4 | using UnityEngine.UIElements; 5 | using UDebug = UnityEngine.Debug; 6 | 7 | namespace GBG.ProjectNotes.Editor 8 | { 9 | public partial class ProjectNotesWindow : EditorWindow, IHasCustomMenu 10 | { 11 | #region Static 12 | 13 | public static ProjectNotesSettings Settings => ProjectNotesSettings.instance; 14 | internal static ProjectNotesLocalCache LocalCache => ProjectNotesLocalCache.instance; 15 | private static ProjectNotesWindow _windowInstance; 16 | 17 | 18 | [MenuItem("Tools/Bamboo/Project Notes")] 19 | public static void Open() 20 | { 21 | _windowInstance = GetWindow(); 22 | } 23 | 24 | public static bool HasUnreadNotes() 25 | { 26 | if (!Settings) 27 | { 28 | return false; 29 | } 30 | 31 | bool hasUnreadNotes = LocalCache.HasUnreadNotes(Settings.Notes); 32 | return hasUnreadNotes; 33 | } 34 | 35 | [InitializeOnLoadMethod] 36 | private static void Initialize() 37 | { 38 | if (Application.isBatchMode) 39 | { 40 | return; 41 | } 42 | 43 | EditorApplication.update -= OnEditorUpdate; 44 | EditorApplication.update += OnEditorUpdate; 45 | } 46 | 47 | private static void OnEditorUpdate() 48 | { 49 | TryCreateToolbarEntry(); 50 | 51 | bool hasUnreadNotes = HasUnreadNotes(); 52 | UpdateToolbarEntryIcon(hasUnreadNotes); 53 | UpdateWindowTitleIcon(hasUnreadNotes); 54 | } 55 | 56 | #endregion 57 | 58 | 59 | private readonly List _filteredNotes = new List(); 60 | 61 | 62 | private void OnEnable() 63 | { 64 | titleContent = EditorGUIUtility.IconContent("Clipboard"); 65 | titleContent.text = "Project Notes"; 66 | minSize = new Vector2(200, 200); 67 | 68 | LocalCache.RemoveInvalidGuids(Settings?.Notes); 69 | _filteredNotes.Clear(); 70 | } 71 | 72 | private void OnFocus() 73 | { 74 | UpdateViews(_noteEntryListView?.selectedItem as NoteEntry); 75 | } 76 | 77 | private void Update() 78 | { 79 | if (!Settings && !_createSettingsButtonVisible) 80 | { 81 | _createSettingsButtonVisible = true; 82 | _createSettingsButton.style.display = DisplayStyle.Flex; 83 | _mainViewContainer.style.display = DisplayStyle.None; 84 | } 85 | else if (Settings && _createSettingsButtonVisible) 86 | { 87 | _createSettingsButtonVisible = false; 88 | _createSettingsButton.style.display = DisplayStyle.None; 89 | _mainViewContainer.style.display = DisplayStyle.Flex; 90 | } 91 | } 92 | 93 | 94 | private void SaveNote(NoteEntry noteToSave, bool isNewNote) 95 | { 96 | if (!Settings) 97 | { 98 | return; 99 | } 100 | 101 | if (isNewNote) 102 | { 103 | Settings.Notes.Add(noteToSave); 104 | Settings.ForceSave(); 105 | LocalCache.MarkAsRead(noteToSave.GetKey()); 106 | LocalCache.SelectedCategory = noteToSave.categoryTrimmed; 107 | UpdateViews(noteToSave); 108 | UDebug.Log($"[Project Notes] Note added: {noteToSave.title} {Utility.FormatTimestamp(noteToSave.timestamp)}."); 109 | return; 110 | } 111 | 112 | for (int i = 0; i < Settings.Notes.Count; i++) 113 | { 114 | NoteEntry note = Settings.Notes[i]; 115 | if (note.guid != noteToSave.guid) 116 | { 117 | continue; 118 | } 119 | 120 | note.Update(noteToSave); 121 | Settings.ForceSave(); 122 | LocalCache.MarkAsRead(note.GetKey()); 123 | UpdateViews(note); 124 | UDebug.Log($"[Project Notes] Note updated: {note.title} {Utility.FormatTimestamp(note.timestamp)}."); 125 | return; 126 | } 127 | 128 | UDebug.LogError($"[Project Notes] Failed to save note: {noteToSave.title} {Utility.FormatTimestamp(noteToSave.timestamp)}."); 129 | } 130 | 131 | private void DeleteNote(NoteEntry noteToDelete, long timestampToDelete) 132 | { 133 | if (!Settings) 134 | { 135 | return; 136 | } 137 | 138 | bool deleted = false; 139 | bool deletedHistory = false; 140 | for (int i = 0; i < Settings.Notes.Count; i++) 141 | { 142 | NoteEntry note = Settings.Notes[i]; 143 | if (note != noteToDelete) 144 | { 145 | continue; 146 | } 147 | 148 | if (note.timestamp == timestampToDelete) 149 | { 150 | Settings.Notes.RemoveAt(i); 151 | deleted = true; 152 | break; 153 | } 154 | 155 | bool breakOuter = false; 156 | for (int j = 0; j < note.contentHistory.Count; j++) 157 | { 158 | NoteHistory history = note.contentHistory[j]; 159 | if (history.timestamp == timestampToDelete) 160 | { 161 | note.contentHistory.RemoveAt(j); 162 | deleted = true; 163 | deletedHistory = true; 164 | breakOuter = true; 165 | break; 166 | } 167 | } 168 | if (breakOuter) 169 | { 170 | break; 171 | } 172 | } 173 | 174 | if (deleted) 175 | { 176 | Settings.ForceSave(); 177 | 178 | if (deletedHistory) 179 | { 180 | UDebug.Log($"[Project Notes] Note history deleted: {noteToDelete.title} {Utility.FormatTimestamp(timestampToDelete)}."); 181 | _contentView.RefreshView(); 182 | } 183 | else 184 | { 185 | UDebug.Log($"[Project Notes] Note deleted: {noteToDelete.title} {Utility.FormatTimestamp(timestampToDelete)}."); 186 | NoteEntry selection = null; 187 | if (_filteredNotes.Count > 1) 188 | { 189 | NoteEntry candidate = _filteredNotes[0]; 190 | if (candidate == noteToDelete) 191 | { 192 | candidate = _filteredNotes[1]; 193 | } 194 | selection = candidate; 195 | } 196 | UpdateViews(selection); 197 | } 198 | } 199 | else 200 | { 201 | UDebug.LogError($"[Project Notes] Failed to delete note: {noteToDelete.title} {Utility.FormatTimestamp(timestampToDelete)}."); 202 | } 203 | } 204 | 205 | 206 | #region Context Menu 207 | 208 | void IHasCustomMenu.AddItemsToMenu(GenericMenu menu) 209 | { 210 | // Document 211 | menu.AddItem(new GUIContent("Unity Manual: Supported Rich Text Tags"), false, () => 212 | { 213 | Application.OpenURL("https://docs.unity3d.com/Manual/UIE-supported-tags.html"); 214 | }); 215 | menu.AddSeparator(""); 216 | 217 | // Toolbar Entry Button #1 Workaround 218 | // TODO FIXME: Toolbar entry button disappered after changing Editor layout 219 | menu.AddItem(new GUIContent("Create Toolbar Entry Button", "The toolbar entry button will disappear after changing the layout of Unity Editor, use this option to re-create the toolbar entry button."), 220 | false, () => 221 | { 222 | TryCreateToolbarEntry(true); 223 | }); 224 | menu.AddSeparator(""); 225 | 226 | // Debug 227 | menu.AddItem(new GUIContent("[Debug] Inspect Settings Asset"), false, () => 228 | { 229 | Selection.activeObject = Settings; 230 | }); 231 | menu.AddItem(new GUIContent("[Debug] Inspect Local Cache Asset"), false, () => 232 | { 233 | Selection.activeObject = LocalCache; 234 | }); 235 | } 236 | 237 | #endregion 238 | } 239 | } -------------------------------------------------------------------------------- /Editor/Picker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor.Search; 4 | 5 | namespace GBG.ProjectNotes.Editor 6 | { 7 | internal static class Picker 8 | { 9 | public const string Pattern_Title = "title:"; 10 | public const string Pattern_Content = "content:"; 11 | public const string Pattern_Author = "author:"; 12 | 13 | 14 | #region Pick Single Note 15 | 16 | public static bool Pick(NoteEntry note, string rawPattern, ref long score) 17 | { 18 | if (string.IsNullOrWhiteSpace(rawPattern)) 19 | { 20 | score = -1; 21 | return true; 22 | } 23 | 24 | rawPattern = rawPattern.Trim(); 25 | 26 | if (rawPattern.StartsWith(Pattern_Title, StringComparison.OrdinalIgnoreCase)) 27 | { 28 | string pattern = rawPattern.Substring(Pattern_Title.Length); 29 | return PickInTitle(note, pattern, ref score); 30 | } 31 | 32 | if (rawPattern.StartsWith(Pattern_Content, StringComparison.OrdinalIgnoreCase)) 33 | { 34 | string pattern = rawPattern.Substring(Pattern_Content.Length); 35 | return PickInContent(note, pattern, ref score); 36 | } 37 | 38 | if (rawPattern.StartsWith(Pattern_Author, StringComparison.OrdinalIgnoreCase)) 39 | { 40 | string pattern = rawPattern.Substring(Pattern_Author.Length); 41 | return PickInAuthor(note, pattern, ref score); 42 | } 43 | 44 | return PickInNote(note, rawPattern, ref score); 45 | } 46 | 47 | public static bool PickInNote(NoteEntry note, string pattern, ref long score) 48 | { 49 | if (string.IsNullOrWhiteSpace(pattern)) 50 | { 51 | score = -1; 52 | return true; 53 | } 54 | 55 | bool match = false; 56 | long maxScore = int.MinValue; 57 | if (FuzzySearch.FuzzyMatch(pattern, note.title, ref score)) 58 | { 59 | match = true; 60 | if (score > maxScore) { maxScore = score; } 61 | } 62 | if (FuzzySearch.FuzzyMatch(pattern, note.content, ref score)) 63 | { 64 | match = true; 65 | if (score > maxScore) { maxScore = score; } 66 | } 67 | if (FuzzySearch.FuzzyMatch(pattern, note.author, ref score)) 68 | { 69 | match = true; 70 | if (score > maxScore) { maxScore = score; } 71 | } 72 | 73 | score = maxScore; 74 | return match; 75 | } 76 | 77 | public static bool PickInTitle(NoteEntry note, string pattern, ref long score) 78 | { 79 | if (string.IsNullOrWhiteSpace(pattern)) 80 | { 81 | score = -1; 82 | return true; 83 | } 84 | 85 | return FuzzySearch.FuzzyMatch(pattern, note.title, ref score); 86 | } 87 | 88 | public static bool PickInContent(NoteEntry note, string pattern, ref long score) 89 | { 90 | if (string.IsNullOrWhiteSpace(pattern)) 91 | { 92 | score = -1; 93 | return true; 94 | } 95 | 96 | return FuzzySearch.FuzzyMatch(pattern, note.content, ref score); 97 | } 98 | 99 | public static bool PickInAuthor(NoteEntry note, string pattern, ref long score) 100 | { 101 | if (string.IsNullOrWhiteSpace(pattern)) 102 | { 103 | score = -1; 104 | return true; 105 | } 106 | 107 | return FuzzySearch.FuzzyMatch(pattern, note.author, ref score); 108 | } 109 | 110 | #endregion 111 | 112 | 113 | #region Pick in Collection 114 | 115 | public static void Pick(List notes, string rawPattern) 116 | { 117 | if (string.IsNullOrWhiteSpace(rawPattern)) 118 | { 119 | foreach (NoteEntry note in notes) 120 | { 121 | note.displayPriority = note.priority; 122 | } 123 | return; 124 | } 125 | 126 | rawPattern = rawPattern.Trim(); 127 | 128 | if (rawPattern.StartsWith(Pattern_Title, StringComparison.OrdinalIgnoreCase)) 129 | { 130 | string pattern = rawPattern.Substring(Pattern_Title.Length); 131 | PickInTitleAppendMode(notes, pattern); 132 | return; 133 | } 134 | 135 | if (rawPattern.StartsWith(Pattern_Content, StringComparison.OrdinalIgnoreCase)) 136 | { 137 | string pattern = rawPattern.Substring(Pattern_Content.Length); 138 | PickInContentAppendMode(notes, pattern); 139 | return; 140 | } 141 | 142 | if (rawPattern.StartsWith(Pattern_Author, StringComparison.OrdinalIgnoreCase)) 143 | { 144 | string pattern = rawPattern.Substring(Pattern_Author.Length); 145 | PickInAuthorAppendMode(notes, pattern); 146 | return; 147 | } 148 | 149 | PickInNoteAppendMode(notes, rawPattern); 150 | } 151 | 152 | public static void PickInNoteAppendMode(List notes, string pattern) 153 | { 154 | if (string.IsNullOrWhiteSpace(pattern)) 155 | { 156 | foreach (NoteEntry note in notes) 157 | { 158 | note.displayPriority = note.priority; 159 | } 160 | return; 161 | } 162 | 163 | for (int i = notes.Count - 1; i >= 0; i--) 164 | { 165 | NoteEntry note = notes[i]; 166 | bool match = false; 167 | long maxScore = int.MinValue; 168 | long score = 0; 169 | if (FuzzySearch.FuzzyMatch(pattern, note.title, ref score)) 170 | { 171 | match = true; 172 | if (score > maxScore) { maxScore = score; } 173 | } 174 | if (FuzzySearch.FuzzyMatch(pattern, note.content, ref score)) 175 | { 176 | match = true; 177 | if (score > maxScore) { maxScore = score; } 178 | } 179 | if (FuzzySearch.FuzzyMatch(pattern, note.author, ref score)) 180 | { 181 | match = true; 182 | if (score > maxScore) { maxScore = score; } 183 | } 184 | 185 | if (match) 186 | { 187 | note.displayPriority = maxScore; 188 | } 189 | else 190 | { 191 | notes.RemoveAt(i); 192 | } 193 | } 194 | } 195 | 196 | public static void PickInTitleAppendMode(List notes, string pattern) 197 | { 198 | if (string.IsNullOrWhiteSpace(pattern)) 199 | { 200 | foreach (NoteEntry note in notes) 201 | { 202 | note.displayPriority = note.priority; 203 | } 204 | return; 205 | } 206 | 207 | for (int i = notes.Count - 1; i >= 0; i--) 208 | { 209 | NoteEntry note = notes[i]; 210 | long score = 0; 211 | if (FuzzySearch.FuzzyMatch(pattern, note.title, ref score)) 212 | { 213 | note.displayPriority = score; 214 | } 215 | else 216 | { 217 | notes.RemoveAt(i); 218 | } 219 | } 220 | } 221 | 222 | public static void PickInContentAppendMode(List notes, string pattern) 223 | { 224 | if (string.IsNullOrWhiteSpace(pattern)) 225 | { 226 | foreach (NoteEntry note in notes) 227 | { 228 | note.displayPriority = note.priority; 229 | } 230 | return; 231 | } 232 | 233 | for (int i = notes.Count - 1; i >= 0; i--) 234 | { 235 | NoteEntry note = notes[i]; 236 | long score = 0; 237 | if (FuzzySearch.FuzzyMatch(pattern, note.content, ref score)) 238 | { 239 | note.displayPriority = score; 240 | } 241 | else 242 | { 243 | notes.RemoveAt(i); 244 | } 245 | } 246 | } 247 | 248 | public static void PickInAuthorAppendMode(List notes, string pattern) 249 | { 250 | if (string.IsNullOrWhiteSpace(pattern)) 251 | { 252 | foreach (NoteEntry note in notes) 253 | { 254 | note.displayPriority = note.priority; 255 | } 256 | return; 257 | } 258 | 259 | for (int i = notes.Count - 1; i >= 0; i--) 260 | { 261 | NoteEntry note = notes[i]; 262 | long score = 0; 263 | if (FuzzySearch.FuzzyMatch(pattern, note.author, ref score)) 264 | { 265 | note.displayPriority = score; 266 | } 267 | else 268 | { 269 | notes.RemoveAt(i); 270 | } 271 | } 272 | } 273 | 274 | #endregion 275 | } 276 | } -------------------------------------------------------------------------------- /Editor/NoteContentView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using UnityEditor; 4 | using UnityEngine; 5 | using UnityEngine.UIElements; 6 | #if !UNITY_2022_3_OR_NEWER 7 | using UnityEditor.UIElements; // PopupField 8 | #endif 9 | using UDebug = UnityEngine.Debug; 10 | 11 | namespace GBG.ProjectNotes.Editor 12 | { 13 | public class NoteContentView : VisualElement 14 | { 15 | public static Color draftLabelBorderColor = new Color32(255, 180, 0, 255); 16 | public static Color unreadLabelBorderColor = new Color32(240, 0, 0, 255); 17 | public static float statusLabelBorderWidth = 2; 18 | public static float statusLabelBorderRadius = 4; 19 | public static float contentLabelBorderSize = 1; 20 | public static Color contentLabelBorderColorDark = new Color32(44, 44, 44, 255); 21 | public static Color contentLabelBorderColorLight = new Color32(177, 177, 177, 255); 22 | 23 | private readonly Label _versionLabel; 24 | private readonly Label _unreadLabel; 25 | private readonly Label _titleLabel; 26 | private readonly Label _authorLabel; 27 | private readonly PopupField _historyPopup; 28 | private readonly List _historyTimestamps = new List(); 29 | private readonly Label _contentLabel; 30 | private readonly Button _markButton; 31 | private readonly Button _opDropdownButton; 32 | private NoteEntry _note; 33 | 34 | public event Action readStatusChanged; 35 | public event Action wantsToEditNote; 36 | public event Action wantsToDeleteNote; 37 | 38 | 39 | public NoteContentView() 40 | { 41 | style.paddingLeft = 8; 42 | style.paddingRight = 6; 43 | style.paddingTop = 4; 44 | style.paddingBottom = 4; 45 | 46 | VisualElement statusContainer = new VisualElement 47 | { 48 | style = 49 | { 50 | flexDirection = FlexDirection.Row, 51 | } 52 | }; 53 | Add(statusContainer); 54 | 55 | _versionLabel = new Label 56 | { 57 | text = "Draft", 58 | style = 59 | { 60 | display = DisplayStyle.None, 61 | marginRight = 2, 62 | paddingLeft= 2, 63 | paddingRight= 2, 64 | borderLeftWidth = statusLabelBorderWidth, 65 | borderRightWidth = statusLabelBorderWidth, 66 | borderTopWidth = statusLabelBorderWidth, 67 | borderBottomWidth = statusLabelBorderWidth, 68 | borderTopLeftRadius = statusLabelBorderRadius , 69 | borderTopRightRadius = statusLabelBorderRadius , 70 | borderBottomLeftRadius = statusLabelBorderRadius , 71 | borderBottomRightRadius = statusLabelBorderRadius , 72 | borderLeftColor = draftLabelBorderColor, 73 | borderRightColor = draftLabelBorderColor, 74 | borderTopColor = draftLabelBorderColor, 75 | borderBottomColor = draftLabelBorderColor, 76 | unityTextAlign = TextAnchor.MiddleCenter, 77 | } 78 | }; 79 | statusContainer.Add(_versionLabel); 80 | 81 | _unreadLabel = new Label 82 | { 83 | text = "Unread", 84 | style = 85 | { 86 | display = DisplayStyle.None, 87 | marginLeft = 2, 88 | paddingLeft= 2, 89 | paddingRight= 2, 90 | borderLeftWidth = statusLabelBorderWidth, 91 | borderRightWidth = statusLabelBorderWidth, 92 | borderTopWidth = statusLabelBorderWidth, 93 | borderBottomWidth = statusLabelBorderWidth, 94 | borderTopLeftRadius = statusLabelBorderRadius, 95 | borderTopRightRadius = statusLabelBorderRadius, 96 | borderBottomLeftRadius = statusLabelBorderRadius, 97 | borderBottomRightRadius = statusLabelBorderRadius, 98 | borderLeftColor = unreadLabelBorderColor, 99 | borderRightColor = unreadLabelBorderColor, 100 | borderTopColor = unreadLabelBorderColor, 101 | borderBottomColor = unreadLabelBorderColor, 102 | unityTextAlign = TextAnchor.MiddleCenter, 103 | } 104 | }; 105 | statusContainer.Add(_unreadLabel); 106 | 107 | _titleLabel = new Label 108 | { 109 | text = "-", 110 | enableRichText = true, 111 | style = 112 | { 113 | fontSize = 16, 114 | } 115 | }; 116 | #if UNITY_2022_3_OR_NEWER 117 | ((ITextSelection)_titleLabel).isSelectable = true; 118 | #endif 119 | Add(_titleLabel); 120 | 121 | _authorLabel = new Label 122 | { 123 | text = "-", 124 | enableRichText = true, 125 | style = 126 | { 127 | marginLeft = 2, 128 | fontSize = 11, 129 | unityFontStyleAndWeight = FontStyle.Italic, 130 | } 131 | }; 132 | #if UNITY_2022_3_OR_NEWER 133 | ((ITextSelection)_authorLabel).isSelectable = true; 134 | #endif 135 | Add(_authorLabel); 136 | 137 | _historyPopup = new PopupField 138 | { 139 | choices = _historyTimestamps, 140 | value = 0, 141 | formatSelectedValueCallback = Utility.FormatTimestamp, 142 | formatListItemCallback = Utility.FormatTimestamp, 143 | style = 144 | { 145 | marginLeft = 0, 146 | alignSelf = Align.FlexStart, 147 | } 148 | }; 149 | _historyPopup.RegisterValueChangedCallback(SelectHistory); 150 | Add(_historyPopup); 151 | 152 | ScrollView contentScrollView = new ScrollView 153 | { 154 | style = 155 | { 156 | flexGrow = 1, 157 | marginTop = 10, 158 | } 159 | }; 160 | Add(contentScrollView); 161 | _contentLabel = new Label 162 | { 163 | text = "-", 164 | enableRichText = true, 165 | style = 166 | { 167 | flexGrow = 1, 168 | fontSize = 14, 169 | whiteSpace = WhiteSpace.Normal, 170 | //borderLeftWidth = contentLabelBorderSize, 171 | //borderRightWidth = contentLabelBorderSize, 172 | //borderTopWidth = contentLabelBorderSize, 173 | //borderBottomWidth = contentLabelBorderSize, 174 | //borderTopLeftRadius = contentLabelBorderSize, 175 | //borderTopRightRadius = contentLabelBorderSize, 176 | //borderBottomLeftRadius = contentLabelBorderSize, 177 | //borderBottomRightRadius = contentLabelBorderSize, 178 | //borderLeftColor = EditorGUIUtility.isProSkin ? contentLabelBorderColorDark : contentLabelBorderColorLight, 179 | //borderRightColor = EditorGUIUtility.isProSkin ? contentLabelBorderColorDark : contentLabelBorderColorLight, 180 | //borderTopColor = EditorGUIUtility.isProSkin ? contentLabelBorderColorDark : contentLabelBorderColorLight, 181 | //borderBottomColor = EditorGUIUtility.isProSkin ? contentLabelBorderColorDark : contentLabelBorderColorLight, 182 | } 183 | }; 184 | #if UNITY_2022_3_OR_NEWER 185 | ((ITextSelection)_contentLabel).isSelectable = true; 186 | #endif 187 | contentScrollView.Add(_contentLabel); 188 | 189 | VisualElement opContainer = new VisualElement 190 | { 191 | style = 192 | { 193 | flexDirection = FlexDirection.Row, 194 | justifyContent = Justify.FlexEnd, 195 | minHeight= 22, 196 | maxHeight= 22, 197 | marginBottom = 2, 198 | }, 199 | }; 200 | Add(opContainer); 201 | 202 | _markButton = new Button(MarkStatus) 203 | { 204 | text = "-", 205 | style = 206 | { 207 | width = 110, 208 | marginRight = 0, 209 | paddingRight = 0, 210 | borderTopLeftRadius = Utility.ButtonBorderRadius, 211 | borderTopRightRadius = Utility.ButtonBorderRadius, 212 | borderBottomLeftRadius = Utility.ButtonBorderRadius, 213 | borderBottomRightRadius = Utility.ButtonBorderRadius, 214 | } 215 | }; 216 | opContainer.Add(_markButton); 217 | 218 | _opDropdownButton = new Button(CreateOpDropdownMenu) 219 | { 220 | style = 221 | { 222 | backgroundImage = EditorGUIUtility.isProSkin 223 | ? EditorGUIUtility.Load("d_icon dropdown@2x") as Texture2D 224 | : EditorGUIUtility.Load("icon dropdown@2x") as Texture2D, 225 | width = 14, 226 | marginLeft = 0, 227 | paddingLeft = 0, 228 | borderTopLeftRadius = Utility.ButtonBorderRadius, 229 | borderTopRightRadius = Utility.ButtonBorderRadius, 230 | borderBottomLeftRadius = Utility.ButtonBorderRadius, 231 | borderBottomRightRadius = Utility.ButtonBorderRadius, 232 | } 233 | }; 234 | opContainer.Add(_opDropdownButton); 235 | } 236 | 237 | public void SetNote(NoteEntry note) 238 | { 239 | _note = note; 240 | _versionLabel.text = _note?.isDraft ?? false 241 | ? "Draft" 242 | : null; 243 | _versionLabel.style.display = _note?.isDraft ?? false 244 | ? DisplayStyle.Flex 245 | : DisplayStyle.None; 246 | _unreadLabel.style.display = _note != null && ProjectNotesLocalCache.instance.IsUnread(_note.GetKey()) 247 | ? DisplayStyle.Flex 248 | : DisplayStyle.None; 249 | _titleLabel.text = _note?.title ?? "TITLE"; 250 | _authorLabel.text = _note == null ? "AUTHOR" : $"by {_note.author}"; 251 | _note.CollectHistoryTimestamps(_historyTimestamps); 252 | _historyPopup.SetValueWithoutNotify(_note?.timestamp ?? 0L); 253 | _contentLabel.text = _note?.content ?? "CONTENT"; 254 | UpdateOpButtons(); 255 | } 256 | 257 | public void RefreshView() 258 | { 259 | SetNote(_note); 260 | } 261 | 262 | private void CreateOpDropdownMenu() 263 | { 264 | if (_note == null) 265 | { 266 | return; 267 | } 268 | 269 | GenericMenu menu = new GenericMenu(); 270 | if (_note.timestamp == _historyPopup.value) 271 | { 272 | menu.AddItem(new GUIContent("Edit"), false, OnWantsToEditNote); 273 | menu.AddSeparator(""); 274 | menu.AddItem(new GUIContent("Delete"), false, OnWantsToDeleteNote); 275 | menu.DropDown(_opDropdownButton.worldBound); 276 | } 277 | else 278 | { 279 | menu.AddItem(new GUIContent("Delete Old Version"), false, OnWantsToDeleteNote); 280 | menu.DropDown(_opDropdownButton.worldBound); 281 | } 282 | } 283 | 284 | private void SelectHistory(ChangeEvent evt) 285 | { 286 | long timestamp = evt.newValue; 287 | if (timestamp == _note.timestamp) 288 | { 289 | RefreshView(); 290 | return; 291 | } 292 | 293 | foreach (NoteHistory history in _note.contentHistory) 294 | { 295 | if (history.timestamp == timestamp) 296 | { 297 | _versionLabel.text = "Old Version"; 298 | _versionLabel.style.display = DisplayStyle.Flex; 299 | _unreadLabel.style.display = DisplayStyle.None; 300 | _contentLabel.text = history.content; 301 | UpdateOpButtons(); 302 | return; 303 | } 304 | } 305 | 306 | UDebug.LogError($"[Project Notes] Unable to find historical version for timestamp '{timestamp}'."); 307 | RefreshView(); 308 | } 309 | 310 | private void UpdateOpButtons() 311 | { 312 | _markButton.text = _note == null || _note.timestamp != _historyPopup.value 313 | ? "MARK" 314 | : ProjectNotesLocalCache.instance.IsUnread(_note.GetKey()) 315 | ? "Mark as Read" 316 | : "Mark as Unread"; 317 | _markButton.SetEnabled(_note != null && _note.timestamp == _historyPopup.value); 318 | _opDropdownButton.SetEnabled(_note != null); 319 | } 320 | 321 | private void MarkStatus() 322 | { 323 | if (_note == null) 324 | { 325 | return; 326 | } 327 | 328 | bool unread = ProjectNotesLocalCache.instance.IsUnread(_note.GetKey()); 329 | if (unread) 330 | { 331 | ProjectNotesLocalCache.instance.MarkAsRead(_note.GetKey()); 332 | } 333 | else 334 | { 335 | ProjectNotesLocalCache.instance.MarkAsUnread(_note.GetKey()); 336 | } 337 | 338 | RefreshView(); 339 | 340 | readStatusChanged?.Invoke(_note); 341 | } 342 | 343 | private void OnWantsToEditNote() 344 | { 345 | if (_note == null) 346 | { 347 | return; 348 | } 349 | 350 | wantsToEditNote?.Invoke(_note); 351 | } 352 | 353 | private void OnWantsToDeleteNote() 354 | { 355 | if (_note == null) 356 | { 357 | return; 358 | } 359 | 360 | bool oldVersion = _note.timestamp != _historyPopup.value; 361 | string title = oldVersion 362 | ? "Delete old version of the selected note?" 363 | : "Delete selected note?"; 364 | string messageHeader = oldVersion 365 | ? $"{_note.title}\nVersion: {Utility.FormatTimestamp(_historyPopup.value)}\n\n" 366 | : $"{_note.title}\n\n"; 367 | string message = messageHeader + 368 | $"This operation cannot be undone.\n" + 369 | $"Once the settings is synced to the version control system, this note will be removed from the project of all team members."; 370 | if (EditorUtility.DisplayDialog(title, message, "Delete", "Cancel")) 371 | { 372 | wantsToDeleteNote?.Invoke(_note, _historyPopup.value); 373 | } 374 | } 375 | } 376 | } -------------------------------------------------------------------------------- /Editor/NoteEditWindow.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using UnityEditor; 5 | using UnityEditor.UIElements; 6 | using UnityEngine; 7 | using UnityEngine.UIElements; 8 | 9 | namespace GBG.ProjectNotes.Editor 10 | { 11 | public class NoteEditWindow : EditorWindow 12 | { 13 | public static NoteEditWindow Open(NoteEntry note, SaveNoteHandler onSave, IEnumerable existingCategories) 14 | { 15 | NoteEditWindow window = GetWindow(true); 16 | window.Initialize(note, onSave, existingCategories); // Called after CreateGUI 17 | //window.ShowModalUtility(); Conflict with undo/redo 18 | return window; 19 | } 20 | 21 | //private static NoteEditWindow _instance; 22 | 23 | [Flags] 24 | enum InvalidStatus 25 | { 26 | Category = 1 << 0, 27 | Author = 1 << 1, 28 | Title = 1 << 2, 29 | Content = 1 << 3, 30 | } 31 | 32 | 33 | public delegate void SaveNoteHandler(NoteEntry note, bool isNewNote); 34 | 35 | public const float FieldLabelWidth = 70; 36 | public const float AlertLabelOffset = 80; 37 | public static Color WarningTextColor = Color.yellow;// new Color32(255, 180, 0, 255); 38 | public static Color ErrorTextColor = new Color32(240, 0, 0, 255); 39 | 40 | private SaveNoteHandler _onSave; 41 | private bool _isNewNote; 42 | private InvalidStatus _invalidStatus; 43 | [SerializeField] 44 | private NoteEntry _serializedNote; // for undo/redo use 45 | private SerializedObject _serializedObject; 46 | 47 | private TextField _guidField; 48 | private TextField _timestampField; 49 | private TextField _categoryField; 50 | private ToolbarMenu _existingCategoryMenu; 51 | private Label _categoryAlertLabel; 52 | private TextField _authorField; 53 | private Label _authorAlertLabel; 54 | private Toggle _draftField; 55 | private IntegerField _priorityField; 56 | private TextField _titleField; 57 | private Label _titleAlertLabel; 58 | private TextField _contentField; 59 | private Label _contentAlertLabel; 60 | 61 | 62 | private void OnEnable() 63 | { 64 | //_instance = this; 65 | 66 | SetWindowTitle(); 67 | minSize = new Vector2(400, 400); 68 | 69 | AssemblyReloadEvents.beforeAssemblyReload -= OnBeforeAssemblyReload; 70 | AssemblyReloadEvents.beforeAssemblyReload += OnBeforeAssemblyReload; 71 | } 72 | 73 | private void CreateGUI() 74 | { 75 | VisualElement root = rootVisualElement; 76 | 77 | ScrollView scrollView = new ScrollView 78 | { 79 | style = { flexGrow = 1 }, 80 | }; 81 | root.Add(scrollView); 82 | 83 | _guidField = new TextField("Guid") 84 | { 85 | isReadOnly = true, 86 | style = { unityTextAlign = TextAnchor.MiddleRight, }, 87 | }; 88 | _guidField.Q