@@ -6,37 +6,50 @@ namespace DCFApixels.Notes.Editors
66{
77 using static NotesConsts ;
88 [ CustomEditor ( typeof ( LazyNote ) ) ]
9- internal class LazyNoteEditor : Editor
9+ internal class LazyNoteEditor : ExtendedEditor < LazyNote >
1010 {
1111 private Rect rect = new Rect ( ) ;
1212 private Texture2D _lineTex ;
1313 private bool _IsInit = false ;
1414
15- private LazyNote Target => target as LazyNote ;
15+ private SerializedProperty _heightProp ;
16+ private SerializedProperty _textProp ;
17+ private SerializedProperty _drawIconProp ;
18+ private SerializedProperty _colorProp ;
1619
17- private void Init ( )
20+ #region Init
21+ protected override void OnInit ( )
1822 {
19- if ( _IsInit ) return ;
2023 _lineTex = CreateTexture ( 2 , 2 , Color . black ) ;
21- _IsInit = true ;
24+
25+ _heightProp = FindProperty ( "_height" ) ;
26+ _textProp = FindProperty ( "_text" ) ;
27+ _drawIconProp = FindProperty ( "_drawIcon" ) ;
28+ _colorProp = FindProperty ( "_color" ) ;
2229 }
30+ private static Texture2D CreateTexture ( int width , int height , Color32 color32 )
31+ {
32+ var pixels = new Color32 [ width * height ] ;
33+ for ( var i = 0 ; i < pixels . Length ; ++ i )
34+ pixels [ i ] = color32 ;
2335
24- public override void OnInspectorGUI ( )
36+ var result = new Texture2D ( width , height ) ;
37+ result . SetPixels32 ( pixels ) ;
38+ result . Apply ( ) ;
39+ return result ;
40+ }
41+ #endregion
42+
43+ #region Draw
44+ protected override void DrawCustom ( )
2545 {
26- Init ( ) ;
2746 Color defaultColor = GUI . color ;
2847 Color defaultBackgroundColor = GUI . backgroundColor ;
2948
30- EditorGUI . BeginChangeCheck ( ) ;
31- SerializedProperty heightProp = serializedObject . FindProperty ( "_height" ) ;
32- SerializedProperty textProp = serializedObject . FindProperty ( "_text" ) ;
33- SerializedProperty colorProp = serializedObject . FindProperty ( "_color" ) ;
34- SerializedProperty drawIconProp = serializedObject . FindProperty ( "_drawIcon" ) ;
35-
36- Color color = colorProp . colorValue ;
49+ Color color = _colorProp . colorValue ;
3750
3851 Color elemcolor = NormalizeBackgroundColor ( color ) ;
39- rect = new Rect ( 0 , 0 , EditorGUIUtility . currentViewWidth , EditorGUIUtility . singleLineHeight * 2 + heightProp . floatValue + 5 ) ;
52+ rect = new Rect ( 0 , 0 , EditorGUIUtility . currentViewWidth , EditorGUIUtility . singleLineHeight * 2 + _heightProp . floatValue + 5 ) ;
4053
4154 EditorGUI . DrawRect ( rect , color ) ;
4255
@@ -53,7 +66,7 @@ public override void OnInspectorGUI()
5366 GUIStyle gUIStyle = new GUIStyle ( EditorStyles . label ) ;
5467 gUIStyle . normal . textColor = new Color ( 0.1f , 0.1f , 0.1f , 0.2f ) ;
5568
56- drawIconProp . boolValue = EditorGUILayout . Toggle ( drawIconProp . boolValue , GUILayout . MaxWidth ( 16 ) ) ;
69+ _drawIconProp . boolValue = EditorGUILayout . Toggle ( _drawIconProp . boolValue , GUILayout . MaxWidth ( 16 ) ) ;
5770 GUILayout . Label ( "" , gUIStyle ) ;
5871
5972 float originalValue = EditorGUIUtility . labelWidth ;
@@ -62,24 +75,21 @@ public override void OnInspectorGUI()
6275 GUI . backgroundColor = Color . white ;
6376
6477 GUIStyle gUIStylex = new GUIStyle ( EditorStyles . helpBox ) ;
65- heightProp . floatValue = EditorGUILayout . FloatField ( "↕" , heightProp . floatValue , gUIStylex , GUILayout . MaxWidth ( 58 ) ) ;
66- heightProp . floatValue = Mathf . Max ( MIN_NOTE_HEIGHT , heightProp . floatValue ) ;
78+ _heightProp . floatValue = EditorGUILayout . FloatField ( "↕" , _heightProp . floatValue , gUIStylex , GUILayout . MaxWidth ( 58 ) ) ;
79+ _heightProp . floatValue = Mathf . Max ( MIN_NOTE_HEIGHT , _heightProp . floatValue ) ;
6780 GUI . color = defaultColor ;
6881 EditorGUIUtility . labelWidth = originalValue ;
6982
70- Color newColor = EditorGUILayout . ColorField ( colorProp . colorValue , GUILayout . MaxWidth ( 40 ) ) ;
83+ Color newColor = EditorGUILayout . ColorField ( _colorProp . colorValue , GUILayout . MaxWidth ( 40 ) ) ;
7184 newColor . a = 1f ;
72- colorProp . colorValue = newColor ;
85+ _colorProp . colorValue = newColor ;
7386
7487 EditorGUILayout . EndHorizontal ( ) ;
7588
7689 GUILayout . Box ( _lineTex , GUILayout . Height ( 1 ) , GUILayout . ExpandWidth ( true ) ) ;
7790
78- textProp . stringValue = EditorGUILayout . TextArea ( textProp . stringValue , areastyle , GUILayout . Height ( heightProp . floatValue ) ) ;
91+ _textProp . stringValue = EditorGUILayout . TextArea ( _textProp . stringValue , areastyle , GUILayout . Height ( _heightProp . floatValue ) ) ;
7992 GUI . backgroundColor = defaultBackgroundColor ;
80-
81- serializedObject . ApplyModifiedProperties ( ) ;
82- EditorGUI . EndChangeCheck ( ) ;
8393 }
8494 public override void DrawPreview ( Rect previewArea )
8595 {
@@ -92,17 +102,7 @@ private static Color NormalizeBackgroundColor(Color color)
92102 S -= S * 0.62f ;
93103 return Color . HSVToRGB ( H , S , V ) * 3f ;
94104 }
95- private static Texture2D CreateTexture ( int width , int height , Color32 color32 )
96- {
97- var pixels = new Color32 [ width * height ] ;
98- for ( var i = 0 ; i < pixels . Length ; ++ i )
99- pixels [ i ] = color32 ;
100-
101- var result = new Texture2D ( width , height ) ;
102- result . SetPixels32 ( pixels ) ;
103- result . Apply ( ) ;
104- return result ;
105- }
105+ #endregion
106106 }
107107}
108108#endif
0 commit comments