1- using System . Reflection ;
2- using UnityEditor ;
1+ using UnityEditor ;
32using UnityEngine ;
43
54namespace DCFApixels . Notes . Editors
65{
7- using static NoteConsts ;
8-
9- internal static class NoteConsts
10- {
11- public const string NOTE_SEPARATOR = ">-<" ;
12- }
13- internal static class NoteUtils
6+ [ CustomEditor ( typeof ( Note ) ) ]
7+ [ CanEditMultipleObjects ]
8+ internal class NoteEditor : Editor
149 {
15- [ MenuItem ( "GameObject/Create Note" ) ]
16- public static void CreateNote ( MenuCommand menuCommand )
10+ private Rect fullRect = new Rect ( ) ;
11+ private Texture2D _lineTex ;
12+ private bool _IsInit = false ;
13+ private static float _headerHeight = 27 ;
14+
15+ private GUIStyle _settingsButtonStyle ;
16+
17+ private Note Target => target as Note ;
18+
19+ private GenericMenu _authorsGenericMenu ;
20+ private int _authorsGenericMenuCount ;
21+ private GenericMenu _typesGenericMenu ;
22+ private int _typesGenericMenuCount ;
23+
24+ private NotesSettings Settings => NotesSettings . Instance ;
25+
26+
27+ public GenericMenu GetAuthorsGenericMenu ( )
1728 {
18- GameObject go = new GameObject ( "Note" ) ;
19- go . AddComponent < Note > ( ) ;
20- GameObjectUtility . SetParentAndAlign ( go , menuCommand . context as GameObject ) ;
21- Undo . RegisterCreatedObjectUndo ( go , "Create " + go . name ) ;
22- Selection . activeObject = go ;
29+ if ( _authorsGenericMenu == null || _authorsGenericMenuCount != Settings . AuthorsCount )
30+ {
31+ _authorsGenericMenuCount = Settings . AuthorsCount ;
32+ _authorsGenericMenu = new GenericMenu ( ) ;
33+ foreach ( var author in Settings . Authors )
34+ _authorsGenericMenu . AddItem ( new GUIContent ( author . name ) , false , OnAuthorSelected , author ) ;
35+ }
36+ return _authorsGenericMenu ;
2337 }
24-
25- [ DrawGizmo ( GizmoType . Selected | GizmoType . NonSelected | GizmoType . Pickable ) ]
26- public static void DrawNote ( Note note , GizmoType gizmoType )
38+ private void OnAuthorSelected ( object obj )
39+ {
40+ AuthorInfo author = ( AuthorInfo ) obj ;
41+ serializedObject . FindProperty ( "_authorID" ) . intValue = author . _id ;
42+ serializedObject . ApplyModifiedProperties ( ) ;
43+ }
44+ public GenericMenu GetTypesGenericMenu ( )
2745 {
28- if ( note . DrawIcon )
46+ if ( _typesGenericMenu == null || _typesGenericMenuCount != Settings . TypesCount )
2947 {
30- var assembly = Assembly . GetExecutingAssembly ( ) ;
31- var packagePath = UnityEditor . PackageManager . PackageInfo . FindForAssembly ( assembly ) . assetPath ;
32- Gizmos . DrawIcon ( note . transform . position , packagePath + "/Gizmos/Runtime/Note Icon.png" , false , note . Color ) ;
48+ _typesGenericMenuCount = Settings . TypesCount ;
49+ _typesGenericMenu = new GenericMenu ( ) ;
50+ foreach ( var type in Settings . Types )
51+ _typesGenericMenu . AddItem ( new GUIContent ( type . name ) , false , OnTypeSelected , type ) ;
3352 }
34-
35- string sceneNote = GetSceneNote ( note . Text , note . DrawIcon ) ;
36- Handles . Label ( note . transform . position , sceneNote , EditorStyles . whiteBoldLabel ) ;
53+ return _typesGenericMenu ;
3754 }
38-
39- private static string GetSceneNote ( string fullNote , bool isNeedSpacing )
55+ private void OnTypeSelected ( object obj )
4056 {
41- int index = fullNote . IndexOf ( NOTE_SEPARATOR ) ;
42- if ( index < 0 ) return string . Empty ;
43- string result = fullNote . Substring ( 0 , index ) ;
44- return isNeedSpacing ? "\r \n " + result : result ;
57+ NoteTypeInfo type = ( NoteTypeInfo ) obj ;
58+ serializedObject . FindProperty ( "_typeID" ) . intValue = type . _id ;
59+ serializedObject . ApplyModifiedProperties ( ) ;
4560 }
46- }
47- [ CustomEditor ( typeof ( Note ) ) ]
48- internal class NoteEditor : Editor
49- {
50- private Rect rect = new Rect ( ) ;
51- private Texture2D _lineTex ;
52- private bool _IsInit = false ;
53-
54- private Note Target => target as Note ;
5561
5662 private void Init ( )
5763 {
5864 if ( _IsInit ) return ;
5965 _lineTex = CreateTexture ( 2 , 2 , Color . black ) ;
66+
67+ _settingsButtonStyle = new GUIStyle ( EditorStyles . miniButton ) ;
68+ _settingsButtonStyle . padding = new RectOffset ( 0 , 0 , 0 , 0 ) ;
69+
6070 _IsInit = true ;
6171 }
6272
73+
74+
6375 public override void OnInspectorGUI ( )
6476 {
6577 Init ( ) ;
66- Color defaultColor = GUI . color ;
67- Color defaultBackgroundColor = GUI . backgroundColor ;
6878
69- EditorGUI . BeginChangeCheck ( ) ;
7079 SerializedProperty heightProp = serializedObject . FindProperty ( "_height" ) ;
7180 SerializedProperty textProp = serializedObject . FindProperty ( "_text" ) ;
72- SerializedProperty colorProp = serializedObject . FindProperty ( "_color" ) ;
81+ SerializedProperty authorProp = serializedObject . FindProperty ( "_authorID" ) ;
82+ SerializedProperty typeProp = serializedObject . FindProperty ( "_typeID" ) ;
7383 SerializedProperty drawIconProp = serializedObject . FindProperty ( "_drawIcon" ) ;
7484
75- Color color = colorProp . colorValue ;
85+ Color defaultColor = GUI . color ;
86+ Color defaultBackgroundColor = GUI . backgroundColor ;
87+
88+ AuthorInfo author = Settings . GetAuthorInfoOrDummy ( authorProp . intValue ) ;
89+ NoteTypeInfo noteType = Settings . GetNoteTypeInfoOrDummy ( typeProp . intValue ) ;
90+ Color headerColor = author . color ;
91+ Color bodyColor = noteType . color ;
92+
93+ EditorGUI . BeginChangeCheck ( ) ;
94+
95+ Color headerBackColor = NormalizeBackgroundColor ( headerColor ) ;
7696
77- Color elemcolor = NormalizeBackgroundColor ( color ) ;
78- rect = new Rect ( 0 , 0 , EditorGUIUtility . currentViewWidth , EditorGUIUtility . singleLineHeight * 2 + heightProp . floatValue + 5 ) ;
97+ fullRect = new Rect ( 0 , 0 , EditorGUIUtility . currentViewWidth , EditorGUIUtility . singleLineHeight * 2 + heightProp . floatValue + 5 ) ;
98+ Rect headerRect = fullRect ;
99+ headerRect . height = _headerHeight ;
100+ Rect bodyRect = fullRect ;
101+ bodyRect . yMin += _headerHeight ;
79102
80- EditorGUI . DrawRect ( rect , color ) ;
103+ EditorGUI . DrawRect ( headerRect , headerColor ) ;
104+ EditorGUI . DrawRect ( bodyRect , bodyColor ) ;
81105
82- GUI . backgroundColor = elemcolor ;
106+ GUI . backgroundColor = headerBackColor ;
83107
84108 GUIStyle areastyle = new GUIStyle ( EditorStyles . wordWrappedLabel ) ;
85109
@@ -93,22 +117,44 @@ public override void OnInspectorGUI()
93117 gUIStyle . normal . textColor = new Color ( 0.1f , 0.1f , 0.1f , 0.2f ) ;
94118
95119 drawIconProp . boolValue = EditorGUILayout . Toggle ( drawIconProp . boolValue , GUILayout . MaxWidth ( 16 ) ) ;
120+
121+
122+ GUI . backgroundColor = Color . white ;
123+ GUI . color = Color . black ;
124+ GUILayout . Label ( "Author:" , GUILayout . Width ( 44 ) ) ;
125+ GUI . color = headerColor ;
126+ if ( GUILayout . Button ( author . IsDummy ( ) ? "-" : author . name , EditorStyles . popup ) )
127+ {
128+ GetAuthorsGenericMenu ( ) . ShowAsContext ( ) ;
129+ }
130+ GUI . color = Color . black ;
131+ GUILayout . Label ( "Type:" , GUILayout . Width ( 36 ) ) ;
132+ GUI . color = headerColor ;
133+ if ( GUILayout . Button ( noteType . IsDummy ( ) ? "-" : noteType . name , EditorStyles . popup ) )
134+ {
135+ GetTypesGenericMenu ( ) . ShowAsContext ( ) ;
136+ }
137+ if ( GUILayout . Button ( EditorGUIUtility . IconContent ( "_Popup" ) , _settingsButtonStyle , GUILayout . Width ( 18f ) ) )
138+ {
139+ NotesSettingsWindow . Open ( ) ;
140+ }
96141 GUILayout . Label ( "" , gUIStyle ) ;
97142
98143 float originalValue = EditorGUIUtility . labelWidth ;
99144 EditorGUIUtility . labelWidth = 14 ;
100145 GUI . color = new Color ( 0.2f , 0.2f , 0.2f ) ;
101- GUI . backgroundColor = Color . white ;
102146
103147 GUIStyle gUIStylex = new GUIStyle ( EditorStyles . helpBox ) ;
104148 heightProp . floatValue = EditorGUILayout . FloatField ( "↕" , heightProp . floatValue , gUIStylex , GUILayout . MaxWidth ( 58 ) ) ;
105149 heightProp . floatValue = Mathf . Max ( 20f , heightProp . floatValue ) ;
106- GUI . color = defaultColor ;
107150 EditorGUIUtility . labelWidth = originalValue ;
108151
109- Color newColor = EditorGUILayout . ColorField ( colorProp . colorValue , GUILayout . MaxWidth ( 40 ) ) ;
110- newColor . a = 1f ;
111- colorProp . colorValue = newColor ;
152+
153+ GUI . color = defaultColor ;
154+
155+ //Color newColor = EditorGUILayout.ColorField(colorProp.colorValue, GUILayout.MaxWidth(40));
156+ //newColor.a = 1f;
157+ //colorProp.colorValue = newColor;
112158
113159 EditorGUILayout . EndHorizontal ( ) ;
114160
@@ -120,9 +166,14 @@ public override void OnInspectorGUI()
120166 serializedObject . ApplyModifiedProperties ( ) ;
121167 EditorGUI . EndChangeCheck ( ) ;
122168 }
169+
170+ private void DrawNote ( Note target , SerializedObject serializedObject )
171+ {
172+
173+ }
123174 public override void DrawPreview ( Rect previewArea )
124175 {
125- rect = previewArea ;
176+ fullRect = previewArea ;
126177 base . DrawPreview ( previewArea ) ;
127178 }
128179 private static Color NormalizeBackgroundColor ( Color color )
0 commit comments